Logo Backtest Lab

Backtest Lab

Cộng đồng
Shubhamkumartrichy
backtest-lab

Backtests rule-based swing ideas on NSE/BSE daily bars with Indian frictions built in: decide on the close and fill at the next open, gap-through stops, slippage, exact per-trade charges by segment and broker (STT, stamp duty, GST, DP), whole shares or lots, circuit-band no-fills, futures-only shorts and an optional STCG/LTCG estimate. Six built-in strategies; CAGR vs buy-and-hold, drawdown, Sharpe/Sortino, profit factor, expectancy in ₹ and R; parameter sweeps with a plateau-or-spike read, walk-forward and Monte Carlo. backtest.py, stdlib only, offline. Use when the user asks: "backtest this strategy", "would a 20/50 crossover have worked on X", "is this edge real or curve-fit", "optimise my parameters", "walk-forward test", "Monte Carlo my trades", "what drawdown should I expect", "do charges kill this idea", "does a NIFTY 200-DMA filter help", or before putting real money behind any mechanical rule.

Tổng quan

Nhà phát hànhShubhamkumartrichy
Kho mãclaude-trading-skills-india
Tên kỹ năngbacktest-lab
Sao
57
Bản fork
11
Tệp đi kèm
1
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI dùng hướng dẫn viết bằng Markdown thay vì mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • 1 tệp đi kèm

    Các tập lệnh, mẫu và tài liệu tham khảo mà mô hình có thể đọc khi làm việc. Các tệp chỉ cho phép đọc và không bao giờ được thực thi.

  • Mã nguồn mở

    Được Shubhamkumartrichy công bố trên GitHub. Hãy đọc các tệp nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Backtest Lab trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL của thư mục kỹ năng được hiển thị bên dưới rồi xác nhận.
    https://github.com/Shubhamkumartrichy/claude-trading-skills-india/tree/main/skills/backtest-lab
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Shubhamkumartrichy/claude-trading-skills-india.git /tmp/claude-trading-skills-india
mkdir -p .claude/skills
cp -r /tmp/claude-trading-skills-india/skills/backtest-lab .claude/skills/backtest-lab
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Backtest Lab trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự nạp Backtest Lab ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên bạn có thể dùng Backtest Lab với cả những mô hình khác ngoài mô hình ban đầu. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên khi kỹ năng chưa được dùng, bạn không tốn token cho phần hướng dẫn.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Backtest Lab

A backtest cannot prove an idea works. It can show quickly that an idea does not. Judge a rule set by how little it degrades when Indian charges, overnight gaps, unseen years and bad luck are piled on, and treat a spectacular first run as a reason for suspicion.

Commands

bash
python3 scripts/backtest.py strategies                                  # rules and defaults
python3 scripts/backtest.py run --csv tcs.csv --strategy sma-cross --params fast=20 slow=50
python3 scripts/backtest.py run --symbol POLYCAB --strategy 52w-high --risk-pct 1 --tax --trades-csv t.csv
python3 scripts/backtest.py run --csv hdfcbank.csv --strategy donchian-breakout --regime-csv nifty.csv
python3 scripts/backtest.py run --csv nifty.csv --strategy sma-cross --segment futures --lot-size 65 \
    --allow-short --leverage 3 --size-pct 300
python3 scripts/backtest.py sweep --csv tcs.csv --strategy sma-cross --grid fast=10,20,30 slow=50,100,200
python3 scripts/backtest.py walkforward --csv tcs.csv --strategy donchian-breakout \
    --grid entry_n=20,40,55 exit_n=10,20 --is-bars 756 --oos-bars 252
python3 scripts/backtest.py montecarlo --csv tcs.csv --strategy ema-pullback --sims 2000 --seed 7
python3 scripts/backtest.py montecarlo --from-trades t.csv --ruin-dd 25

Inputs follow technical-analysis: --csv, --candles (broker-MCP JSON, null candles skipped) or --symbol (yfinance, --period 10y). --start sets the first trading day while earlier bars still warm up the indicators. --grid also takes ranges (fast=10:50:10). Every command takes --json. Bad input exits 2 with one error: line.

Strategies (--strategy, override with --params key=value)

NameRule (long side; shorts mirror it)Defaults
sma-crossfast SMA crosses above slow; out when back belowfast 20, slow 50, stop 3×ATR
ema-pullbackclose above a rising trend EMA, low tags the EMA, close back above itema 20, trend 100, 2×ATR, target 2R, 20 bars
rsi-reversionRSI(period) below buy_below while above the trend SMA; out above sell_above2, 10, 70, trend 200, 10 bars
donchian-breakoutclose above the prior entry_n high; out below the prior exit_n low20 / 10, 2×ATR
bollinger-reversionclose below the lower band; out at the middle band20, k 2, trend 0 (off), 20 bars
52w-highclose above the prior lookback-bar high; out below the exit SMA252, exit_ma 50, 2.5×ATR

Every strategy also takes stop_atr (k × ATR14 from the fill), stop_pct (overrides it), target_r and max_hold (bars), where 0 turns each one off. There is no custom-code hook: new rules are added to the script as reviewed code.

How orders and costs are simulated

  • No look-ahead. Signals use bars up to and including the signal bar's close. The order fills at the next bar's open, never at the close that produced it.
  • Stops and targets rest in the market. A gap through the level fills at the open (a stop at ₹101 after a ₹96 open books ₹96). If one bar touches both, the stop is assumed to have filled first.
  • Slippage --slippage-bps (default 5) on every fill. Use 15–30 for small caps.
  • Charges come from trading-costs (charges.py) for each round trip, by --segment delivery|intraday|futures and --broker. A delivery buy sold the same day is charged as intraday.
  • Sizing: --size-pct (default 100% of equity), --risk-pct (risk to the initial stop, the position-sizing method) or --fixed-inr. The size is set on the signal close, capped by the cash available at the fill, and rounded down to whole shares or whole --lot-size lots (futures, SME).
  • Intraday turns each signal into a next-session open-to-close MIS trade.
  • Shorts need --segment futures --allow-short. An Indian cash-market short has to be bought back the same session (SLB aside), so a multi-day short only exists as futures. Futures notional ≤ equity × --leverage. Rollover, basis and margin calls are not modelled.
  • Circuits: with --circuit-band 2|5|10|20, an open at the band limit gets no fill. The entry is skipped; an exit or stop waits for the next unlocked open. Each case is listed under order events.
  • Regime filter: --regime-csv nifty.csv (or --regime-symbol NIFTY) allows longs only while the benchmark closes above its --regime-ma (200) SMA on the signal day, and shorts only below it.
  • Cash earns nothing. Sharpe and Sortino subtract --rf (default 6.5% a year, about a liquid fund or T-bill; change it).
  • --tax applies indian-tax-for-traders rates for a rough post-tax view: STCG 20% (held ≤12 months), LTCG 12.5% above ₹1.25 lakh per FY, intraday and futures at --slab-pct, plus 4% cess. It is approximate: losses are not carried forward and STT is treated as deductible, which it is not.

Reading the output

  • Versus buy-and-hold (delivery, one round trip). A rule earns its keep with a better Sharpe or Calmar, or a much smaller drawdown, not just a higher return in a bull market.
  • Max drawdown and longest underwater stretch: would you have kept following the rules through it?
  • Profit factor (after charges) below 1.2 is thin. Above 2 on fewer than 30 trades is suspicious.
  • Expectancy: about +0.2R or more after costs is worth a closer look. Breakeven trades (net ₹0) count as neither wins nor losses and do not end a losing streak.
  • Charges as % of gross profit above 25% means costs, not the market, own the result.
  • Yearly table: one great year carrying the whole test is regime luck.
  • Sweep: plateau (neighbours keep ≥75% of the best score) is what you want. Slope means pick the middle of the good zone. Spike means curve-fit. The luck hurdle is the Sharpe the best of N zero-edge variants would show by chance; the best cell should clear it comfortably.
  • Walk-forward: efficiency = out-of-sample CAGR ÷ mean in-sample CAGR. ≥0.5 holds up; below 0 fails. Frequent parameter changes mean the "optimum" is noise.
  • Monte Carlo: size for the 95th-percentile drawdown, not the backtest's one path. bootstrap varies the outcome; shuffle only reorders the trades (final equity is fixed, the path is not).

Checklist: try to break the idea before it breaks your account

  1. Look-ahead: can every input be known before the order? Today's high/low or close cannot trigger an entry today. Dividend-adjusted closes are not prices anyone traded at.
  2. Survivorship: today's NIFTY 50 or a current screener list are winners by construction. Ten years on them flatters every long strategy. Add names that were dropped, delisted or merged, or test the index itself.
  3. Overfitting: each extra grid cell is another lottery ticket. Keep grids coarse, insist on a plateau, walk forward, and leave the last 1–2 years untouched until the very end.
  4. Costs: a delivery round trip at Zerodha costs about 0.24% of the position (STT 0.1% a side, stamp duty, DP charge). 100 full-size round trips a year is about 24% of capital before any edge. High-turnover ideas die here. Rerun at 2–3× slippage and on a costlier broker.
  5. Regime: does it only work in 2020–21-style rallies? Check the yearly rows, add --regime-csv, and include a bad phase (2008, 2015–16, 2018 small caps, March 2020, late 2024–early 2025).
  6. Data: Yahoo history usually adjusts splits and bonuses, but not always. Moves of 25% or more overnight are flagged; check them. Dividends are left out for both the strategy and buy-and-hold.
  7. Small samples: under 30 trades is an anecdote. Run the same rules on several stocks and look at the spread of results, not the best one.
  8. Execution: thin names lock at circuits and slip more (--circuit-band, higher slippage). Stop orders are DAY-only on exchanges, so a real system needs GTTs (see breakout-planner).

Workflow with other skills

  1. market-regime (../market-regime/scripts/regime.py): test whether a NIFTY trend filter (--regime-csv) cuts drawdown more than it cuts return before using it live.
  2. Run run → sweep → walkforward → montecarlo, and stop at the first red flag.
  3. position-sizing (../position-sizing/scripts/risk.py): choose a --risk-pct that keeps the Monte Carlo 95th-percentile drawdown survivable.
  4. trading-discipline: --trades-csv writes journal columns, so python3 ../trading-discipline/scripts/discipline.py review t.csv breaks the backtest down by weekday and setup. Compare it with your live journal later; a large gap is a warning.
  5. breakout-planner: 52w-high and donchian-breakout are rough stand-ins for its Stage-2 entries. They tell you whether breakout buying pays on a stock at all, not whether a given VCP will work.

Limits: one symbol and one position at a time (no portfolio rotation), daily or weekly bars, no options, no tick rounding.

Output

NAME: strategy (params) | segment on NSE via broker | capital | sizing | slippage
start → end | bars (years) | signal on close, fill next open | charges as of <date>
Strategy vs Buy & hold: total return, CAGR, max DD, volatility, Sharpe (rf), Sortino, Calmar
Trades N: W / L / BE | win rate | avg win / loss | PF | expectancy ₹ (R) | payoff | losing streak
Exposure | avg hold | max DD dates | longest underwater | charges (% of gross profit) | slippage
Year table | last trades | order events | red flags | data notes

Educational analysis, not investment advice. A backtest describes the past, not your next trade.

Tệp đi kèm

Khi kỹ năng đã được tải, mô hình có thể đọc các tệp này nếu cần. Các tệp này chỉ dùng để đọc và không bao giờ được thực thi.

Câu hỏi thường gặp

Kỹ năng AI Backtest Lab làm được gì?

Backtests rule-based swing ideas on NSE/BSE daily bars with Indian frictions built in: decide on the close and fill at the next open, gap-through stops, slippage, exact per-trade charges by segment and broker (STT, stamp duty, GST, DP), whole shares or lots, circuit-band no-fills, futures-only shorts and an optional STCG/LTCG estimate. Six built-in strategies; CAGR vs buy-and-hold, drawdown, Sharpe/Sortino, profit factor, expectancy in ₹ and R; parameter sweeps with a plateau-or-spike read, walk-forward and Monte Carlo. backtest.py, stdlib only, offline. Use when the user asks: "backtest th...

Vì sao nên dùng Backtest Lab trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Backtest Lab là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Backtest Lab trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/Shubhamkumartrichy/claude-trading-skills-india/tree/main/skills/backtest-lab. TypingMind đọc tệp SKILL.md, đóng gói các tệp đi kèm rồi cài đặt cả gói dưới dạng một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Backtest Lab?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Có thể dùng Backtest Lab với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Backtest Lab với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Backtest Lab có miễn phí không?

Có. Kỹ năng này được Shubhamkumartrichy phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp các công cụ mới mà mô hình có thể gọi. Khi mô hình gọi một công cụ, mã của công cụ đó chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và những tiêu chí mà kết quả cần đáp ứng. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇