跳至正文
OpenAgentSkill
浏览已开放 · 目录记录日期 2026-11-21 · 自动更新和账户服务暂时关闭。
金融

alpaca-trading-backtest

Execute deterministic, reproducible historical backtests from a start date, end date, and strategy concept using the Alpaca CLI plus agent-written workspace code. Use when the user wants to backtest a strategy, simulate historical trades, or return trades, diagnostics, and reproducibility artifacts.

alpacahq · 已有 AI 审核记录

安装与使用

运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。

npx skills add alpacahq/alpaca-skills --skill alpaca-trading-backtest

技能说明


name: alpaca-trading-backtest description: > Execute deterministic, reproducible historical backtests from a start date, end date, and strategy concept using the Alpaca CLI plus agent-written workspace code. Use when the user wants to backtest a strategy, simulate historical trades, or return trades, diagnostics, and reproducibility artifacts.

Trading API Backtesting

Use this skill when you want your AI agent to run a specific historical backtest with the Alpaca CLI and local workspace code. This version is optimized for run-specific execution: your agent writes the minimum readable code needed for the confirmed strategy, stores the exact artifacts, and reports the results back to you.

This skill is written for you, the person invoking it through your AI agent. You means the trader, developer, researcher, or operator asking your agent to run the backtest. Your agent should address you directly, restate assumptions clearly, and make every interpretation choice visible.

strategy idea -> formalized rules -> confirmed assumptions -> CLI data fetch -> local script -> artifacts -> report

It is not a promise that a strategy will work in live markets. It is a reproducible research workflow.

Required disclosures

Every report, notes.md, report.md, notebook, dashboard, or exported result should include:

Important disclosure
This backtest is a hypothetical historical simulation and does not represent actual trading performance. Backtested results do not guarantee future results. Results depend on market-data quality, data feed selection, corporate-action handling, fees, slippage, liquidity, taxes, execution assumptions, and implementation details. This material is for research and educational purposes only and is not investment advice, a recommendation, an offer, or a solicitation to buy or sell securities, options, cryptocurrencies, or any other financial product. All investments involve risk and may lose value. Review Alpaca's disclosures and agreements at alpaca.markets/disclosures.

When paper trading appears in the workflow, add:

Paper trading is a simulated environment. It does not involve real money or actual securities transactions. Paper results may differ from live trading because of fill assumptions, market impact, liquidity, latency, data differences, order handling, fees, and other market conditions.

When the backtest models Alpaca securities trading-activity fees, notes.md, summary.json, and report.md should link to the Alpaca Brokerage Fee Schedule PDF:

https://files.alpaca.markets/disclosures/library/BrokFeeSched.pdf

Record the PDF revision date, extraction timestamp, modeled fee categories, and any fee items intentionally excluded.

CLI prerequisites

Alpaca CLI

Your agent should use the Alpaca CLI for market-data access.

Check whether it is installed:

alpaca version

Install with Go when needed:

go install github.com/alpacahq/cli/cmd/alpaca@latest

On macOS or Linux with Homebrew:

brew install alpacahq/tap/cli

Make sure the binary directory is on PATH, commonly ~/go/bin for Go installs.

Local execution permissions

Alpaca CLI commands should run in your local workspace where your Alpaca profile, environment variables, network access, and saved artifacts are available. Some agent runtimes express this as:

required_permissions: ["all"]

Use the equivalent permission model in your agent environment so the CLI can access local auth/config and write run artifacts.

Connectivity and authentication check

Before any backtest run, verify the CLI and credentials:

alpaca doctor

If authentication fails, your agent should stop the run and show you the available login/help command:

alpaca profile login --help

For interactive paper setup:

alpaca profile login

For API-key setup:

alpaca profile login --api-key

For automation, environment variables are preferred because secrets do not need to be written into generated code:

export ALPACA_API_KEY=PK...
export ALPACA_SECRET_KEY=...
export ALPACA_QUIET=1

Your agent should never print your secret key, commit it to files, include it in reports, or pass it in a way that exposes it to shell history.

Machine-readable output

Use --quiet for commands whose output will be parsed by code:

alpaca account get --quiet
alpaca data bars --symbol SPY --start 2024-01-01 --end 2024-12-31 --timeframe 1Day --quiet

Use installed CLI help and schemas as the source of truth for flags and response fields:

alpaca --help-all
alpaca data bars --help
alpaca data bars --schema
alpaca data quotes --schema

Because the CLI is generated from API specifications and may evolve, your agent should prefer current --help, --schema, and alpaca doctor output over stale examples.

Required workflow

Your agent should follow this workflow:

  1. Gather required inputs: start date, end date, strategy concept or strategy file.
  2. Gather or infer the rest: asset class, symbols or universe, timeframe, initial cash, position sizing, feed, adjustment mode, execution assumptions, benchmark.
  3. Work through run considerations: order simulation, indicators, dividends, splits, fees, slippage, spread, market hours, calendar handling, and validation.
  4. Translate your freeform idea into precise mathematical rules.
  5. Present the formalized interpretation to you before writing code unless your request was already mathematically precise.
  6. Check the workspace for reusable data, prior runs, and existing utilities.
  7. Create a self-contained run folder.
  8. Write notes.md, strategy_spec.json, config.json, and a readable run-specific script.
  9. Fetch historical data through the Alpaca CLI, save raw CLI outputs, filter to the chosen market hours, and compute data finge
阅读完整来源 ↗