Skip to content

/backtest-expert

Expert guidance for systematic backtesting of trading strategies on Indian markets (NSE/BSE). Use when developing strategies, testing robustness, avoiding overfitting, or validating trading ideas.

shell
$ npx -y skills add ajeeshworkspace/indian-trading-skills --skill backtest-expert --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.
  • You can call itInvoke it directly when you want it.
  • Slash command/backtest-expert
How auto-invocation works

Context preview

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

Expert guidance for systematic backtesting of trading strategies on Indian markets (NSE/BSE). Use when developing strategies, testing robustness, avoiding overfitting, or validating trading ideas.

SKILL.md

backtest-expert.SKILL.md
name: backtest-expert
description: >
  Expert guidance for systematic backtesting of trading strategies on Indian markets (NSE/BSE).
  Use when developing strategies, testing robustness, avoiding overfitting, or validating trading ideas.

Backtest Expert — Indian Market Strategy Validation

Core Philosophy

> **"Find strategies that break the least, not profit the most."**

A strategy that survives stress testing across multiple market regimes, transaction cost assumptions, and parameter perturbations is far more valuable than one that shows spectacular returns on a single optimized parameter set. Overfitting is the silent killer of trading accounts.

---

6-Step Backtesting Workflow

Step 1: State the Hypothesis (1 Sentence Edge)

Before writing a single line of code, articulate why the strategy should work in one clear sentence.

**Good hypotheses:**

  • "Stocks that gap up >3% on above-average volume after consolidation tend to continue higher for 2-5 days on NSE."
  • "Nifty 50 stocks that revert to their 20-day mean after RSI drops below 30 produce positive expectancy within 5 trading sessions."
  • "Selling strangles on Bank Nifty on Wednesday expiry with delta <0.15 captures time decay faster than gamma risk materializes."

**Bad hypotheses:**

  • "This indicator combination looks good on the chart." (no edge articulated)
  • "I saw someone on Twitter making money with this." (no reasoning)

**Ask yourself:**

  • What behavioral or structural edge am I exploiting?
  • Why would this edge persist? (Structural > Behavioral > Statistical)
  • Who is on the other side of this trade, and why are they losing?

---

Step 2: Codify Rules (No Ambiguity)

Every rule must be binary — a computer must be able to execute it without interpretation.

Rule Categories

| Category | What to Define | Example | |----------|---------------|---------| | **Universe** | Which stocks/instruments | Nifty 200 constituents, F&O stocks only, market cap >5000 Cr | | **Entry** | Exact trigger conditions | Close > 20 EMA AND RSI(14) crosses above 40 AND volume > 1.5x 20-day avg | | **Exit — Target** | Profit-taking rule | Close 3% above entry OR trailing stop of 1.5 ATR | | **Exit — Stop** | Loss-cutting rule | Close below entry-day low OR 2% fixed stop | | **Exit — Time** | Maximum holding period | Exit after 10 trading sessions if neither target nor stop hit | | **Position Sizing** | How much capital per trade | 5% of equity per position, max 10 concurrent positions | | **Filters** | When NOT to trade | Skip if stock is in F&O ban period, skip 2 days around results |

India-Specific Rules to Consider

  • **Circuit limits:** Stocks hitting upper/lower circuit cannot be exited. Define handling.
  • **F&O ban period:** Stocks crossing 95% MWPL cannot add fresh F&O positions.
  • **T+1 settlement:** Cash equity settles next trading day (changed from T+2 in 2023).
  • **Pre-open session:** 9:00-9:08 AM orders, 9:08-9:15 AM matching. Define if you use pre-open.
  • **Muhurat trading:** Special Diwali session — include or exclude?
  • **Corporate actions:** Adjust for splits, bonuses, dividends, rights issues.

---

Step 3: Run Initial Backtest

Minimum Requirements

| Parameter | Minimum | Recommended | |-----------|---------|-------------| | **Time period** | 5 years | 8-10+ years | | **Number of trades** | 100 | 200+ | | **Market regimes covered** | 2 (bull + bear) | 4+ (bull, bear, sideways, high-vol) | | **Data quality** | Adjusted for corporate actions | Survivorship-bias-free universe |

Indian Market Regimes to Cover

| Regime | Period Examples | Characteristics | |--------|----------------|-----------------| | **Bull market** | 2014-2017, 2020-2021 | Nifty trending up, broad participation | | **Bear market** | 2008, 2020 (Mar), 2022 (Jun) | Sharp drawdowns, high correlation | | **Sideways/Range** | 2018-2019, 2023 H1 | Nifty in 10% range, stock-specific moves | | **High volatility** | 2008, 2020, Budget days | India VIX > 25 | | **Low volatility** | 2017, 2021 H2 | India VIX < 15 | | **Pre/Post Budget** | Every Feb 1 | Gap moves, policy-driven sectors | | **Election cycle** | 2014, 2019, 2024 | Uncertainty then rally pattern | | **Monsoon impact** | Jun-Sep annually | Agri, FMCG, rural economy impact | | **RBI policy shifts** | Rate hike/cut cycles | Banking, NBFC, rate-sensitive sectors | | **Global crude shock** | 2018, 2022 | INR weakness, OMC impact, inflation |

Key Metrics to Record

Returns: CAGR, total return, monthly returns distribution
Risk: Max drawdown, average drawdown, drawdown duration, Calmar ratio
Efficiency: Sharpe ratio (use 6% risk-free for India), Sortino ratio
Trade quality: Win rate, avg win/loss, profit factor, expectancy per trade
Consistency: % profitable months, worst month, longest losing streak

---

Step 4: Stress Test (Spend 80% of Your Time Here)

This is where most backtests fail — and where the real value lies.

4a. Parameter Sensitivity

Perturb every parameter by +/-20% and check if performance degrades gracefully or collapses.

| Parameter | Base | -20% | -10% | +10% | +20% | Verdict | |-----------|------|------|------|------|------|---------| | EMA period | 20 | 16 | 18 | 22 | 24 | Stable if all profitable | | RSI threshold | 40 | 32 | 36 | 44 | 48 | Fragile if only 40 works | | Stop loss % | 2% | 1.6% | 1.8% | 2.2% | 2.4% | Check drawdown impact |

**Rule of thumb:** If the strategy only works with exact parameter values, it is overfit. You want a "plateau" of profitability, not a "peak."

4b. Execution Friction (India-Specific Costs)

Apply realistic transaction costs:

| Cost Component | Delivery (CNC) | Intraday (MIS) | F&O | |----------------|----------------|-----------------|-----| | Brokerage | ~₹20/order or 0.03% | ~₹20/order or 0.03% | ~₹20/order | | STT | 0.1% (buy+sell) | 0.025% (sell only) | 0.0125% (sell, options) | | Exchange charges | 0.00345% (NSE) | 0.00345% (NSE) | 0.05% (options) | | GST | 18% on brokerag

Read more
Read it on GitHub ↗

Showing the first part of this file.

Ships withindian-trading-skills

Turn Claude into your Indian market research analyst. 10 specialized skills covering NSE/BSE equities, F&O derivatives, institutional flows, market breadth, live news tracking, and weekly trade planning — all built for Indian markets.

Get the whole plugin, auto-invoked
Stats
52
Stars
0
Views
41
Forks
Active
Maintenance
Python
Language
MIT
License
2d ago
Last commit
4mo ago
Created

Repo: ajeeshworkspace/indian-trading-skills

Other skills on indian-trading-skills.