mirror of
https://ghfast.top/https://github.com/aeroxw/easy-tdx.git
synced 2026-09-12 20:24:16 +08:00
Root cause: _generate_signals() iterated all bars calling strategy.next() but never updated _position_size or _cash on the strategy. Strategies that check self.position['size'] before buy/sell always saw 0, producing only BUY signals with no SELL — exhausting cash and producing drawdowns exceeding 100%. Fix: add _update_strategy_position() that estimates position changes after each bar's signals using close price. This gives the strategy an accurate view of its holdings so it can correctly alternate buy/sell. Regression tests added: - test_position_aware_buy_sell_alternation: verifies BUY/SELL alternation - test_position_aware_no_duplicate_buys: no suspicious tiny duplicate buys Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>