I am working offline with lean and generated some option data:
sudo lean data generate --start 20241201 --end 20241207 --tickers xyz --security-type option --resolution Minute
Afterwards I read the data into a Data frame:
from datetime import datetime, timedelta
qb = QuantBook()
start_date = datetime(2024,1, 1)
end_date = datetime(2024, 12, 31)
symbol = qb.add_equity("xyz", Resolution.MINUTE).symbol
index_option = qb.add_option(symbol, 'xyz')
index_option.set_filter(lambda u: u.include_weeklys().expiration(0, 0).strikes(-1,-1) ) #.calls_only().expiration(20, 280).delta(0.3,0.5))
option_history = qb.option_history(index_option.symbol, start_date, end_date, Resolution.MINUTE, fill_forward=False, extended_market_hours=False)
option_history.data_frame
I exepected an dataframe with option data, but got this:

My question is: How do I create fake option data for the local environment.
Mia Alissi
To create fake option data for the local environment using Lean, you can follow these steps:
Generate Option Data: You have already generated the option data using the
lean data generate
command. Ensure that the data is correctly generated for the specified date range and tickers.Read Data into DataFrame: Use the
QuantBook
class to read the generated data into a DataFrame. Make sure you are using the correct symbol and resolution.Add Equity and Option: Use
qb.add_equity
to add the underlying equity andqb.add_option
to add the option. Ensure you apply the correct filters for the options you want to analyze.Set Option Filters: Apply filters such as expiration and strike range using the
set_filter
method to narrow down the options data to your requirements. For example:Retrieve Option History: Use
qb.option_history
to retrieve the historical option data for the specified symbol and date range. Ensure thatfill_forward
andextended_market_hours
are set according to your needs.Convert to DataFrame: Access the
data_frame
property of theOptionHistory
object to convert the option data into a pandas DataFrame for analysis.Verify Data: Ensure that the data is correctly populated in the DataFrame by checking the columns and data types to confirm that the option data is as expected.
Here's an example of how you might set up your code:
Make sure to adjust the filters and parameters according to your specific needs. This setup should help you generate and analyze fake option data locally using Lean.
Sources: US Equity Options - QuantConnect.com, Opening Range Breakout for Stocks in Play, Sector Rotation Based On News Sentiment, Rendering Data with Notebooks - QuantConnect.com, Rendering Data with Python - QuantConnect.com
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Fari Tigar
The provided source code just creates data for an equity but not for options, eg strikes and expirations are not included.
Louis Szeto
Hi Fari
You can just replace and assign the symbol by
Best
Louis
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Fari Tigar
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!