Backtest stock trading strategies on historical OHLCV data and report win rate, return, CAGR, drawdown, Sharpe ratio, and trade logs. Use when evaluating or...
Documents
Stock Backtest Analyst
Run long-only backtests on daily stock OHLCV CSVs and get standardized performance metrics plus a trade log.
What it does
A bundled script that validates a daily price CSV, applies one of three strategy rules (SMA crossover, RSI mean reversion, or breakout), and emits a JSON object to stdout containing the chosen strategy, the test period, performance metrics, the run configuration, and a per-trade log. Metrics include total return, CAGR, win rate, max drawdown, Sharpe ratio, profit factor, and trade count. Commission and slippage are configurable in basis points so the same cost model can be applied across parameter variants, and signals are computed on bar t with execution at bar t+1 to reduce look-ahead.
When to use it
- Comparing SMA crossover fast/slow windows on a single daily series
- Testing RSI oversold entry and recovery exit thresholds under a fixed cost model
- Sweeping breakout lookback windows against the same benchmark period
- Producing a JSON trade log for downstream review pipelines
The skill document
Stock Strategy Backtester
Version Notice
1.0.0and1.0.1are deprecated.- Use
1.0.2or newer only. - Deprecation reason: early versions bundled non-core marketplace automation files and may trigger security scanner warnings in some environments.
Overview
Run repeatable, long-only stock strategy backtests from daily OHLCV CSV files. Use bundled scripts to generate consistent metrics and trade-level output, then summarize with investor-friendly conclusions.
Quick Start
- Prepare a CSV with at least
DateandClosecolumns. - Run a baseline backtest:
python scripts/backtest_strategy.py \
--csv /path/to/prices.csv \
--strategy sma-crossover \
--fast-window 20 \
--slow-window 60
- Export artifacts for review:
python scripts/backtest_strategy.py \
--csv /path/to/prices.csv \
--strategy rsi-reversion \
--rsi-period 14 \
--rsi-entry 30 \
--rsi-exit 55 \
--commission-bps 5 \
--slippage-bps 2
Workflow
- Validate data
- Ensure
Dateis parseable and sorted ascending. - Ensure
Open/High/Low/Closeare numeric; missingOpen/High/Lowfalls back toClose.
- Pick strategy logic
sma-crossover: trend-following with fast/slow moving averages.rsi-reversion: buy oversold and exit on momentum recovery.breakout: enter on highs breakout and exit on lows breakdown.
- Set realistic assumptions
- Always set
--commission-bpsand--slippage-bps. - Avoid reporting cost-free backtests as production-ready.
- Compare variants
- Change one parameter block at a time.
- Compare on the same date range and same cost model.
- Produce final summary
- Report:
total_return_pct,cagr_pct,win_rate_pct,max_drawdown_pct,sharpe_ratio,profit_factor, and trade count. - Use trade CSV to explain where alpha is coming from.
Supported Commands
- Baseline SMA strategy:
python scripts/backtest_strategy.py \
--csv /path/to/prices.csv \
--strategy sma-crossover \
--fast-window 10 \
--slow-window 50
- Breakout strategy:
python scripts/backtest_strategy.py \
--csv /path/to/prices.csv \
--strategy breakout \
--lookback 20
- JSON-only output (for automation pipelines):
python scripts/backtest_strategy.py \
--csv /path/to/prices.csv \
--strategy rsi-reversion \
--quiet
Output Contract
- Script prints a JSON object to stdout with:
strategyperiodmetricsconfigtrades
Analysis Guardrails
- Use out-of-sample logic
- Prefer walk-forward validation over one-shot tuning.
- Avoid leakage
- Compute signals from bar
t, execute at bart+1open.
- Report downside with upside
- Never present return without drawdown and trade count.
- Treat results as research
- Backtests are not guarantees and should not be framed as financial advice.
References
- Metrics details:
references/backtest-metrics.md
Questions people ask
- What input format is required?
- A daily OHLCV CSV with at least `Date` and `Close` columns; missing `Open/High/Low` values fall back to `Close`, and `Date` must be parseable and sorted ascending.
- Which strategies are built in?
- Three are documented: `sma-crossover` (trend-following with fast/slow moving averages), `rsi-reversion` (buy oversold, exit on momentum recovery), and `breakout` (enter on highs, exit on lows).
- How should the numbers be interpreted?
- The skill's own guardrails state that backtests are research, not guarantees, recommend walk-forward over one-shot tuning, and require reporting drawdown and trade count alongside any return figure.
Related skills
Financial analysis from single-stock metrics to DCF models and portfolio optimization, delivered as dashboards, PDFs, or Excel.
Backtest, extract, and analyze trading strategies across A-share, HK, US, India, Korea, and crypto markets from a single toolkit.
Trade crypto, manage a multi-chain wallet, and query an AI analyst from one CLI.
Deep crypto research covering tokens, DeFi protocols, on-chain data, and portfolio strategy from a single prompt.
Stock terminal for AI agents. Turns chat into a futuristic financial terminal: typed commands like "open NVDA", "screen smart-money", "daily brief", or natural questions like "what's hot today?" return composite synthesized reports across price, sentiment, insider trades, congressional disclosures, institutional flows, analyst ratings, AI insights, and embedded news. Use for stock terminal, financial terminal for AI, daily market brief, open a ticker, screen stocks by smart money, what is hot today, one-command stock research. Read-only. No trading, no purchases, no write operations, no wallet access.