loelschlaeger / fHMM

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

Lookahead bias ? #75

Closed polizzi4757 closed 2 years ago

polizzi4757 commented 2 years ago

First of all I want to thank you for sharing your package. I think you have done a great job. However, if your goal is to fit HMM to financial data, I have to tell you that the HMM calculations might have a lookahead bias. To show you what I mean, I attach two scripts:

It would be nice to have a feedback from you. Thank you Giuseppe Polizzi

HMM lookahead bias.zip

loelschlaeger commented 2 years ago

I was able to reproduce the bias with your code. I strongly believe that this has nothing to do with the implementation, but rather with the underlying model and especially the applied Viterbi algorithm for global decoding. So when fitting an HMM to a financial time series and subsequently applying the Viterbi decoding, we can only make probabilistic statements about future states and future (log-) returns, cf. https://doi.org/10.1177/1471082X211034048. Recalculating specific dates definitely compromises the global decoding, so your result is very much expected. I guess local decoding is required in this case, and we will put it on our "TODO" list for future package developments. Thanks for pointing this out, Giuseppe.

polizzi4757 commented 2 years ago

Thank you for your timely response and thank you again for your great work.