Skip to content

NotCheeseMaggi/options-pricing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Options Pricing & Analytics — India (NSE/BSE)

A personal options analytics tool built for Indian markets. Prices options using Black-Scholes and Binomial Tree models, computes Greeks, evaluates trades against your market thesis, and backtests trade logic on historical data.

Built with Python and Streamlit. Data via yfinance.


Features

Single Contract Pricer

Price any NSE/BSE option with both Black-Scholes (analytical) and CRR Binomial Tree (numerical) models side by side. See all Greeks with plain-English explanations, early exercise premium, and sensitivity charts for price vs spot, delta/gamma/theta vs spot, and price vs volatility.

Strategy Builder

Compose multi-leg strategies with 8 pre-built templates — long call/put, bull/bear spreads, straddle, strangle, iron condor — or build custom legs. Shows P&L at expiry with profit/loss zones, break-even markers, aggregate position Greeks, and full transaction cost breakdown (STT, NSE charges, SEBI levy, GST, stamp duty).

Trade Evaluator

Describe the trade you're considering from Zerodha — strike, market price, expiry, your expected move, holding period (intraday or multi-day). The tool rates the trade across five dimensions: breakeven reachability, theta sustainability, pricing vs BS model, delta quality, and DTE risk. Gives a clear verdict (Strong / Reasonable / Marginal / Poor) with all reasoning explained.

Backtester

Model-based backtesting using Black-Scholes reconstructed prices. Test any trade setup (option type, strike offset, DTE, profit target, stop loss) over historical price data. Accounts for the NIFTY weekly Tuesday expiry cycle. Shows cumulative P&L, win rate, profit factor, exit reason breakdown, and performance by volatility regime.


Installation

git clone https://github.com/NotCheeseMaggi/options-pricing-india.git
cd options-pricing-india
pip install -r requirements.txt
python -m streamlit run app.py

Configuration

Broker transaction costs — edit broker_config.json in the project root to match your broker. Zerodha rates are the default. Any missing field defaults to 0.

{
  "broker_name": "Zerodha",
  "brokerage_flat_inr": 20.0,
  "stt_rate_sell": 0.000625,
  "nse_txn_rate": 0.00053,
  "sebi_rate": 0.000001,
  "gst_rate": 0.18,
  "stamp_duty_rate": 0.00003
}

RBI repo rate — update risk_free_rate in options_engine/market_config.py when RBI changes the rate at MPC meetings (roughly every 2 months).


Architecture

options-pricing-india/
├── app.py                        # Streamlit entry point
├── broker_config.json            # Broker cost configuration
├── options_engine/
│   ├── __init__.py               # OptionsEngine facade
│   ├── market_config.py          # India market context (lot sizes, rates, tickers)
│   ├── costs.py                  # Transaction cost calculator
│   ├── backtest.py               # Backtesting engine
│   ├── data/
│   │   ├── base.py               # MarketDataAdapter interface
│   │   └── yfinance_adapter.py   # yfinance implementation
│   ├── pricing/
│   │   ├── black_scholes.py      # BS pricer + analytical Greeks
│   │   └── binomial_tree.py      # CRR binomial tree (American/European)
│   ├── greeks/
│   │   └── calculator.py         # Chain enrichment + position aggregation
│   └── utils/
│       └── volatility.py         # Historical vol, IV solver, vol surface
└── pages_impl/
    ├── shared.py                 # Shared fetch functions and UI helpers
    ├── single_contract.py        # Single Contract Pricer page
    ├── strategy_builder.py       # Strategy Builder page
    ├── trade_advisor.py          # Trade Evaluator page
    └── backtester.py             # Backtester page

Data source — yfinance works well for NSE stocks (RELIANCE, TCS, HDFCBANK etc.). Index option chains (NIFTY, BANKNIFTY) are not available via yfinance due to NSE data restrictions; the Single Contract and Trade Evaluator pages work for indices using manual input. Full index option chain support requires the Zerodha Kite API (planned).


Supported Instruments

Indices (pricing + evaluation, no live chain) NIFTY 50, BANK NIFTY, FINNIFTY, MIDCPNIFTY, SENSEX

Stocks (full option chain via yfinance) RELIANCE, TCS, INFY, HDFCBANK, ICICIBANK, SBIN, WIPRO, LT, AXISBANK, BAJFINANCE, MARUTI, TATAMOTORS, HCLTECH, TECHM, KOTAKBANK, ADANIENT, SUNPHARMA, DRREDDY, ITC, and more.


Pricing models

Black-Scholes — closed-form pricing for European options with analytical Greeks (delta, gamma, theta, vega, rho). Validated against put-call parity. Handles edge cases: zero vol, expired options, deep ITM/OTM.

CRR Binomial Tree — 150-step Cox-Ross-Rubinstein tree for both European and American options with continuous dividend yield. Computes early exercise premium (American price − European price). Greeks via finite differences.

Implied Volatility — Brent's method solver, accurate to 1e-6. Returns None for options with no extrinsic value.

Time to expiry — computed using precise IST datetime arithmetic to 15:30 IST on expiry day, eliminating the off-by-one error from naive days/365 calculation.


Limitations

  • Index option chains require Zerodha Kite API (not yet integrated)
  • Backtesting uses model-reconstructed BS prices, not actual historical option prices
  • yfinance data is delayed and may have gaps for illiquid strikes

Roadmap

  • Zerodha Kite API adapter for live index option chains
  • Portfolio tracker for open positions
  • Historical IV database for more accurate backtesting

Disclaimer

This tool is for educational and personal research purposes only. It does not constitute financial advice. Options trading involves significant risk of loss.

About

Options pricing (BS, Binomial tree), Greeks, strategy builder and trade evaluator for Indian markets (NSE/BSE)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages