← ClaudeAtlas

pair-tradinglisted

Statistical pair trading (market-neutral long/short) for NSE stocks. pairs.py tests whether two stocks are cointegrated (Engle-Granger with an ADF on residuals, judged against MacKinnon's cointegration critical values), estimates the hedge ratio, half-life and current spread z-score, screens every same-sector pair with a Bonferroni caution, lists in-sample z-score trades with a hit rate, and plans Indian execution: stock futures in whole lots, residual hedge mismatch, margin, charges, last-Tuesday rollover, F&O ban and lot-size revisions. Stdlib only; offline CSVs. Use when the user asks: "is HDFCBANK/ICICIBANK a good pair", "are TCS and INFY cointegrated", "find pairs in the bank/IT sector", "what is the z-score of the BPCL-HPCL spread", "pair trade entry and exit", "hedge ratio between two stocks", "how many lots for a pair trade", "how do I short the other leg in India", or wants a market-neutral or relative-value trade.
Shubhamkumartrichy/claude-trading-skills-india · ★ 62 · AI & Automation · score 84
Install: claude install-skill Shubhamkumartrichy/claude-trading-skills-india
# Pair Trading (NSE) 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. ## 1. Run it ```bash 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