refactor: engine.py God Object 분해 (C2) + 선물/스캘핑 시스템#7
Open
nunionda wants to merge 6 commits into
Open
Conversation
4-phase plan to reduce engine.py from 6689 to ~1900 lines: - Phase A: constants, models, allocator extraction (zero risk) - Phase B: regime, risk gates, indicators, sizing - Phase C: 7 strategy modules to simulation/strategies/ - Phase D: dispatcher cleanup with strategy registry Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…se A) Phase A of engine.py decomposition - zero-risk extractions: - constants.py: regime params, strategy weights, ETF universes (~345 lines) - models.py: 8 Pydantic models (SimPosition, SimSignal, etc.) (~130 lines) - allocator.py: StrategyAllocator class + _compute_adx helper (~330 lines) All 58 tests pass. No behavioral changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…e B) Phase B domain logic extraction: - regime.py: market regime, index trend, stock regime classification (~300 lines) - risk_gates.py: RG1-RG5, bearish divergence, S/R detection (~170 lines) All 58 tests pass. No behavioral changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Phase B of C2 decomposition — domain logic extraction: - regime.py: market regime detection, index trend analysis, stock regime classification - risk_gates.py: RG1-RG5 checks, bearish divergence, S/R detection - indicators.py: MA/RSI/MACD/BB/ATR/ADX calculations, trend confirmation, stage estimation - sizing.py: VIX-based sizing multiplier All replaced with thin delegating wrappers in engine.py. 58/58 tests pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Phase C of C2 decomposition — strategy extraction: - strategies/momentum.py: 6-Phase pipeline scan + 7-tier exit cascade - strategies/smc.py: SMC 4-Layer scoring + CHoCH exits - strategies/mean_reversion.py: MR indicators, scoring, scan + exits - strategies/breakout_retest.py: BRT 4-Layer + retest zone scoring - strategies/arbitrage.py: pair discovery, basis gate, spread scoring - strategies/defensive.py: safe-haven/inverse ETF rotation - strategies/volatility.py: VIX premium capture Engine.py reduced from 5208 to 2159 lines. 58/58 tests pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Phase D cleanup — strategy dispatch simplification: - Add _STRATEGY_MODULES registry mapping strategy names to modules - Replace if/elif chains in _scan_entries, _check_exits, _scan_entries_multi, _check_exits_multi with single registry lookups - Remove 185 lines of dead delegating wrapper methods Engine.py: 2159 → 1942 lines. 58/58 tests pass. Co-Authored-By: Claude Opus 4.6 <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
simulation/engine.py6,689줄 → 1,942줄 (71% 감소)Engine Decomposition 상세
constants.pymodels.pyallocator.pyregime.pyrisk_gates.pyindicators.pysizing.pystrategies/momentum.pystrategies/smc.pystrategies/mean_reversion.pystrategies/breakout_retest.pystrategies/arbitrage.pystrategies/defensive.pystrategies/volatility.pyTest plan
python3 run_tests.py— 58/58 테스트 통과🤖 Generated with Claude Code