Skip to content

Clashrohit/Index-Market-Backtesting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ¦… Options Trading Backtesting Framework

A modular and extensible backtesting framework for Options Trading in Python.
Supports advanced strategies like Long Straddle, Long Strangle, Bull Call Spread, Bear Put Spread, and custom user-defined strategies β€” complete with PnL analytics, ML-based performance prediction, and risk metrics.


πŸš€ Features

  • βœ… Fetches NSE/BSE data automatically
  • βœ… Implements 5 popular option strategies
  • βœ… Simulates positional, intraday, and swing modes
  • βœ… Calculates key performance metrics: Cumulative PnL, Max Drawdown, Sharpe & Sortino Ratios, Win Rate
  • βœ… Machine Learning–based direction prediction
  • βœ… Beautiful tabular summaries and graphs

🧩 Example Usage

from strategies.bull_call_spread import BullCallSpread
from utils.data_fetcher import get_index_data
from utils.metrics import backtest_strategy

data = get_index_data("^NSEI", "2024-01-01", "2024-12-31")
strategy = BullCallSpread(buy_call_premium=120, sell_call_premium=80)

results, metrics = backtest_strategy(
    strategy, data, lot_size=50, premium=100,
    stop_loss_pct=0.1, target_profit_pct=0.2,
    trading_type="positional"
)

πŸ“ˆ Output Example

πŸ“Š Performance Metrics
╒════════════════════╀════════════╕
β”‚ Metric             β”‚ Value      β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•ͺ════════════║
β”‚ Final PnL (β‚Ή)      β”‚ 12,500.00  β”‚
β”‚ Max Drawdown (β‚Ή)   β”‚ 3,200.00   β”‚
β”‚ Sharpe Ratio       β”‚ 1.42       β”‚
β”‚ Sortino Ratio      β”‚ 1.85       β”‚
β”‚ Win Rate (%)       β”‚ 61.23      β”‚
β•˜β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•§β•β•β•β•β•β•β•β•β•β•β•β•β•›

πŸ€– Machine Learning Integration

from utils.ml_evaluator import evaluate_with_ml
from tabulate import tabulate

ml_results = evaluate_with_ml(results)
print(tabulate(ml_results, headers="keys", tablefmt="fancy_grid"))

Predicts the next-day direction of profit/loss using models like:

  • Random Forest
  • SVM
  • Logistic Regression
  • Neural Network (MLP)
  • KNN
  • Decision Tree
  • Naive Bayes
  • Gradient Boosting

βš™οΈ Installation

git clone https://github.com/<your-username>/options-backtesting-framework.git
cd options-backtesting-framework
pip install -r requirements.txt

🧠 Dependencies

pandas
numpy
matplotlib
scikit-learn
tabulate
nsepython
bse

πŸ“œ License

MIT License Β© Rohit Baskaran


πŸ’‘ Author

πŸ‘€ Rohit Baskaran
πŸ’Ό CSE Student | Interested in Trading, Stock Market & AI
πŸ“§ brohitbaskaran@gmail.com
πŸŒ™ GitHub: clashrohit


🏁 Next Steps (Optional Add-Ons)

  • Add visualization dashboards using Plotly
  • Integrate live NSE option chain API
  • Add Paper-Trading mode
  • Connect with Zerodha Kite or Angel One SmartAPI
  • Deploy via Streamlit or Flask for web interface

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages