fix(strategies): align factory regime numbering with training labeler (#15)#18
Open
bradsmithmba wants to merge 1 commit into
Open
Conversation
Regime integers in StrategyFactory used different semantics than RegimeType in regime_labeler.py, which produces the training labels. Regime 0 meant BULL_TRENDING to the labeler but "Deep Bear Market" to the factory, so the model recommended bearish strategies in bull markets (and vice versa) across nearly every regime. Realign the factory mapping, performance map, and risk classification to RegimeType. Remove the unreachable regime 8 (detector emits 8 classes, 0-7). Update tests that had encoded the inverted numbering as expected behavior, and add a regression guard tying the factory to the labeler's numbering. Note: any model checkpoints trained before this change learned the inverted associations and must be retrained after merge. Closes cloudtrainerwork#15 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
StrategyFactoryand the training-timeRegimeTypelabeler (src/data/regime_labeler.py) used the same regime integers (0–7) to mean different things. The neural net is trained on labels from the labeler, then its predictions are interpreted by the factory. Because the two numberings were misaligned, the system recommended bull-market strategies in bear markets and vice versa across nearly every regime.Closes #15.
The misalignment (before this PR)
When the labeler tagged a market BULL_TRENDING (0) and the model learned to output 0, the factory mapped 0 to "Deep Bear Market" and recommended
LONG_PUT/BEAR_PUT_SPREAD/BEAR_CALL_SPREAD.Changes
src/strategies/factory.py_build_regime_mappings()realigned toRegimeTypesemantics (0=BULL_TRENDING … 7=CRISIS)RegimeDetectoremits 8 classes, indices 0–7)_assess_expected_performance()performance map realigned_assess_risk_for_regime()high_risk_regimescorrected to[1, 2, 6, 7](BEAR_TRENDING, HIGH_VOLATILITY, DISTRIBUTION, CRISIS)RegimeTypeas the source of truthtests/strategies/test_factory.pytest_regime_mappings_match_labeler_numbering: a regression guard that fails if the factory and labeler diverge againtests/strategies/test_integration.pyWhy the bug survived
The pre-existing
test_factory.pyasserted that regime 0 should produce bearish strategies and regime 1 bullish — i.e. it validated the inverted mapping. Passing tests that encode a bug make the bug permanent. The new regression test ties the factory's directional output back to the documentedRegimeTypenumbering so this cannot silently re-invert.Required follow-up: retraining
This is a code fix, not a full remediation. Any model checkpoint trained before this change learned feature → wrong-regime-integer associations and must be discarded and retrained after merge. No checkpoints are committed to the repo, so there is nothing to delete here — this is a heads-up for anyone holding local/remote weights.
Two upstream issues should be resolved before a useful retrain, since they corrupt the training input itself:
RegimeStateVectorassembles 21D by default, butRegimeDetectorexpects 48DTesting
Verification was scoped to
tests/strategies/because the rest of the suite currently fails to collect due to unrelated, separately-filed issues (#1 missingsrc.dataproviders, #6sys.exitat import, #7 missinggym). This PR touches none of those paths.🤖 Generated with Claude Code