feat: add backtest CLI for historical price simulation#12
Merged
Conversation
…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>
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
backtestbinary for simulating trades at historical dates with forward PnL analysis (+1/+2/+4/+7 days)Changes
src/backtest.rs— Historical data providers (Yahoo Finance, CoinGecko), simulated portfolio engine, PnL computationsrc/bin/backtest.rs— CLI entry point with clap argument parsingsrc/commands/quote.rs— Madesymbol_aliases()andcoingecko_symbol_map()public for reusesrc/commands/report.rs— Made SEC filing types/functions public; addedbefore_datefilter toget_filings()src/lib.rs— RegisterbacktestmoduleCargo.toml— Addbacktestbinary targetREADME.md— Full documentation: quick guide, capability matrix, command reference, JSON mode examplestests/backtest/— E2E test scripts for all backtest commandsexamples/backtest/— Example strategy scripts (COVID crash hedge, FTX contagion, NVDA earnings, Ukraine oil shock)tests/helpers.sh— AddBACKTESTbinary to build/check helpersTest plan
cargo build --releasecompiles the newbacktestbinarybacktest --at 2025-01-15 quote BTCreturns historical BTC pricebacktest --at 2025-01-15 buy AAPL --amount 10shows forward PnL tablebacktest --at 2025-01-15 balanceshows portfolio statebacktest --at 2025-01-15 resetclears portfoliotests/backtest/e2e_backtest.shfor full E2E coverage🤖 Generated with Claude Code