agentleFS
ntaffziintaffzii/Skill-Agents/skills/trading/backtest-expert/SKILL.md

backtest-expert

Skill4 starsChanged 2 months agoMITView on GitHub

Use this skill to simulate how a trading rule would have performed on historical price data — win rate, average return, max drawdown, profit factor — from a CSV or list of prices the user supplies, no market-data API required. Trigger on "backtest this strategy", "ทดสอบกลยุทธ์ย้อนหลัง", "how would this rule have performed historically", "moving average crossover backtest", "max drawdown of this strategy". If the user wants to size a position or apply a risk gate on a trade they're about to take, use position-sizer/drawdown-circuit-breaker instead — this skill evaluates a rule against the past, not a single upcoming trade.

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Not accounting for what this backtest excludes: no commissions, slippage, taxes, or bid-ask spread by default — real returns will be lower …

    line 50
  2. Very specific:

    Run python3 backtest.py for the self-test (includes a fully hand-verified trade sequence and a hand-verified MA-crossover signal sequence, …

    line 59
  3. Distinctive:

    No commissions, slippage, spread, taxes, shorting, position sizing, or multi-position support — this is a minimal long-only single-position …

    line 63

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Backtest Expert

Overview

position-sizer and drawdown-circuit-breaker manage risk once you've already decided to trade a rule — neither tells you whether the rule itself actually works. This skill fills that gap: given historical price data and a set of buy/sell signals (either supplied directly or generated from a simple moving-average crossover), it simulates the trades a long-only, one-position-at-a-time strategy would have taken and reports the standard backtest metrics.

Not financial advice. A backtest describes how a rule performed on one specific historical sample. It does not predict future performance, and a rule tuned by trial-and-error against the same data it's being "backtested" on will look better than it is (overfitting/curve-fitting) — see Known limitations.

When to use

  • ทดสอบกฎเทรดกับข้อมูลราคาย้อนหลัง ก่อนใช้เงินจริง
  • Evaluating a simple moving-average crossover (or any buy/sell signal series you already have) against historical prices
  • Comparing win rate, average return, max drawdown, and profit factor across a few rule variants on the same data

When NOT to use

  • Sizing or risk-gating a specific upcoming trade — that's position-sizer/drawdown-circuit-breaker, not this skill
  • The user wants live/real-time strategy execution — this is historical simulation only, it does not place or track live trades
  • Short selling, multi-position, or portfolio-level backtesting — this engine is long-only and one-position-at-a-time; a strategy needing more than that needs a different tool

Core knowledge

Trade simulation: long-only, one position at a time. Enters on a "buy" signal only while flat; exits on a "sell" signal only while in a position. A "buy" while already in a position, or a "sell" while flat, is a no-op — it does not pyramid into a second position or close a position that doesn't exist.

Metrics reported:

MetricMeaning
Win rate% of completed trades with a positive return
Average returnMean return % per completed trade
Total returnCompounded return across all trades, starting from a normalized equity of 1.0
Max drawdownLargest peak-to-trough decline in the equity curve across the whole run — same peak/current formula as drawdown-circuit-breaker
Profit factorGross profit ÷ gross loss (sum of winning trades' returns over the absolute sum of losing trades' returns) — undefined (None) when there are no losing trades to divide by

An open position at the end of the data (a "buy" with no later "sell") is not counted as a completed trade and is flagged separately (open_position_at_end) — don't silently drop it from the report.

Moving-average crossover signal generator: a simple, common way to produce buy/sell signals mechanically instead of supplying them by hand. fast_period/slow_period are trailing-window sizes (in bars); a "buy" fires the first bar the fast MA moves above the slow MA, "sell" the first bar it moves below. No lookahead — each bar's MA only uses that bar and earlier ones. Bars without enough history for both MAs get "hold".

Common mistakes

  1. Tuning the fast/slow period (or any rule parameter) by trying many values against the same historical sample and keeping whichever looks best — that's curve-fitting, not validation; the resulting metrics describe how well the rule was fit to this data, not how it will perform on new data.
  2. Treating a high win rate as good on its own — a rule with a 70% win rate and rare large losses can still have a negative profit factor; report win rate, average return, and profit factor together, not in isolation.
  3. Ignoring open_position_at_end — a trade still open when the data ends isn't a loss or a win, it's incomplete; don't fold it into win rate as either.
  4. Applying this long-only, single-position engine to a strategy that actually shorts, pyramids, or holds multiple concurrent positions — the metrics would silently misrepresent a strategy this engine can't actually simulate.
  5. Not accounting for what this backtest excludes: no commissions, slippage, taxes, or bid-ask spread by default — real returns will be lower than a raw backtest suggests, especially for a rule with many trades.

Code

backtest.py — Decimal arithmetic, no dependencies:

  • run_backtest(bars) → BacktestResult(trades, total_trades, win_rate, avg_return_pct, total_return_pct, max_drawdown_pct, profit_factor, open_position_at_end), where bars is a chronological list of {"date", "price", "signal"}
  • generate_ma_crossover_signals(prices, fast_period, slow_period) → the same list with a "signal" key added, ready to feed into run_backtest

Run python3 backtest.py for the self-test (includes a fully hand-verified trade sequence and a hand-verified MA-crossover signal sequence, not just round-trip assertions).

Known limitations

  • No commissions, slippage, spread, taxes, shorting, position sizing, or multi-position support — this is a minimal long-only single-position simulator, not a full trading-system backtester.
  • Says nothing about statistical significance — a handful of trades on one historical window is a small sample; treat a backtest over a short period or few trades as weak evidence, not proof a rule works.
  • Overfitting is a real, easy-to-fall-into trap: if the rule's parameters were chosen by testing many variants against this same data, the reported metrics are optimistic. A rule validated on data it was never tuned against (out-of-sample / walk-forward testing) is much stronger evidence — this skill does not enforce that discipline for you.
  • Past performance shown by any backtest, however carefully done, does not guarantee future results.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.