← 返回 Skills 市场
finskills

backtest-expert

作者 finskills · GitHub ↗ · v1.0.2 · MIT-0
cross-platform ✓ 安全检测通过
96
总下载
0
收藏
0
当前安装
3
版本数
在 OpenClaw 中安装
/install finskills-backtest-expert
功能描述
Design, execute, and evaluate quantitative trading strategies using historical price data and Fama-French factor attribution via the Finskills API.
使用说明 (SKILL.md)

Backtest Expert

Design, execute, and evaluate quantitative trading strategies using historical price data from the Finskills API. Transforms a natural-language strategy hypothesis into a rigorous backtest with performance metrics, drawdown analysis, Fama-French factor attribution, and walk-forward validation.


Setup

API Key requiredRegister at https://finskills.net to get your free key.
Header: X-API-Key: \x3Cyour_api_key>

Get your API key: Register at https://finskills.net — free tier available, Pro plan unlocks real-time quotes, history, and financials.


When to Activate This Skill

Activate when the user:

  • Describes a trading rule they want to test historically
  • Asks "how would X strategy have performed?"
  • Wants to validate a momentum, mean-reversion, or factor-based strategy
  • Asks about Sharpe ratio, maximum drawdown, or strategy performance metrics
  • Wants to see walk-forward or out-of-sample testing
  • Asks to compare two or more strategies head-to-head

Strategy Hypothesis Formulation

Before fetching data, clarify the strategy with the user:

  1. Universe: Which stocks? (Single stock, S&P 500, sector, custom list)
  2. Signal: What is the entry trigger? (Moving average crossover, RSI level, fundamental metric, etc.)
  3. Entry: Long, Short, or Long/Short?
  4. Exit: Trailing stop, fixed target, time-based, signal reversal?
  5. Holding Period: Daily, weekly, monthly?
  6. Position Sizing: Equal weight, volatility-adjusted, Kelly?
  7. Benchmark: SPY (default) or sector ETF?

State the strategy in a formal grammar:

ENTRY:  Buy {SYMBOL} when {condition}
EXIT:   Sell when {condition} OR stop at {-X%}
HOLD:   Max {N} days / bars
SIZING: {$N fixed / X% of portfolio / equal weight}
BENCH:  {SPY / QQQ / custom}
PERIOD: From {YYYY-MM-DD} to {YYYY-MM-DD}

Data Retrieval — Finskills API Calls

1. Historical OHLCV for Strategy Symbols

GET https://finskills.net/v1/stocks/history/{SYMBOL}?period=5y&interval=1d

Parameters:

  • period: 1y, 2y, 5y, 10y, max
  • interval: 1d (daily), 1wk (weekly), 1mo (monthly)

Extract: date, open, high, low, close, volume, adjustedClose

Repeat for each symbol in the strategy universe AND the benchmark (SPY or QQQ).

2. Fama-French 3-Factor Data

GET https://finskills.net/v1/free/market/fama-french

Extract: Mkt-RF (market excess return), SMB (small-minus-big), HML (high-minus-low), RF (risk-free rate)
Use for: Attribution analysis — what % of strategy return is explained by market, size, value factors


Analysis Workflow

Step 1 — Data Preparation

  1. Align all price series to the same trading calendar (drop non-overlapping dates).
  2. Use adjustedClose for all calculations (accounts for splits and dividends).
  3. Compute daily returns: r_t = (adjustedClose_t / adjustedClose_{t-1}) - 1
  4. Handle missing data: forward-fill up to 2 days; drop if missing > 2 consecutive days.

Step 2 — Signal Generation

Based on the strategy rules, generate entry/exit signals for each day in the backtest.

Example Signal Implementations:

Simple Moving Average Crossover:

SMA_fast = rolling_mean(adjustedClose, window=fast_n)
SMA_slow = rolling_mean(adjustedClose, window=slow_n)
Signal = 1 (Long)  when SMA_fast crosses above SMA_slow
Signal = 0 (Flat)  when SMA_fast crosses below SMA_slow

RSI Reversion:

RSI = 100 - 100 / (1 + avg_gain_14 / avg_loss_14)
Signal = 1 (Long)  when RSI \x3C 30 (oversold)
Signal = 0 (Flat)  when RSI > 70 (overbought)

Momentum:

Momentum_N = current_price / price_N_days_ago - 1
Signal = 1 when Momentum_N > threshold
Signal = 0 otherwise

Step 3 — Portfolio Returns Calculation

strategy_return_t = Signal_{t-1} × return_t   (signal from prior day, no lookahead)
benchmark_return_t = SPY daily return

Compute cumulative returns:

cumulative_return = PRODUCT(1 + strategy_return_t) - 1

Apply transaction costs (default: 0.10% per round-trip trade, adjustable):

cost_t = 0.001 × |Signal_t - Signal_{t-1}|  (cost only on signal changes)
net_return_t = strategy_return_t - cost_t

Step 4 — Performance Metrics

Compute the full performance scorecard:

Metric Formula
Total Return PRODUCT(1 + r_t) - 1
Annualized Return (CAGR) (1 + total_return)^(252/n_days) - 1
Annualized Volatility STD(r_t) × √252
Sharpe Ratio (CAGR - rf_rate) / annualized_vol
Sortino Ratio (CAGR - rf_rate) / downside_vol
Max Drawdown max(1 - V_t / max(V_s for s ≤ t))
Calmar Ratio CAGR / Max Drawdown
Win Rate % of trading days with positive return
Avg Win / Avg Loss mean positive return / mean negative return
Profit Factor sum wins / sum losses
Alpha (vs benchmark) CAGR_strategy - CAGR_benchmark
Beta COV(r_strategy, r_benchmark) / VAR(r_benchmark)
Information Ratio Alpha / tracking error
Number of Trades Count of signal transitions
Avg Holding Period Avg days per trade

Step 5 — Fama-French Factor Attribution

Regress strategy excess returns against F-F factors:

r_strategy - RF = α + β₁(Mkt-RF) + β₂(SMB) + β₃(HML) + ε

Interpret:

  • α (Alpha): Risk-adjusted return not explained by factors — the "skill" component
  • β₁ (Market Beta): Sensitivity to market direction
  • β₂ (SMB loading): Small-cap vs. large-cap tilt
  • β₃ (HML loading): Value (high) vs. growth (low) tilt
  • : How much of returns are explained by common factors (R² \x3C 0.3 = distinctive strategy)

Step 6 — Walk-Forward Validation

To detect overfitting, split the full history:

  • In-Sample (IS): First 60% of data — used to identify strategy parameters
  • Out-of-Sample (OOS): Last 40% — held out, tested after IS optimization

Walk-Forward Efficiency Ratio:

WFE = OOS_Sharpe / IS_Sharpe
  • WFE > 0.7: Strategy generalizes well — low overfitting concern
  • WFE 0.4–0.7: Some degradation — monitor live, reduce leverage
  • WFE \x3C 0.4: Likely overfit to historical data — do not trade with confidence

Step 7 — Risk Scenarios

Stress-test the strategy in 3 regimes:

  1. 2020 COVID Crash: Feb 19 – Mar 23, 2020 (S&P -34% in 33 days)
  2. 2022 Bear Market: Jan 1 – Dec 31, 2022 (S&P -19.4%)
  3. 2008 Financial Crisis: Oct 1 – Dec 31, 2008 (S&P -38% in quarter)

For each stress scenario, report the strategy's return vs. SPY return.


Output Format

╔══════════════════════════════════════════════════════════════════╗
║    BACKTEST REPORT  —  {STRATEGY NAME}                          ║
║    Period: {start_date}  to  {end_date}   ({N} trading days)   ║
╚══════════════════════════════════════════════════════════════════╝

📋 STRATEGY SUMMARY
  Universe:       {SYMBOL(s) or index}
  Entry Signal:   {description}
  Exit Signal:    {description}
  Position Type:  {Long / Long-Short}
  Benchmark:      {SPY / QQQ}
  Tx Cost:        0.10% per round-trip

📈 CUMULATIVE RETURNS
  Strategy:   +{X.X}%  ($100K → ${value}K)
  Benchmark:  +{X.X}%  ($100K → ${value}K)
  Alpha:      +{X.X}% annualized

📊 PERFORMANCE SCORECARD
               Strategy     Benchmark    Δ vs. Bench
  CAGR:         {X.X}%       {X.X}%      +{X.X}%
  Volatility:   {X.X}%       {X.X}%      
  Sharpe:        {X.XX}       {X.XX}      +{X.XX}
  Sortino:       {X.XX}       {X.XX}
  Max Drawdown: -{X.X}%      -{X.X}%
  Calmar:        {X.XX}       {X.XX}
  Win Rate:      {X.X}%       —
  Profit Factor: {X.XX}       —
  Avg Hold:      {N} days     —
  N Trades:      {count}      —

📉 DRAWDOWN ANALYSIS
  Worst Drawdown:       -{X}%  (from {date} to {date}, {N} days to recover)
  2nd Worst Drawdown:   -{X}%
  Average Drawdown:     -{X}%

🧬 FACTOR ATTRIBUTION (Fama-French)
  α (Annualized):   {X.XX}%  [{statistically significant yes/no}]
  β Market:         {X.XX}
  β SMB (size):     {X.XX}  [{small-cap / large-cap} tilt]
  β HML (value):    {X.XX}  [{value / growth} tilt]
  R² (explained):   {X}%

🔁 WALK-FORWARD VALIDATION
  In-Sample  ({dates}):  Sharpe {X.XX},  CAGR {X.X}%
  Out-of-Sample ({dates}): Sharpe {X.XX},  CAGR {X.X}%
  WF Efficiency Ratio:   {X.XX}  → {Generalizes well / Some degradation / Likely overfit}

💥 STRESS TEST
  2020 COVID Crash:    Strategy {+/-X}%  vs SPY -{X}%
  2022 Bear Market:    Strategy {+/-X}%  vs SPY -{X}%
  2008 Q4 Crash:       Strategy {+/-X}%  vs SPY -{X}%

🎯 VERDICT
  Signal Quality:   {Strong / Moderate / Weak / Overfit}
  Trade Live?       {Yes / Caution / No — further development needed}
  Suggested Refinement: {1–2 concrete suggestions to improve the strategy}

Limitations

  • Backtests suffer from survivorship bias (S&P 500 historical data excludes delisted companies).
  • Look-ahead bias is explicitly prevented by using prior-day signals; verify signal construction.
  • Slippage is not modeled (real-world execution will have impact beyond transaction cost assumption).
  • Fama-French data may have a 1–2 month lag; factors are smoothed — not for very recent periods.
  • Past performance in backtests does not guarantee future results.
安全使用建议
This skill appears internally consistent and only needs your Finskills API key to fetch historical prices and factor data. Before installing: 1) Confirm you trust finskills.net and the API key provider (don't reuse a high‑privilege key used elsewhere). 2) Check the Finskills plan limits and pricing (README mentions Pro for historical data) so you don't unexpectedly hit billing/rate limits. 3) Treat the API key as a secret—do not paste it into public places. 4) If you want to limit automation risk, review how your agent will be allowed to invoke the skill (it can run autonomously by default) and consider restricting automatic runs if you prefer manual approval.
功能分析
Type: OpenClaw Skill Name: finskills-backtest-expert Version: 1.0.2 The skill bundle is a legitimate tool designed for quantitative trading strategy backtesting using the Finskills API. It provides detailed instructions for an AI agent to fetch historical stock data, calculate performance metrics (Sharpe, Sortino, etc.), and perform Fama-French factor attribution. No evidence of data exfiltration, malicious execution, or prompt injection was found; the use of the FINSKILLS_API_KEY is strictly aligned with the stated purpose of accessing the financial data service at finskills.net.
能力标签
requires-sensitive-credentials
能力评估
Purpose & Capability
Name/description match the runtime instructions: the SKILL.md specifies fetching historical OHLCV and Fama‑French factor data from finskills.net and performing backtests and attribution. The sole declared credential (FINSKILLS_API_KEY) is appropriate for that purpose; no unrelated binaries, paths, or credentials are requested.
Instruction Scope
Runtime instructions are narrowly focused on forming strategy rules, calling the Finskills API endpoints, preparing price series, computing signals/returns, applying transaction costs, computing performance metrics, and running factor regressions. The instructions do not direct the agent to read arbitrary local files, grab unrelated environment variables, or POST data to third‑party endpoints other than finskills.net.
Install Mechanism
This is an instruction‑only skill with no install specification and no bundled code—therefore nothing is written to disk or downloaded during install. That is the lowest‑risk install surface and is proportionate to the skill's function.
Credentials
The skill requires a single API key (FINSKILLS_API_KEY) and declares it as the primary credential; this aligns with the declared use of the Finskills API. No extra secrets, system credentials, or config paths are requested.
Persistence & Privilege
Defaults are used (always: false). The skill does not request permanent presence or modification of other skills/config. Autonomous invocation is allowed by platform default but does not combine here with other concerning privileges.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install finskills-backtest-expert
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /finskills-backtest-expert 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.2
No user-facing changes in this version. - Version update only; no code or documentation changes detected. - All functionality and documentation remain the same.
v1.0.1
- Updated skill metadata to include Openclaw manifest fields and environment variable requirements. - Changed API key setup instructions to clarify the registration process. - No changes to core logic, API usage, or analytical workflow. - Improved documentation formatting and metadata for easier integration.
v1.0.0
Backtest Expert 1.0.0 — Transform strategy ideas into professional-grade quant backtests using Finskills API. - Converts natural-language trading hypotheses into formal backtest specifications. - Fetches historical price and Fama-French factor data from Finskills API. - Calculates signal-driven returns, risk-adjusted performance metrics, and trade statistics. - Delivers full benchmark comparison, drawdown analysis, and factor attribution (alpha, beta, loadings). - Supports walk-forward (in/out-of-sample) and major stress-test scenario analysis. - Outputs an easy-to-read professional backtest report with summary tables and statistics.
元数据
Slug finskills-backtest-expert
版本 1.0.2
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 3
常见问题

backtest-expert 是什么?

Design, execute, and evaluate quantitative trading strategies using historical price data and Fama-French factor attribution via the Finskills API. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 96 次。

如何安装 backtest-expert?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install finskills-backtest-expert」即可一键安装,无需额外配置。

backtest-expert 是免费的吗?

是的,backtest-expert 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

backtest-expert 支持哪些平台?

backtest-expert 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 backtest-expert?

由 finskills(@finskills)开发并维护,当前版本 v1.0.2。

💬 留言讨论