$npx -y skills add ajeeshworkspace/indian-trading-skills --skill backtest-expertExpert guidance for systematic backtesting of trading strategies on Indian markets (NSE/BSE). Use when developing strategies, testing robustness, avoiding overfitting, or validating trading ideas.
| 1 | # Backtest Expert — Indian Market Strategy Validation |
| 2 | |
| 3 | ## Core Philosophy |
| 4 | |
| 5 | > **"Find strategies that break the least, not profit the most."** |
| 6 | |
| 7 | 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. |
| 8 | |
| 9 | --- |
| 10 | |
| 11 | ## 6-Step Backtesting Workflow |
| 12 | |
| 13 | ### Step 1: State the Hypothesis (1 Sentence Edge) |
| 14 | |
| 15 | Before writing a single line of code, articulate why the strategy should work in one clear sentence. |
| 16 | |
| 17 | **Good hypotheses:** |
| 18 | - "Stocks that gap up >3% on above-average volume after consolidation tend to continue higher for 2-5 days on NSE." |
| 19 | - "Nifty 50 stocks that revert to their 20-day mean after RSI drops below 30 produce positive expectancy within 5 trading sessions." |
| 20 | - "Selling strangles on Bank Nifty on Wednesday expiry with delta <0.15 captures time decay faster than gamma risk materializes." |
| 21 | |
| 22 | **Bad hypotheses:** |
| 23 | - "This indicator combination looks good on the chart." (no edge articulated) |
| 24 | - "I saw someone on Twitter making money with this." (no reasoning) |
| 25 | |
| 26 | **Ask yourself:** |
| 27 | - What behavioral or structural edge am I exploiting? |
| 28 | - Why would this edge persist? (Structural > Behavioral > Statistical) |
| 29 | - Who is on the other side of this trade, and why are they losing? |
| 30 | |
| 31 | --- |
| 32 | |
| 33 | ### Step 2: Codify Rules (No Ambiguity) |
| 34 | |
| 35 | Every rule must be binary — a computer must be able to execute it without interpretation. |
| 36 | |
| 37 | #### Rule Categories |
| 38 | |
| 39 | | Category | What to Define | Example | |
| 40 | |----------|---------------|---------| |
| 41 | | **Universe** | Which stocks/instruments | Nifty 200 constituents, F&O stocks only, market cap >5000 Cr | |
| 42 | | **Entry** | Exact trigger conditions | Close > 20 EMA AND RSI(14) crosses above 40 AND volume > 1.5x 20-day avg | |
| 43 | | **Exit — Target** | Profit-taking rule | Close 3% above entry OR trailing stop of 1.5 ATR | |
| 44 | | **Exit — Stop** | Loss-cutting rule | Close below entry-day low OR 2% fixed stop | |
| 45 | | **Exit — Time** | Maximum holding period | Exit after 10 trading sessions if neither target nor stop hit | |
| 46 | | **Position Sizing** | How much capital per trade | 5% of equity per position, max 10 concurrent positions | |
| 47 | | **Filters** | When NOT to trade | Skip if stock is in F&O ban period, skip 2 days around results | |
| 48 | |
| 49 | #### India-Specific Rules to Consider |
| 50 | - **Circuit limits:** Stocks hitting upper/lower circuit cannot be exited. Define handling. |
| 51 | - **F&O ban period:** Stocks crossing 95% MWPL cannot add fresh F&O positions. |
| 52 | - **T+1 settlement:** Cash equity settles next trading day (changed from T+2 in 2023). |
| 53 | - **Pre-open session:** 9:00-9:08 AM orders, 9:08-9:15 AM matching. Define if you use pre-open. |
| 54 | - **Muhurat trading:** Special Diwali session — include or exclude? |
| 55 | - **Corporate actions:** Adjust for splits, bonuses, dividends, rights issues. |
| 56 | |
| 57 | --- |
| 58 | |
| 59 | ### Step 3: Run Initial Backtest |
| 60 | |
| 61 | #### Minimum Requirements |
| 62 | |
| 63 | | Parameter | Minimum | Recommended | |
| 64 | |-----------|---------|-------------| |
| 65 | | **Time period** | 5 years | 8-10+ years | |
| 66 | | **Number of trades** | 100 | 200+ | |
| 67 | | **Market regimes covered** | 2 (bull + bear) | 4+ (bull, bear, sideways, high-vol) | |
| 68 | | **Data quality** | Adjusted for corporate actions | Survivorship-bias-free universe | |
| 69 | |
| 70 | #### Indian Market Regimes to Cover |
| 71 | |
| 72 | | Regime | Period Examples | Characteristics | |
| 73 | |--------|----------------|-----------------| |
| 74 | | **Bull market** | 2014-2017, 2020-2021 | Nifty trending up, broad participation | |
| 75 | | **Bear market** | 2008, 2020 (Mar), 2022 (Jun) | Sharp drawdowns, high correlation | |
| 76 | | **Sideways/Range** | 2018-2019, 2023 H1 | Nifty in 10% range, stock-specific moves | |
| 77 | | **High volatility** | 2008, 2020, Budget days | India VIX > 25 | |
| 78 | | **Low volatility** | 2017, 2021 H2 | India VIX < 15 | |
| 79 | | **Pre/Post Budget** | Every Feb 1 | Gap moves, policy-driven sectors | |
| 80 | | **Election cycle** | 2014, 2019, 2024 | Uncertainty then rally pattern | |
| 81 | | **Monsoon impact** | Jun-Sep annually | Agri, FMCG, rural economy impact | |
| 82 | | **RBI policy shifts** | Rate hike/cut cycles | Banking, NBFC, rate-sensitive sectors | |
| 83 | | **Global crude shock** | 2018, 2022 | INR weakness, OMC impact, inflation | |
| 84 | |
| 85 | #### Key Metrics to Record |
| 86 | |
| 87 | ``` |
| 88 | Returns: CAGR, total return, monthly returns distribution |
| 89 | Risk: Max drawdown, average drawdown, drawdown duration, Calmar ratio |
| 90 | Efficiency: Sharpe ratio (use 6% risk-free for India), Sortino ratio |
| 91 | Trade quality: Win rate, avg win/loss, profit factor, expectancy per trade |
| 92 | Consistency: % profitable months, worst month, longest losing streak |
| 93 | ``` |
| 94 | |
| 95 | --- |
| 96 | |
| 97 | ### Step 4: Stress Test (Spend 80% of Your Time Here) |
| 98 | |
| 99 | This is where most backtests fail — and where the real value lies. |
| 100 | |
| 101 | #### 4a. Parameter Sensitivity |
| 102 | |
| 103 | Perturb every |