Stock Strategy Backtester — Stock Strategy Back测试器
v1.0.4Backtest stock trading strategies on historical OHLCV data and 报告 win rate, return, CAGR, drawdown, Sharpe ratio, and trade 记录s. Use when evaluating or comparing strategy rules (SMA crossover, RSI mean reversion, breakout), quantifying transaction-cost impact, tuning parameters, or generating performance summaries from CSV data. Trigger for 请求s like "回测股票策略胜率", "测收益率", "compare two strategy backtests", and "build a strategy 报告 from historical prices".
运行时依赖
安装命令
点击复制技能文档
Stock Strategy Back测试器 Version Notice 1.0.0 and 1.0.1 are deprecated. Use 1.0.2 or newer only. Deprecation reason: early versions bundled non-core marketplace 自动化 files and may trigger security 扫描器 警告s in some 环境s. Overview
运行 repeatable, long-only stock strategy backtests from dAIly OHLCV CSV files. Use bundled scripts to 生成 consistent 指标 and trade-level 输出, then summarize with investor-friendly conclusions.
Quick 启动 Prepare a CSV with at least Date and Close columns. 运行 a baseline backtest: python scripts/backtest_strategy.py \ --csv /path/to/prices.csv \ --strategy sma-crossover \ --fast-window 20 \ --slow-window 60
导出 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
工作流 验证 data Ensure Date is 解析able and 排序ed ascending. Ensure Open/High/Low/Close are numeric; missing Open/High/Low falls back to Close. Pick strategy 记录ic sma-crossover: trend-following with fast/slow moving averages. rsi-reversion: buy oversold and exit on momentum 恢复y. breakout: enter on highs breakout and exit on lows breakdown. 设置 rea列出ic assumptions Always 设置 --commission-bps and --slippage-bps. Avoid 报告ing cost-free backtests as production-ready. Compare variants Change one parameter block at a time. Compare on the same date range and same cost 模型. Produce final summary 报告: 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 输出 (for 自动化 流水线s): python scripts/backtest_strategy.py \ --csv /path/to/prices.csv \ --strategy rsi-reversion \ --quiet
输出 Contract Script prints a JSON object to stdout with: strategy period 指标 config trades Analysis 防护rAIls Use out-of-sample 记录ic Prefer walk-forward 验证 over one-shot tuning. Avoid leakage Compute 签名als from bar t, 执行 at bar t+1 open. 报告 downside with upside Never present return without drawdown and trade count. Treat 结果s as re搜索 Backtests are not guarantees and should not be framed as financial advice. References 指标 detAIls: references/backtest-指标.md