Skip to content

feat: add backtest CLI for historical price simulation#12

Merged
juntao merged 4 commits intomainfrom
feat/backtest
Mar 15, 2026
Merged

feat: add backtest CLI for historical price simulation#12
juntao merged 4 commits intomainfrom
feat/backtest

Conversation

@juntao
Copy link
Member

@juntao juntao commented Mar 15, 2026

Summary

  • Add new backtest binary for simulating trades at historical dates with forward PnL analysis (+1/+2/+4/+7 days)
  • Supports spot and perp trades with persistent portfolio state, leverage settings, and auto-pricing from historical close prices
  • Includes SEC filing date filtering, Yahoo Finance and CoinGecko data sources, and full JSON mode support
  • No API keys or wallet configuration required — all data is read-only from public sources

Changes

  • src/backtest.rs — Historical data providers (Yahoo Finance, CoinGecko), simulated portfolio engine, PnL computation
  • src/bin/backtest.rs — CLI entry point with clap argument parsing
  • src/commands/quote.rs — Made symbol_aliases() and coingecko_symbol_map() public for reuse
  • src/commands/report.rs — Made SEC filing types/functions public; added before_date filter to get_filings()
  • src/lib.rs — Register backtest module
  • Cargo.toml — Add backtest binary target
  • README.md — Full documentation: quick guide, capability matrix, command reference, JSON mode examples
  • tests/backtest/ — E2E test scripts for all backtest commands
  • examples/backtest/ — Example strategy scripts (COVID crash hedge, FTX contagion, NVDA earnings, Ukraine oil shock)
  • tests/helpers.sh — Add BACKTEST binary to build/check helpers

Test plan

  • cargo build --release compiles the new backtest binary
  • backtest --at 2025-01-15 quote BTC returns historical BTC price
  • backtest --at 2025-01-15 buy AAPL --amount 10 shows forward PnL table
  • backtest --at 2025-01-15 balance shows portfolio state
  • backtest --at 2025-01-15 reset clears portfolio
  • Run tests/backtest/e2e_backtest.sh for full E2E coverage

🤖 Generated with Claude Code

juntao and others added 4 commits March 15, 2026 01:44
…nL analysis

Add a new `backtest` binary that simulates trades at historical dates and
computes forward PnL at +1/+2/+4/+7 days using Yahoo Finance and CoinGecko
data. Supports spot and perp trades with persistent portfolio state, leverage
settings, and SEC filing date filtering. No API keys or wallet required.

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove unused `close` field from JSON PerpBuy/PerpSell variants, fix
print_literal warning, and suppress too_many_arguments for cmd_trade.

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The trade JSON output uses `.trade.type` not `.trade.tradeType`.
Fixed in sell_spot.sh, perp_buy.sh, and perp_sell.sh.

Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Michael Yuan <michael@secondstate.io>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@juntao juntao merged commit 4e61ca6 into main Mar 15, 2026
2 checks passed
@juntao juntao deleted the feat/backtest branch March 15, 2026 09:24
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