Skip to content

Add backtesting framework, parameter optimization, and drift metrics - #23

Merged
IamJasonBian merged 2 commits into
mainfrom
feature/backtests-drift-metrics-optimization
Feb 19, 2026
Merged

IamJasonBian merged 2 commits into
mainfrom
feature/backtests-drift-metrics-optimization

Conversation

@IamJasonBian

Copy link
Copy Markdown
Owner

Summary

  • Backtesting suite: Full BTC DCA simulation engine with options hedging (protective puts, collars), drawdown strategies (cash reserve, trailing stop, adaptive sizing), and SPY/QQQ buy-and-hold benchmarks — generates a 31-page comparison PDF with charts, risk analysis, and limitations
  • Parameter optimization: Grid search over stop_offset × buy_offset × coverage_threshold (75+ combos), rolling 21-day metrics, drift detection, and volatility regime classification. Strategy defaults updated to optimized values: stop=1.25%, buy=$0.50, coverage=25%, lot_size=200
  • Drift metrics in state snapshot: Each run_once() cycle now computes rolling Sharpe, volatility, regime, and suggested params — uploaded to Netlify Blobs alongside the order book for dashboard consumption
  • Order management improvements: Cancel-before-replace logic, Order entity extended with side/order_id/created_at, cancel_order_by_id with state verification, Slack oncall summaries
  • Housekeeping: Replace emoji with text indicators for CI compatibility, add IWM to symbol map, add strategy docs

Test plan

  • Run python -m trading_system.backtests.strategy_comparison_backtest — verify 31-page PDF generates with all sections
  • Run pytest tests/ — verify all unit tests pass (order entities, state manager, momentum DCA, simulation, order replacement)
  • Dry-run the trading system and verify drift_metrics appears in local state log JSON
  • Verify strategy defaults match optimized values (stop=0.0125, buy=0.50, coverage=0.25)

🤖 Generated with Claude Code

Jason Bian and others added 2 commits February 19, 2026 04:59
- Add full backtesting suite: BTC DCA simulation, options hedging (puts/collars),
  drawdown strategies (cash reserve, trailing stop, adaptive sizing), and
  SPY/QQQ buy-and-hold benchmarks
- Add parameter optimizer with grid search over stop_offset × buy_offset ×
  coverage_threshold, rolling 21-day metrics, drift detection, and
  volatility regime classification
- Generate 31-page comparison PDF with charts, risk analysis, and backtest
  limitations
- Update strategy defaults to grid-search-optimized values:
  stop_offset=1.25%, buy_offset=$0.50, coverage=25%, lot_size=200
- Add drift metrics to Netlify Blobs state snapshot (rolling Sharpe,
  volatility, regime, suggested params, drift alerts)
- Add order replacement logic with cancel-before-replace and PDT safety
- Extend Order entity with side, order_id, created_at fields
- Add cancel_order_by_id to SafeCashBot with state verification
- Add Slack oncall summary notifications
- Add IWM to Twelve Data symbol map
- Replace emoji with text indicators in logs for CI/terminal compatibility
- Add docs: strategy writeup PDF and comparison backtest PDF

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Pipe drift_metrics from main.py into market_data.json so the dashboard
can render regime status, rolling Sharpe/vol/return stat cards, a
parameter comparison table, and a pulsing alert banner when Sharpe < -1.0
or regime is HIGH_VOL.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@IamJasonBian
IamJasonBian merged commit cc38b0d into main Feb 19, 2026
3 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant