zhengxinjipai

Backtesting Trading Strategies

专业领域v2.0.0
作者:zhengxinjipai更新于 2026-05-11backtesting-trading-strategies
#Trading Strategy

据 AlphaMoat 统计,截至 2026-09,Backtesting Trading Strategies 累计下载 3,865 次、获 0 个星标,在全部 5,078 个 AI 技能中排名第 2,696 位,在「专业领域」分类(465 个)中排名第 224 位。

累计安装
105
累计下载
3,865
星标
-
全站排名
#2,696
全站前 54% · 「专业领域」前 49%
平台累计安装累计下载星标评论
ClawHub ↗1053,865--

各平台的计数口径不同,统计时间不一致。

这个技能是做什么的

回测依赖数据来源、交易成本、滑点和模型假设;历史表现不能保证未来结果,也不应直接作为交易指令。

资料发布于 2026-10-29

可以用来做什么

  • 比较不同策略在历史数据上的表现。
  • 检查风险指标、权益曲线和逐笔交易结果。
  • 规划参数搜索与结果复核。

什么时候用

  • 需要在实盘决策前检验交易策略假设时。
  • 需要查看历史收益、回撤和风险表现时。
  • 需要评估数据、手续费及滑点假设对回测结果的影响时。

示例提示词

以下是根据技能文档生成的示例,不代表实际运行结果。

概述该回测工作流能生成的分析输出及其限制。
列出判断历史回测是否适用于实际决策时要检查的假设。

月度数据趋势

累计下载3,865
1,2072,6354,0622026-03 · 累计下载 1,4042026-05 · 累计下载 3,0132026-06 · 累计下载 2,9002026-07 · 累计下载 3,3112026-08 · 累计下载 3,6482026-09 · 累计下载 3,86526-0326-09
星标-
0112026-03 · 星标 -2026-05 · 星标 -2026-06 · 星标 -2026-07 · 星标 -2026-08 · 星标 -2026-09 · 星标 -26-0326-09

2026-09 起统计方法调整:同名技能按作者分别统计,并覆盖全部技能。图中虚线为调整前的月份,与之后的数据不直接比较,也不计算跨越调整的增长。

月份累计下载环比星标
2026-093,865—-
2026-083,648+10.2%-
2026-073,311+14.2%-
2026-062,900-3.8%-
2026-053,013—-
2026-031,404—-

SKILL.md 原文

以下是作者发布的原始文件,按纯文本显示,本站未做修改或审核;其中的链接不可点击,命令请核实后再运行。抓取于 2026-10-23。

6.2 KB · ClawHub v2.0.0
---
name: backtesting-trading-strategies
description: |
  Backtest crypto and traditional trading strategies against historical data.
  Calculates performance metrics (Sharpe, Sortino, max drawdown), generates equity curves,
  and optimizes strategy parameters. Use when user wants to test a trading strategy,
  validate signals, or compare approaches.
  Trigger with phrases like "backtest strategy", "test trading strategy", "historical performance",
  "simulate trades", "optimize parameters", or "validate signals".
allowed-tools: Read, Write, Edit, Grep, Glob, Bash(python:*)
展开全部(共 201 行)
version: 2.0.0
author: Jeremy Longshore <[email protected]>
license: MIT
---

# Backtesting Trading Strategies

## Overview

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:**
- 8 pre-built trading strategies (SMA, EMA, RSI, MACD, Bollinger, Breakout, Mean Reversion, Momentum)
- Full performance metrics (Sharpe, Sortino, Calmar, VaR, max drawdown)
- Parameter grid search optimization
- Equity curve visualization
- Trade-by-trade analysis

## Prerequisites

Install required dependencies:

```bash
pip install pandas numpy yfinance matplotlib
```

Optional for advanced features:
```bash
pip install ta-lib scipy scikit-learn
```

## Instructions

### Step 1: Fetch Historical Data

```bash
python {baseDir}/scripts/fetch_data.py --symbol BTC-USD --period 2y --interval 1d
```

Data is cached to `{baseDir}/data/{symbol}_{interval}.csv` for reuse.

### Step 2: Run Backtest

Basic backtest with default parameters:

```bash
python {baseDir}/scripts/backtest.py --strategy sma_crossover --symbol BTC-USD --period 1y
```

Advanced backtest with custom parameters:

```bash
# Example: backtest with specific date range
python {baseDir}/scripts/backtest.py \
  --strategy rsi_reversal \
  --symbol ETH-USD \
  --period 1y \
  --capital 10000 \
  --params '{"period": 14, "overbought": 70, "oversold": 30}'
```

### Step 3: Analyze Results

Results are saved to `{baseDir}/reports/` including:
- `*_summary.txt` - Performance metrics
- `*_trades.csv` - Trade log
- `*_equity.csv` - Equity curve data
- `*_chart.png` - Visual equity curve

### Step 4: Optimize Parameters

Find optimal parameters via grid search:

```bash
python {baseDir}/scripts/optimize.py \
  --strategy sma_crossover \
  --symbol BTC-USD \
  --period 1y \
  --param-grid '{"fast_period": [10, 20, 30], "slow_period": [50, 100, 200]}'
```

## Output

### Performance Metrics

| 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 |

### Risk Metrics

| 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 |

### Trade Statistics

| 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 |

### Example Output

```
================================================================================
                    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
================================================================================
```

## Supported Strategies

| 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 | `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` |

## Configuration

Create `{baseDir}/config/settings.yaml`:

```yaml
data:
  provider: yfinance
  cache_dir: ./data

backtest:
  default_capital: 10000
  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
```

## Error Handling

See `{baseDir}/references/errors.md` for common issues and solutions.

## Examples

See `{baseDir}/references/examples.md` for detailed usage examples including:
- Multi-asset comparison
- Walk-forward analysis
- Parameter optimization workflows

## Files

| 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 |

## Resources

- [yfinance](https://github.com/ranaroussi/yfinance) - Yahoo Finance data
- [TA-Lib](https://ta-lib.org/) - Technical analysis library
- [QuantStats](https://github.com/ranaroussi/quantstats) - Portfolio analytics

「专业领域」分类下的热门技能

zhengxinjipai 的其他技能

数据月份:2026-09 · 下载/星标/安装数聚合自公开技能注册库(ClawHub、SkillHub),按月更新。口径说明见数据方法。