Skip to content

Add Real Options Chain Data Support and Comprehensive Model Backtesting#1

Merged
ankitdutta428 merged 2 commits intomainfrom
feature/new-models
Feb 3, 2026
Merged

Add Real Options Chain Data Support and Comprehensive Model Backtesting#1
ankitdutta428 merged 2 commits intomainfrom
feature/new-models

Conversation

@ankitdutta428
Copy link
Copy Markdown
Owner

Summary

This PR adds support for fetching real options chain data from Yahoo Finance and enhances the comprehensive backtest example to test all available deep learning models with real market data.

Changes

  1. Options Chain Data Fetching ( finlearner/data.py )
  • Added DataLoader.download_options_chain(ticker, expiration=None) method that returns:

  • Call and put options DataFrames with bid/ask, strike, volume, open interest, implied volatility

  • Current underlying price

  • Selected and available expiration dates

chain = DataLoader.download_options_chain('AAPL')
calls = chain['calls']
puts = chain['puts']
spot = chain['underlying_price']
  1. Updated Comprehensive Backtest ( examples/examples-python/10_comprehensive_backtest.py )
  • Now fetches real market data from Yahoo Finance (TCS.NS)
  • Tests all deep learning models: LSTM, GRU, CNN-LSTM, and Transformer
  • Includes Golden Cross custom strategy for comparison
  • Outputs a comparison table with returns, Sharpe ratios, and max drawdown
  1. Updated Options Backtest ( examples/examples-python/11_options_backtest.py )
  • Uses real options chain data instead of synthetic model-calculated prices
  • Analyzes ATM options with market prices
  • Compares market prices vs theoretical model prices (BSM, Binomial Tree)
  • Demonstrates Bull Call Spread strategy with Greeks calculation
  1. Fixed Optional Dependencies ( finlearner/models.py )
  • Made torch and transformers imports optional with graceful fallbacks
  • Prevents import failures in environments without PyTorch installed
  • Core models (LSTM, GRU, CNN-LSTM, Transformer) now only require TensorFlow

Testing

  • Verified options chain fetching works correctly
  • Confirmed imports succeed without torch installed
  • All existing tests should pass

Notes

  • Yahoo Finance options data provides current snapshots only, not historical data
  • For true historical options backtesting, paid data sources (CBOE, Polygon.io) would be required
  • Indian stocks (NSE) may not have options data on Yahoo Finance; use US tickers for options demos

@ankitdutta428 ankitdutta428 self-assigned this Feb 3, 2026
@ankitdutta428 ankitdutta428 added documentation Improvements or additions to documentation enhancement New feature or request labels Feb 3, 2026
@ankitdutta428
Copy link
Copy Markdown
Owner Author

This PR is good to merge since it has passed all the tests.

@ankitdutta428 ankitdutta428 merged commit cd65e68 into main Feb 3, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant