Documents

Stock Backtest Analyst

Backtest long-only stock strategies on daily CSV data and export metrics, configuration, and trade records.

What it does

Run repeatable, long-only backtests on daily OHLCV CSV data using SMA crossover, RSI reversion, or breakout rules. The bundled script validates price fields, models commission and slippage, and emits JSON metrics, configuration, and trade records for comparison and investor-oriented reporting.

When to use it

  • Comparing SMA parameter variants
  • Testing RSI mean-reversion rules
  • Evaluating breakout strategies with trading costs
  • Generating JSON backtest results for automation

The skill document

Stock Strategy Backtester

Version Notice

  • 1.0.0 and 1.0.1 are deprecated.
  • Use 1.0.2 or newer only.
  • Deprecation reason: early versions bundled non-core marketplace automation files and may trigger security scanner warnings in some environments.

Overview

Run repeatable, long-only stock strategy backtests from daily OHLCV CSV files. Use bundled scripts to generate consistent metrics and trade-level output, then summarize with investor-friendly conclusions.

Quick Start

  1. Prepare a CSV with at least Date and Close columns.
  2. Run a baseline backtest:
python scripts/backtest_strategy.py \
  --csv /path/to/prices.csv \
  --strategy sma-crossover \
  --fast-window 20 \
  --slow-window 60
  1. Export artifacts for review:
python scripts/backtest_strategy.py \
  --csv /path/to/prices.csv \
  --strategy rsi-reversion \
  --rsi-period 14 \
  --rsi-entry 30 \
  --rsi-exit 55 \
  --commission-bps 5 \
  --slippage-bps 2

Workflow

  1. Validate data
  • Ensure Date is parseable and sorted ascending.
  • Ensure Open/High/Low/Close are numeric; missing Open/High/Low falls back to Close.
  1. Pick strategy logic
  • sma-crossover: trend-following with fast/slow moving averages.
  • rsi-reversion: buy oversold and exit on momentum recovery.
  • breakout: enter on highs breakout and exit on lows breakdown.
  1. Set realistic assumptions
  • Always set --commission-bps and --slippage-bps.
  • Avoid reporting cost-free backtests as production-ready.
  1. Compare variants
  • Change one parameter block at a time.
  • Compare on the same date range and same cost model.
  1. Produce final summary
  • Report: total_return_pct, cagr_pct, win_rate_pct, max_drawdown_pct, sharpe_ratio, profit_factor, and trade count.
  • Use trade CSV to explain where alpha is coming from.

Supported Commands

  • Baseline SMA strategy:
python scripts/backtest_strategy.py \
  --csv /path/to/prices.csv \
  --strategy sma-crossover \
  --fast-window 10 \
  --slow-window 50
  • Breakout strategy:
python scripts/backtest_strategy.py \
  --csv /path/to/prices.csv \
  --strategy breakout \
  --lookback 20
  • JSON-only output (for automation pipelines):
python scripts/backtest_strategy.py \
  --csv /path/to/prices.csv \
  --strategy rsi-reversion \
  --quiet

Output Contract

  • Script prints a JSON object to stdout with:
  • strategy
  • period
  • metrics
  • config
  • trades

Analysis Guardrails

  1. Use out-of-sample logic
  • Prefer walk-forward validation over one-shot tuning.
  1. Avoid leakage
  • Compute signals from bar t, execute at bar t+1 open.
  1. Report downside with upside
  • Never present return without drawdown and trade count.
  1. Treat results as research
  • Backtests are not guarantees and should not be framed as financial advice.

References

  • Metrics details: references/backtest-metrics.md

Questions people ask

What data does the backtester require?
Provide a daily CSV with parseable, ascending Date values and at least a numeric Close column. Missing Open, High, or Low values fall back to Close.
Which strategies and assumptions are supported?
It supports SMA crossover, RSI reversion, and high/low breakout strategies with configurable parameters. Commission and slippage can be specified in basis points and should be included for realistic comparisons.
What results does it produce?
The script outputs JSON containing the strategy, test period, configuration, metrics, and trades. Reported measures include total return, CAGR, win rate, maximum drawdown, Sharpe ratio, profit factor, and trade count.

Related skills

Turn financial questions and inputs into stock research, valuation models, portfolio reviews, and formatted reports.

133 installs5 stars

Backtest markets, benchmark 462 alphas, price options, and turn trade journals into testable rules.

95 installs4 stars

Execute crypto research, wallet actions, swaps, perps, and limit orders through the Minara CLI.

162 installs109 stars

Research tokens, DeFi protocols, on-chain activity, portfolios, whitepapers, and smart-contract risk.

118 installs8 stars

Turn uploaded datasets into executed analyses, charts, reports, dashboards, and cleaned files.

113 installs4 stars