lindermanlab / ssm

Bayesian learning and inference for state space models
MIT License
540 stars 196 forks source link

Fit HMM to financial time series and generate samples #131

Closed mackancurtaincheeks closed 1 year ago

mackancurtaincheeks commented 3 years ago

Dear Linderman,

I'm new to this package and I have only used hmmlearn in the past - I can't seem to find any function to generate actual values from the model.

I'm training/fitting my model on financial time series data and I would like to generate/forecast prices to compare with the actual historical price for accuracy. Is this possible?

slinderman commented 1 year ago

This is certainly doable! For an HMM, once you've fit the model you can call hmm.sample(T) to simulate new data from the model. If you want to forecast into the future, you can do it in two steps. I think this should work

z_past = hmm.most_likely_states(x_past) 
z_pred, x_pred = hmm.sample(T_pred, prefix = (z_past, x_past))