/india-trading-skills:pair-tradingfrom india-trading-skills
Tests cointegration and computes hedge ratios, half-life, and z-scores for NSE stock pairs. Plans Indian futures execution with lot sizes, margin, and F&O rules. Use for market-neutral long/short pair trades.
Ships in india-trading-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Two stocks that share the same economics (two private banks, two oil marketing companies) can drift apart for weeks, then close the gap. A pair trade is long the cheap one and short the rich one, sized so the market move cancels out. This works only if the gap is statistically mean-reverting (cointegrated). A high correlation is not enough.
python3 scripts/pairs.py test HDFCBANK ICICIBANK --csv-dir stocks/ # one pair, full statistics
python3 scripts/pairs.py screen --members members.csv --csv-dir stocks/ # all same-sector pairs
python3 scripts/pairs.py signal BPCL HPCL --csv-dir stocks/ --exit 0.5 # rules + in-sample trades
python3 scripts/pairs.py plan BPCL HPCL --csv-dir stocks/ --lots-csv fo_mktlots.csv \
--ban-list fo_secban.csv --margin-a 120000 --margin-b 110000 # India execution
Without --csv-dir, prices come from Yahoo (pip install yfinance). Create offline CSVs with
../technical-analysis/scripts/ta.py fetch --symbol TCS --out stocks/TCS.csv. Only a date and a
close column are needed; a volume column turns on the liquidity filter. Use split and bonus-adjusted
closes. --members is a symbol,sector CSV. Common options: --lookback 500 sessions (0 = all),
--end YYYY-MM-DD (re-test an earlier window), --window 60 (z-score), --entry 2 --exit 0 --stop 3.5, --adf-lag N or --max-lag N, --splits 3, --max-half-life 40, --json.
Screen adds --min-bars 250 --min-turnover 10 (₹ crore a day) --min-corr 0.5 --top 20.
| Statistic | How |
|---|---|
| Correlation | Pearson correlation of daily log returns on common dates |
| Hedge ratio β | OLS of ln A on ln B. Hold ₹β of B against each ₹1 of A. Also reverse OLS and total least squares |
| Cointegration | Engle-Granger: ADF (no constant) on the OLS residuals, lag by AIC (Schwert maximum) or fixed |
| Critical values | MacKinnon (2010) Table 2, N = 2 with constant: ≈ −3.90 / −3.34 / −3.04 (1/5/10%) plus a T-adjustment. These are stricter than plain Dickey-Fuller values (≈ −2.86 at 5%) because β was fitted |
| p-value | MacKinnon (1994) asymptotic surface. Use it for ranking; the critical values decide |
| Half-life | AR(1) on the spread: s_t = c + φ·s_{t−1}; half-life = ln 0.5 / ln φ sessions |
| z-score | (spread − 60-session mean) / 60-session sd |
| Stability | β in 3 consecutive sub-periods; drift ≤ 25% of β = stable, > 50% = unstable |
Both regression directions are tested. A pair counts only if both reject the unit root.
--max-half-life;
3–20 fits a monthly futures cycle best) and β stable. Then look at the z-score.signal enters at |z| ≥ 2 once |z| has reset inside the band. It exits when z returns to 0 (or
±0.5 with --exit 0.5), stops at |z| ≥ 3.5, and time-stops after 2× the half-life
(--max-hold, --time-stop-mult). Each trade is returned as % of gross notional. The trade list
is in-sample: β, the test and the half-life all come from the same data, so the hit rate is an
optimistic upper bound and excludes costs. Check out of sample: run test with --end six
months back, then see whether the pair still holds on the newer data.
plan)--legs cash-long to buy the long leg for delivery and short
the other leg in futures. SLB (stock lending) exists but is thin.plan rounds the B leg, reports the residual mismatch in % and ₹, and lists the lot combinations
with the tightest hedge. With --legs cash-long, the delivery leg is sized in shares.--lot-a/--lot-b, or --lots-csv with NSE's fo_mktlots.csv (one column per
contract month). NSE revises lot sizes periodically, and corporate actions adjust them. If the
file shows a different size in a later month, the plan flags it: re-size the hedge when you roll.--margin-a/--margin-b (₹ per lot from your broker), otherwise --margin-pct 25 of
contract value per leg. Margin is summed leg by leg. A long/short across two different stocks is
not a recognised spread, so do not count on a hedge margin benefit. Futures are marked to market
daily, so keep a buffer.../trading-costs/scripts/charges.py (futures STT 0.05% on the sell side
since Apr 2026). The plan counts one round trip per leg plus one per roll, and futures carry (the
long leg pays it, the short earns it).../fno-options-analysis/scripts/options.py). They are physically
settled. The plan lists roll-by dates within the expected hold (2× half-life). Near expiry, it
switches to the next month.--ban-list (NSE fo_secban.csv), --banned SYM, or --mwpl-a/--mwpl-b (%). See
indian-market-structure.HDFCBANK/ICICIBANK, KOTAKBANK/AXISBANK, SBIN/BANKBARODA, TCS/INFY, HCLTECH/WIPRO, BPCL/HPCL (IOC as a third), ULTRACEMCO/SHREECEM, TATASTEEL/JSWSTEEL. They share sector, regulation and macro drivers. That makes them worth testing, not cointegrated by default. Re-test every quarter.
screen reports, and confirm on a later window.Size the risk-to-stop rupee figure with position-sizing; compare broker costs in trading-costs;
ban and margin rules in indian-market-structure; expiries in fno-options-analysis; sector
backdrop in sector-rotation.
Pair A / B: N sessions [from → to] | corr r | β (OLS / TLS) | EG t = x vs 5% crit y → reject? p≈
Half-life H sessions | z now Z → zone | β stability: stable/drifting/unstable | verdict
Signal (in-sample): trades n, hit rate h%, avg r% | now: flat / open / signal
Plan: SELL A fut n lots / BUY B fut m lots | mismatch ±x% | margin ₹ | charges ₹ | roll by date
Risks: F&O ban, lot revision, results dates, structural break
Educational analysis, not investment advice.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub xdhruv/claude-trading-skills-india-mv --plugin india-trading-skills36 skills in this plugin
/backtest-labBacktests 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.
/breakout-plannerStage-2 breakout setups on NSE/BSE stocks: a trend-template check (rising 200 DMA, 50>150>200
stack, distance from 52-week high/low, relative strength vs NIFTY), base detection (volatility
contraction with successively tighter pullbacks, or a flat base) with pivot, depth, duration,
volume dry-up and a grade, then an order-ready plan: trigger, chase limit, capped stop, size,
Indian charges, R targets, GTT/SL templates, circuit-band and NSE tick-size checks. breakout.py
scans a folder of CSVs or yfinance symbols and ranks them, offline-capable.
Use when the user asks: "is X in a Stage 2 uptrend", "find VCP setups", "where is the pivot on X",
"plan a breakout trade in X", "breakout buy point and stop", "scan these stocks for breakouts",
"Minervini trend template for NSE stocks", "how do I place a GTT for a breakout", or any question
about buying stocks as they clear a base.
2 plugins ship this exact skill · first indexed Nov 4, 2026
Other plugins' skills for the same job