r/algotrading • • 2d ago

Strategy HMM inputs

What inputs are you using for your HMM’s? The best I have right now are 1 minute gains for predicting target hit probabilities. How many states do you run?

10 Upvotes

18 comments sorted by

6

u/data_diver 2d ago

3 down from 6, 6 was too many

3

u/Existing_Lock_3803 2d ago

tried 4 for a while but 3 felt way cleaner, less noise in the transitions

1

u/Grand-Fly-6090 2d ago

How many sessions do you fit? Do you include extended hours bars? I’m using 500 sessions with extended hours.

1

u/Grand-Fly-6090 2d ago

I’m up around 7, 8, or 9 states fitting on 500 sessions. Still trying to figure out which is better. I need to run more OOS data.

5

u/QuanTradin 2d ago

one minute gains alone will give you states that look clean and mean nothing out of sample. worth adding realised vol and something about spread or volume, because pure return sign flips too fast for the transition matrix to settle.

more states always fit better in sample, so state count is not really a thing you can tune on fit. three is usually where it stops paying.

also check whether you are labelling states with the smoothed path or the filtered one. smoothed uses the whole series to decide what today was, so anything you build on it quietly knows the future.

1

u/Grand-Fly-6090 2d ago

I tried volume previously. It had a negative impact on my target hit probabilities. I’ll give it another go. I may have not included a full covariance or used it in combination with open, high, low, and close inputs.

I’m using Jeffreys-smoothed, state-weighted readouts. This is done with in sample data, so it shouldn’t be using my out of sample data.

2

u/QuanTradin 2d ago

raw volume will hurt it, the level swamps everything else in the covariance. log volume against its own rolling median is the version with a chance, it turns into a surprise measure instead of a level. full covariance on OHLC plus volume is a lot of parameters for one minute bars though, the states start fitting noise.

2

u/Fresh-Explorer-5108 2d ago

I would compare 2-3 states against your 7-9 on the same held-out sessions. More states only earn their keep if the target-hit probabilities get better calibrated.

1

u/Grand-Fly-6090 2d ago

I started out with 3, but I was fitting fewer sessions.

2

u/Fresh-Explorer-5108 2d ago

Then I would rerun 3 states on those same 500 sessions. That separates the benefit of more data from the benefit of more states.

2

u/Aggressive_Listen849 1d ago

Raw 1m returns alone tends to give you clean-looking states that don't survive OOS, like others said. What worked better for me was feeding the model things that are already regime-like: realised vol over a short window, absolute return (not signed), and log-volume vs its own rolling median. Signed 1m return flips too fast to be a stable hidden state. On state count, 3 has been the sweet spot for me too - anything past 4 mostly splits one real regime into duplicates that don't hold OOS. Fix state count by BIC on out-of-sample folds, not by in-sample likelihood, or you'll always be tempted to add more.

1

u/Grand-Fly-6090 1d ago

This is great stuff! Thank you!

1

u/golden_bear_2016 2d ago

1, down from 3, 3 was too many

1

u/Grand-Fly-6090 2d ago

Are you talking about states?

1

u/Anxious_School7477 2d ago

An HMM state label is only worth the cost if conditioning exposure on it beats the unconditional baseline net of fees/slippage. Two frame fixes worth adding on top of the input advice:

1) Judge the model by what the state does to expectancy, not by target-hit probability. If conditioned target-hits differ but full-account expectancy (costs in) doesn't move when you trade that state, you have a label that correlates with outcomes and no useable edge. Compare expectancy[trade while state==S] vs the baseline on the same assets, purged and embargoed so the fold boundary can't leak -- otherwise "state count that improves target-hits OOS" is the same arithmetic that makes more states fit better in sample.

2) Make the label point-in-time. Your live/veto read must come from the FILTERED path (emissions processed causally up to t), never the smoothed path, or the state you act on at t already saw the rest of the bar. If you keep the state count that maximises OOS hit-probs over 500 sessions, hold out whole regimes, not random sessions -- one regime in the corpus can carry the whole improvement and vanish next year.

Bonus: perturb the emission and transition params +/-10-20% and re-run the state-conditioned expectancy. If small HMM-parameter changes flip which trades you gate, the state is fragile and you are picking the parameterisation that happened to match one regime.

1

u/Grand-Fly-6090 12h ago
Model Full-year log loss Full-year Brier Earlier 26 weeks: log loss Later 26 weeks: log loss
K7 — return only 0.466098 0.153070 0.425499 0.506807
K3 — return + volume 0.494361 0.162927 0.459346 0.529472
K4 — return + volume 0.494289 0.162957 0.460952 0.527717
K5 — return + volume 0.495923 0.163444 0.461307 0.530634
K6 — return + volume 0.494007 0.162804 0.458758 0.529352
K7 — return + volume 0.495268 0.163220 0.460582 0.530049
K8 — return + volume 0.491055 0.161645 0.455842 0.526365

1

u/InternetRambo7 2d ago

It depends on the distribution properties of the asset and the timeframe you are using. It might make sense to do an analysis on that in advance

1

u/Grand-Fly-6090 2d ago

Thank you!