Skip to content
Finance
Skill

/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

BOOST
From plugin
alpaca-skills
15714 skills
Install
$ npx -y skills add alpacahq/alpaca-skills --skill backtest --agent claude-code

How it fires

How this skill gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
  • You can call itInvoke it directly when you want it.
  • Slash command/backtest

Context preview

The summary Claude sees to decide when to auto-load this skill.

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

SKILL.md

backtest.SKILL.md
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](https://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](#run-considerations-checklist): 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

Read more
Ships withalpaca-skills

Open agent skills for Alpaca's Trading API and Broker API. Each skill is a SKILL.md file with step-by-step instructions your AI coding assistant follows when you ask it to complete a task, such as running a historical backtest, onboarding Broker API accounts,

Get the whole plugin
Stats
157
Stars
19
Forks
Active
Maintenance
Python
Language
Apache-2.0
License
16h ago
Last commit
4mo ago
Created
4h ago
Added

Repo: alpacahq/alpaca-skills

Other skills on alpaca-skills.