← 返回 Skills 市场
clawdiri-ai

Backtest Engine - Run Backtests

作者 RunByDaVinci · GitHub ↗ · v0.1.0 · MIT-0
cross-platform ⚠ suspicious
191
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install einstein-research-backtest-engine-dv
功能描述
Programmatic backtesting framework for trading strategies. Runs backtests with historical price data (yfinance or CSV), supports momentum/mean-reversion/fact...
使用说明 (SKILL.md)

Backtest Engine

This skill is the programmatic engine for running quantitative trading strategy backtests. It takes a machine-readable strategy definition (e.g., from the einstein-research-edge skill) and executes it against historical data, producing detailed performance metrics.

When to Use This Skill

  • User wants to run a backtest on a specific strategy.
  • User has a strategy.yaml file from the edge-generator skill.
  • User wants to generate performance metrics for a trading idea.
  • Triggers: "run a backtest," "test this strategy," "generate performance metrics."

This skill is for execution. For guidance on how to design a robust backtest, see the einstein-research-backtest methodology skill.

Workflow

Step 1: Provide Strategy Definition

The backtest engine requires a strategy.yaml file that defines the rules of the strategy.

strategy.yaml Format:

version: backtest-engine/v1
name: 52-Week High Momentum
universe: "sp500"
data:
  source: yfinance
  start_date: "2018-01-01"
  end_date: "2023-12-31"
entry_signal:
  - "price > high_52w"
  - "volume > 2 * avg_volume_50d"
exit_signal:
  - "hold_days == 5"
  - "pct_change >= 0.10"
  - "pct_change \x3C= -0.05"
parameters:
  hold_days: 5
  profit_target: 0.10
  stop_loss: -0.05

Step 2: Execute the Backtest

The backtest-engine CLI runs the simulation.

backtest-engine run --strategy-file path/to/strategy.yaml

Optional Flags:

  • --costs 0.0005: Apply a 0.05% transaction cost per trade.
  • --out-of-sample-split 2022-01-01: Split data for out-of-sample testing.
  • --walk-forward: Enable walk-forward optimization mode.

The script performs the following actions:

  1. Loads Data: Fetches historical price data via yfinance or from a local CSV.
  2. Generates Signals: Iterates through the historical data day-by-day, applying the entry_signal and exit_signal logic.
  3. Simulates Trades: Creates a trade log based on the generated signals.
  4. Calculates Equity Curve: Builds the portfolio's equity curve over time.
  5. Computes Metrics: Calculates a full suite of performance metrics.

Step 3: Analyze the Performance Report

The engine generates a detailed report in JSON and Markdown.

Key Performance Metrics (KPIs):

  • CAGR: Compound Annual Growth Rate.
  • Max Drawdown: The largest peak-to-trough drop.
  • Sharpe Ratio: Risk-adjusted return (vs. risk-free rate).
  • Sortino Ratio: Risk-adjusted return (vs. downside deviation only).
  • Calmar Ratio: Return relative to max drawdown.
  • Win Rate %: Percentage of trades that were profitable.
  • Profit Factor: Gross profits / gross losses.
  • Trades per Year: Frequency of the strategy.

Report Structure (backtest_report_YYYY-MM-DD.md):

  1. Strategy Summary: The input strategy.yaml definition.
  2. Overall Performance: A table with the key performance metrics.
  3. Equity Curve: An ASCII or image chart of the portfolio's growth.
  4. Drawdown Periods: Highlights the worst drawdown periods.
  5. Trade Log: A sample of the individual trades made.
  6. Annual Returns: A bar chart of returns by year.

Step 4: Present Findings

Synthesize the report for the user, focusing on the most important metrics that answer their original question. Always contextualize the results by referencing the methodology from the einstein-research-backtest skill (e.g., "This is an initial backtest. The next step is to test for parameter robustness.").

安全使用建议
This package appears to do what it says: run backtests against historical prices. Before using: (1) Be cautious when supplying or running custom strategy files — the engine dynamically imports and executes user-provided Python, so do not run strategies from untrusted sources. (2) Ensure you run it in a controlled environment with required Python deps installed (pandas, numpy, yfinance, etc.). (3) The engine will read CSVs from any path you provide and will fetch data from the Internet via yfinance — avoid passing sensitive file paths or secrets. (4) Note the small mismatch: SKILL.md mentions a 'backtest-engine' CLI while the repo provides scripts/backtest_engine.py; you may run the script directly (python3 scripts/backtest_engine.py). (5) Validate cost models, regime assumptions, and sample sizes before drawing conclusions from any backtest outputs.
功能分析
Type: OpenClaw Skill Name: einstein-research-backtest-engine-dv Version: 0.1.0 The skill bundle contains a significant security vulnerability in `scripts/backtest_engine.py`, where the `load_custom_strategy` function uses `importlib.util` to dynamically load and execute arbitrary Python code from a file path provided via the `--strategy-file` CLI argument. This pattern allows for Remote Code Execution (RCE) if an attacker can influence the file system or the arguments passed to the script. Additionally, there is a discrepancy between `SKILL.md`, which describes a YAML-based configuration, and the Python implementation, which lacks YAML parsing logic and expects a Python file for custom strategies.
能力评估
Purpose & Capability
The skill is described as a programmatic backtest engine and the included Python scripts implement data loading (yfinance/CSV), built-in strategies, signal generation, transaction-cost models, walk-forward capabilities, regime detection, and metric calculation. The declared requirements (no env vars, no binaries) match the contents: it needs Python and standard data science libs (pandas/numpy/yfinance) which are documented in README.
Instruction Scope
SKILL.md and README describe running a CLI and passing a strategy definition or CSV. The runtime instructions and code operate strictly within backtesting scope (price data, strategy logic, metrics). Two items to note: (1) SKILL.md references a 'backtest-engine' CLI while the bundle provides scripts/backtest_engine.py — the script provides a CLI but there is no explicit wrapper named 'backtest-engine' included. (2) The engine supports loading custom strategy code via dynamic import (load_custom_strategy) which will execute arbitrary Python from user-supplied files; this is expected for extensibility but means untrusted strategy files can run arbitrary code on the host. SKILL.md does not explicitly warn about executing custom strategy code.
Install Mechanism
There is no install spec — this is an instruction + script bundle. That minimizes install-time risk. Dependencies are standard Python packages (yfinance, pandas, numpy, scipy) declared in README; no external downloads or obscure install URLs are used.
Credentials
The skill requests no environment variables or credentials, and its runtime behavior (network access to Yahoo via yfinance and reading a user-specified CSV path) is proportionate to its purpose. There are no unexpected credential requests. Note: it does use internet access for yfinance and may attempt to fetch SPY separately for regime detection if not present.
Persistence & Privilege
The skill does not request permanent presence (always:false) and does not attempt to modify other skills or system-wide settings. It runs as a standalone script; no elevated privileges or persistent installation are requested.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install einstein-research-backtest-engine-dv
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /einstein-research-backtest-engine-dv 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.1.0
Initial release
元数据
Slug einstein-research-backtest-engine-dv
版本 0.1.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

Backtest Engine - Run Backtests 是什么?

Programmatic backtesting framework for trading strategies. Runs backtests with historical price data (yfinance or CSV), supports momentum/mean-reversion/fact... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 191 次。

如何安装 Backtest Engine - Run Backtests?

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

Backtest Engine - Run Backtests 是免费的吗?

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

Backtest Engine - Run Backtests 支持哪些平台?

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

谁开发了 Backtest Engine - Run Backtests?

由 RunByDaVinci(@clawdiri-ai)开发并维护,当前版本 v0.1.0。

💬 留言讨论