backtesting-trading-strategies by jeremylongshore/claude-code-plugins-plus-skills
npx skills add https://github.com/jeremylongshore/claude-code-plugins-plus-skills --skill backtesting-trading-strategies在投入真实资金前,使用历史数据验证交易策略。此技能提供了一个完整的回测框架,包含 8 种内置策略、全面的性能指标和参数优化功能。
主要特性:
安装所需依赖:
set -euo pipefail
pip install pandas numpy yfinance matplotlib
高级功能可选安装:
set -euo pipefail
pip install ta-lib scipy scikit-learn
获取历史数据(将缓存到 ${CLAUDE_SKILL_DIR}/data/ 以供重用):
python ${CLAUDE_SKILL_DIR}/scripts/fetch_data.py --symbol BTC-USD --period 2y --interval 1d
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
使用默认或自定义参数运行回测:
python ${CLAUDE_SKILL_DIR}/scripts/backtest.py --strategy sma_crossover --symbol BTC-USD --period 1y
python ${CLAUDE_SKILL_DIR}/scripts/backtest.py \
--strategy rsi_reversal \
--symbol ETH-USD \
--period 1y \
--capital 10000 \ # 10000: 10 seconds in ms
--params '{"period": 14, "overbought": 70, "oversold": 30}'
分析保存到 ${CLAUDE_SKILL_DIR}/reports/ 的结果——包括 *_summary.txt(性能指标)、*_trades.csv(交易日志)、*_equity.csv(权益曲线数据)和 *_chart.png(可视化权益曲线)。
通过网格搜索优化参数以找到最佳组合:
python ${CLAUDE_SKILL_DIR}/scripts/optimize.py \
--strategy sma_crossover \
--symbol BTC-USD \
--period 1y \
--param-grid '{"fast_period": [10, 20, 30], "slow_period": [50, 100, 200]}' # HTTP 200 OK
| 指标 | 描述 |
|---|---|
| 总回报率 | 总体百分比收益/损失 |
| 年复合增长率 | 复合年增长率 |
| 夏普比率 | 风险调整后收益(目标:>1.5) |
| 索提诺比率 | 下行风险调整后收益 |
| 卡尔玛比率 | 收益除以最大回撤 |
| 指标 | 描述 |
|---|---|
| 最大回撤 | 最大的峰谷跌幅 |
| 风险价值 (95%) | 95% 置信度下的风险价值 |
| 条件风险价值 (95%) | 超出 VaR 的预期损失 |
| 波动率 | 年化标准差 |
| 指标 | 描述 |
|---|---|
| 总交易次数 | 往返交易次数 |
| 胜率 | 盈利交易百分比 |
| 盈亏比 | 总利润除以总亏损 |
| 期望值 | 每笔交易的预期价值 |
================================================================================
BACKTEST RESULTS: SMA CROSSOVER
BTC-USD | [start_date] to [end_date]
================================================================================
PERFORMANCE | RISK
Total Return: +47.32% | Max Drawdown: -18.45%
CAGR: +47.32% | VaR (95%): -2.34%
Sharpe Ratio: 1.87 | Volatility: 42.1%
Sortino Ratio: 2.41 | Ulcer Index: 8.2
--------------------------------------------------------------------------------
TRADE STATISTICS
Total Trades: 24 | Profit Factor: 2.34
Win Rate: 58.3% | Expectancy: $197.17
Avg Win: $892.45 | Max Consec. Losses: 3
================================================================================
| 策略 | 描述 | 关键参数 |
|---|---|---|
sma_crossover | 简单移动平均线交叉 | fast_period, slow_period |
ema_crossover | 指数移动平均线交叉 | fast_period, slow_period |
rsi_reversal | RSI 超买/超卖 | period, overbought, oversold |
macd | MACD 信号线交叉 | fast, slow, signal |
bollinger_bands | 布林带均值回归 | period, std_dev |
breakout | 价格区间突破 | lookback, threshold |
mean_reversion | 回归移动平均线 | period, z_threshold |
momentum | 变化率动量 | period, threshold |
创建 ${CLAUDE_SKILL_DIR}/config/settings.yaml:
data:
provider: yfinance
cache_dir: ./data
backtest:
default_capital: 10000 # 10000: 10 seconds in ms
commission: 0.001 # 0.1% per trade
slippage: 0.0005 # 0.05% slippage
risk:
max_position_size: 0.95
stop_loss: null # Optional fixed stop loss
take_profit: null # Optional fixed take profit
常见问题及解决方案请参阅 ${CLAUDE_SKILL_DIR}/references/errors.md。
详细使用示例请参阅 ${CLAUDE_SKILL_DIR}/references/examples.md,包括:
| 文件 | 用途 |
|---|---|
scripts/backtest.py | 主回测引擎 |
scripts/fetch_data.py | 历史数据获取器 |
scripts/strategies.py | 策略定义 |
scripts/metrics.py | 性能计算 |
scripts/optimize.py | 参数优化 |
每周安装量
2.6K
代码仓库
GitHub 星标数
1.7K
首次出现
Jan 26, 2026
安全审计
安装于
opencode2.2K
gemini-cli2.2K
codex2.2K
github-copilot2.2K
kimi-cli2.2K
amp2.2K
Validate trading strategies against historical data before risking real capital. This skill provides a complete backtesting framework with 8 built-in strategies, comprehensive performance metrics, and parameter optimization.
Key Features:
Install required dependencies:
set -euo pipefail
pip install pandas numpy yfinance matplotlib
Optional for advanced features:
set -euo pipefail
pip install ta-lib scipy scikit-learn
Fetch historical data (cached to ${CLAUDE_SKILL_DIR}/data/ for reuse):
python ${CLAUDE_SKILL_DIR}/scripts/fetch_data.py --symbol BTC-USD --period 2y --interval 1d
Run a backtest with default or custom parameters:
python ${CLAUDE_SKILL_DIR}/scripts/backtest.py --strategy sma_crossover --symbol BTC-USD --period 1y
python ${CLAUDE_SKILL_DIR}/scripts/backtest.py \
--strategy rsi_reversal \
--symbol ETH-USD \
--period 1y \
--capital 10000 \ # 10000: 10 seconds in ms
--params '{"period": 14, "overbought": 70, "oversold": 30}'
Analyze results saved to ${CLAUDE_SKILL_DIR}/reports/ -- includes *_summary.txt (performance metrics), *_trades.csv (trade log), *_equity.csv (equity curve data), and *_chart.png (visual equity curve).
Optimize parameters via grid search to find the best combination:
python ${CLAUDE_SKILL_DIR}/scripts/optimize.py \
--strategy sma_crossover \
--symbol BTC-USD \
--period 1y \
--param-grid '{"fast_period": [10, 20, 30], "slow_period": [50, 100, 200]}' # HTTP 200 OK
| Metric | Description |
|---|---|
| Total Return | Overall percentage gain/loss |
| CAGR | Compound annual growth rate |
| Sharpe Ratio | Risk-adjusted return (target: >1.5) |
| Sortino Ratio | Downside risk-adjusted return |
| Calmar Ratio | Return divided by max drawdown |
| Metric | Description |
|---|---|
| Max Drawdown | Largest peak-to-trough decline |
| VaR (95%) | Value at Risk at 95% confidence |
| CVaR (95%) | Expected loss beyond VaR |
| Volatility | Annualized standard deviation |
| Metric | Description |
|---|---|
| Total Trades | Number of round-trip trades |
| Win Rate | Percentage of profitable trades |
| Profit Factor | Gross profit divided by gross loss |
| Expectancy | Expected value per trade |
================================================================================
BACKTEST RESULTS: SMA CROSSOVER
BTC-USD | [start_date] to [end_date]
================================================================================
PERFORMANCE | RISK
Total Return: +47.32% | Max Drawdown: -18.45%
CAGR: +47.32% | VaR (95%): -2.34%
Sharpe Ratio: 1.87 | Volatility: 42.1%
Sortino Ratio: 2.41 | Ulcer Index: 8.2
--------------------------------------------------------------------------------
TRADE STATISTICS
Total Trades: 24 | Profit Factor: 2.34
Win Rate: 58.3% | Expectancy: $197.17
Avg Win: $892.45 | Max Consec. Losses: 3
================================================================================
| Strategy | Description | Key Parameters |
|---|---|---|
sma_crossover | Simple moving average crossover | fast_period, slow_period |
ema_crossover | Exponential MA crossover | fast_period, slow_period |
rsi_reversal | RSI overbought/oversold |
Create ${CLAUDE_SKILL_DIR}/config/settings.yaml:
data:
provider: yfinance
cache_dir: ./data
backtest:
default_capital: 10000 # 10000: 10 seconds in ms
commission: 0.001 # 0.1% per trade
slippage: 0.0005 # 0.05% slippage
risk:
max_position_size: 0.95
stop_loss: null # Optional fixed stop loss
take_profit: null # Optional fixed take profit
See ${CLAUDE_SKILL_DIR}/references/errors.md for common issues and solutions.
See ${CLAUDE_SKILL_DIR}/references/examples.md for detailed usage examples including:
| File | Purpose |
|---|---|
scripts/backtest.py | Main backtesting engine |
scripts/fetch_data.py | Historical data fetcher |
scripts/strategies.py | Strategy definitions |
scripts/metrics.py | Performance calculations |
scripts/optimize.py | Parameter optimization |
Weekly Installs
2.6K
Repository
GitHub Stars
1.7K
First Seen
Jan 26, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode2.2K
gemini-cli2.2K
codex2.2K
github-copilot2.2K
kimi-cli2.2K
amp2.2K
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装
period, overbought, oversold |
macd | MACD signal line crossover | fast, slow, signal |
bollinger_bands | Mean reversion on bands | period, std_dev |
breakout | Price breakout from range | lookback, threshold |
mean_reversion | Return to moving average | period, z_threshold |
momentum | Rate of change momentum | period, threshold |