Nifty 100 Low Volatility Strategy: survivorship-bias-free files
================================================================

A Python tutorial from marketcalls.in, not a trading recommendation.

What is in this folder
----------------------
nifty100_low_volatility.py
    The full backtest and tear sheet script (OpenAlgo Python SDK,
    openalgo.backtest engine and openalgo ta).

nifty100_membership.csv
    Point-in-time Nifty 100 membership, January 2015 to November 2026.
    Columns: symbol, start, end
    One row per spell in the index. A stock that left and came back has
    two rows. "start" is the first session it was a member. "end" is the
    first session it was no longer a member (so the spell runs up to the
    day before). A blank "end" means it is still a member.
    230 rows, 187 symbols, 100 open spells today.

nifty100_sectors.csv
    Columns: symbol, sector
    One fixed sector label per stock, used for the 3-per-sector cap.

past_members/SYMBOL.csv
    Daily bars for the ten past members that merged or delisted:
    ABIRLANUVO, CAIRN, GSKCONS, HDFC, IDFC, INGVYSYABK, MINDTREE, PEL,
    RELCAPITAL, TATAMTRDVR.
    Columns: date, open, high, low, close, volume. The script back-adjusts
    splits and bonuses itself.

How to run
----------
1. pip install -U openalgo pandas numpy   (openalgo 2.4.1 or later)
   Optional, for PNG panels of the tear sheet: pip install playwright
   (it uses an installed Chrome).
2. Start your OpenAlgo server and copy the API key from its dashboard.
3. In this folder:
       export OPENALGO_API_KEY="your_key_here"
       python nifty100_low_volatility.py

The first run downloads daily bars for the current and former members and
the NIFTY and NIFTY 100 indices, and caches them in price_cache.pkl.
Stocks that no longer trade are read from past_members/. Point the script
at another folder with PAST_MEMBERS_DIR=/path/to/folder.

What it prints and writes
-------------------------
For each period (tuning 2015 to 2021, test January 2022 to 28 November
2025, sealed year 1 December 2025 to 27 November 2026): CAGR, maximum
drawdown, Sharpe and turnover for the strategy and the NIFTY 100, the last
rebalance's ten stocks and a summary table.

output/results.json        every figure by period
output/chained_curves.csv  the three periods joined into one curve, with the index
output/tearsheet.html      the tear sheet: summary statistics, equity curve,
                           underwater chart, monthly heatmap, yearly returns,
                           rolling 12-month return and volatility
output/panel_1..6.png      one image per tear sheet panel (needs playwright)

Rules in short
--------------
First trading session of January, April, July and October. Rank only the
stocks that were in the Nifty 100 that day, calmest daily price moves over
the last 126 sessions first. Buy the 10 calmest in equal weight, at most 3
from one sector. Orders fill at the next open with standard Indian delivery
charges and 0.1 percent slippage. A 2 percent cash buffer is kept, and idle
cash is credited 6 percent a year.

This is a backtest of past data.
