Commit Graph

39 Commits

Author SHA1 Message Date
3abc51e3e3 feat: add OHLCV market data updater 2026-04-17 23:59:06 +08:00
7239310be3 docs: add US alpha research design spec 2026-04-17 23:41:10 +08:00
5e1c4a681d Add point-in-time S&P 500 backtest to expose survivorship bias
The existing framework fetches today's S&P 500 constituents from Wikipedia
and applies that list to the entire 10-year price history — classic
survivorship bias. Stocks that went bankrupt or were removed for poor
performance are absent, while today's winners (which may have been minor
names 10 years ago) are implicitly selected. This materially inflates
reported strategy returns.

New pipeline:
  - universe_history.py reconstructs per-ticker membership intervals by
    walking Wikipedia's "Selected changes" table backward from today.
  - research/fetch_historical.py downloads prices for all 848 tickers
    that were ever members (Yahoo returns ~675 of them; ~170 fully
    delisted names are unavailable — remaining partial bias).
  - research/pit_backtest.py masks prices to NaN outside membership
    windows so strategies naturally cannot select non-members.
  - research/strategies_plus.py adds RecoveryMomentumPlus (generalized
    Recovery+Momentum with configurable weighting / blend / regime hook)
    and an EnsembleStrategy.
  - research/optimize.py runs five experiments: bias drift, hyperparameter
    sweep (2016-2022 train / 2023-2026 test), SPY MA regime filter,
    weighting schemes, and an uncorrelated-config ensemble.

Headline finding: the biased backtest reports 40.9% CAGR for
recovery_mom_top10 over 2016-2026; the point-in-time version reports
22.4% (vs 14.0% SPY buy-and-hold). True edge is ~8pp CAGR, not ~27pp.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-17 16:26:02 +08:00
2015b62104 Charge 5 CNY per A-share trade via per-market fee table
Add MARKET_FEES {us: 2, cn: 5} so the monitor and cron (auto) paths
automatically apply the correct local-currency fixed commission without
needing a per-strategy override. CLI --fixed-fee still wins when set
explicitly for auto; monitor now always resolves from the table so its
banner and each strategy sub-call agree.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:32:41 +08:00
b2176b0c3e Record daily snapshot in cmd_evening for monitor NAV tracking
cmd_evening (used by the monitor path) only updated the simple daily_equity
dict, so daily_log had gaps on every monitor-driven day. Mirror cmd_auto's
pattern and call record_daily_snapshot so each strategy's NAV is recorded
every trading day, even when no trades execute.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-11 13:15:09 +08:00
ae25f2f6b5 Add 32 factor-combo strategies with configurable rebalancing frequency
New FactorComboStrategy class (strategies/factor_combo.py) implements
8 champion factor signals (4 US, 4 CN) discovered through iterative
factor research, each at 4 rebalancing frequencies (daily/weekly/
biweekly/monthly). Registered in trader.py as fc_{signal}_{freq}.

Existing strategies and state files are untouched — safe to git pull
and restart monitor on server.

Also includes factor research scripts (factor_loop.py, factor_research.py,
etc.) used to discover and validate these factors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-08 10:41:34 +08:00
a66b039d2d Reject empty attribution semantics headers 2026-04-07 18:10:21 +08:00
88d765713e Reject colliding attribution semantics headers 2026-04-07 18:10:21 +08:00
35a91ba6cc Honor complete attribution beta semantics labels 2026-04-07 18:10:21 +08:00
b3d87b3d92 Harden attribution beta semantics fallback 2026-04-07 18:10:21 +08:00
097131d962 Add attribution beta semantics metadata 2026-04-07 18:10:21 +08:00
82a3e63c2b Restore summary schema for proxy attribution 2026-04-07 18:10:21 +08:00
69a03f52d9 Fix proxy attribution benchmark and labeling 2026-04-07 18:10:21 +08:00
9c4a219c68 Integrate factor attribution into backtest CLI 2026-04-07 18:10:21 +08:00
f6670d9e6d Normalize one-point regression residual volatility 2026-04-07 17:02:00 +08:00
18174a9e11 Compute residual vol for square regressions 2026-04-07 16:57:58 +08:00
3d934b3316 Handle square factor regressions without inference 2026-04-07 16:53:16 +08:00
0876c0b6af Guard factor regressions against unidentified models 2026-04-07 16:48:23 +08:00
f2e14ec200 Add factor attribution regression engine 2026-04-07 16:40:24 +08:00
507565c556 Tighten benchmark mutation leakage test 2026-04-07 16:34:35 +08:00
26937f035e Split proxy leakage tests 2026-04-07 16:31:51 +08:00
7afc60dfcb Strengthen proxy factor builder tests 2026-04-07 16:28:00 +08:00
7e44ece569 Add factor builder leakage tests 2026-04-07 16:21:05 +08:00
7e8d24c1e9 Add local attribution factor builders 2026-04-07 16:16:59 +08:00
2382364a46 Handle HTTP protocol errors in factor download 2026-04-07 16:12:00 +08:00
71912b8358 Wrap additional network errors in factor download 2026-04-07 16:06:54 +08:00
7f0c5de574 Use explicit download errors for factor loader fallback 2026-04-07 16:01:51 +08:00
c46727b1ca Handle OSError download fallback for factor loader 2026-04-07 15:57:16 +08:00
0e94688066 Narrow factor loader format fallback handling 2026-04-07 15:51:57 +08:00
9e6da727a3 Implement Ken French factor download and cache fallback 2026-04-07 15:44:46 +08:00
e70922d9af Harden factor loader zip parsing and fallback 2026-04-07 15:38:49 +08:00
feb1864a4d Add factor loader and cache scaffolding 2026-04-07 15:27:44 +08:00
80493cb6af Add factor attribution design spec 2026-04-07 15:01:57 +08:00
14ec64c1da Single-process monitor for US + CN markets
- `trader.py monitor` now handles all markets in one process
  (US 9:45/16:35 ET, CN 9:45/15:35 CST) with unified UTC event loop
- Events from different markets/timezones are merged; sleeps until
  the globally next event across all markets
- Overlapping events (e.g. US evening + CN morning) fire together
- `trader.py compare` defaults to US, use --market cn for A-shares
- One tmux session handles everything: just `uv run python trader.py monitor`

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 00:16:46 +08:00
4aa17c7e98 Zero-config monitor and compare
- `trader.py monitor` — runs ALL 9 strategies by default, $10k capital,
  $2 fee, integer shares. Just start and forget.
- `trader.py compare` — auto-discovers all state files in data/, no
  --strategy needed. Ranks by return with equity curves.
- Monitor defaults: --capital 10000, --fixed-fee 2.0, --integer-shares

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 00:10:00 +08:00
7f618b9c31 Multi-strategy monitor and compare command
- Monitor accepts multiple --strategy args, runs all at each phase
- Each strategy maintains its own independent state file
- Add 'compare' subcommand: side-by-side ranking table + equity curves
- Error in one strategy doesn't block others (isolated try/catch)

Usage:
  trader.py monitor --strategy recovery_mom_top10 momentum dual_momentum
  trader.py compare --strategy sim_recovery_mom_top10 sim_momentum

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-07 00:04:45 +08:00
942164a38f Two-phase monitor, integer shares, and daily log
- Monitor now runs morning (9:45 → signals) and evening (4:35 → execute)
  instead of single daily run; falls back to auto if morning missed
- Add --integer-shares flag for whole-share-only trading (no fractional)
- Add daily_log to state: each day records holdings, cash, and operations
- Add 'log' subcommand to view daily snapshots with date range filter
- record_daily_snapshot() called from both simulate and auto commands

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 23:57:03 +08:00
4709271504 auto mode for continuous running 2026-04-05 00:50:26 +08:00
42218741d4 Initial commit: quant backtesting framework with daily trading simulator
Backtesting engine supporting 11 strategies across US (S&P 500) and CN (CSI 300)
markets with open-to-close execution, proportional + fixed per-trade fees.

Daily trader (trader.py) with auto/morning/evening/simulate/status commands
and cron-friendly `auto` mode for unattended daily runs on a server.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-05 00:41:19 +08:00