loelschlaeger / fHMM

Hidden Markov models for finance
https://loelschlaeger.de/fHMM/
GNU General Public License v3.0
12 stars 8 forks source link

Update model with new data #73

Closed MislavSag closed 2 years ago

MislavSag commented 2 years ago

Thanks for the great package!

I would like to backtest the prediction performance of HHMM in predicting bull/bear states. Is there some efficient way to backtest the strategy? For example, is it possible to update a new state with new data?

For example, if I have daily data from 2000 to 2022-01-01, I can estimate HHMM model and calculate predictions. But for the next point (day 2022-01-03), I have to estimate the whole model again and calculate predictions again? This seems very inefficient.

I would like to post a features request for model update with new data (monitoring) if that is not implemented already.

loelschlaeger commented 2 years ago

This is not implemented yet but will be considered for the next update. Until then, you are right, the only (but very inefficient) way is to manually add new data points and estimate the model again. Thanks for pointing this out!

MislavSag commented 2 years ago

Great,I will wait for update than :)

loelschlaeger commented 2 years ago

After careful consideration, we think that the likelihood must be maximized again when having new data. There is no straight-forward way to recycle the old likelihood and update it with new data.

However, as a work-around, we added the argument init to fit_model(), which can be the estimate of a previously fitted model. Using such an initial value will result in a much faster convergence of the numerical optimizer.

Hence, a typical workflow for you can look like follows: Estimate a first model. With new data, estimate a model again, but specify the init argument for fit_model() with the estimate of the previous model. It is saved at model$estimate. You may want to reduce the number of optimization runs in controls then.