Back

How to retreive historical Option data in C#

Hello!

I have installed the nuget package for Visual Studio:

https://www.nuget.org/packages/QuantConnect.Lean/

Now I am really struggling on how to set up a code in C# to retreive historical data for an option. I have looked at many examples but they seem to be incomplete in the documentation: 

Get Historical Option Data

For example the below code is incomplete. How can I create a complete code here that works for C#?

qb = QuantBook();

var option = AddOption("SPY", Resolution.Minute);
option.SetFilter(-10, 10, 0, 180);
var option_history = GetOptionHistory(option.Symbol, new DateTime(2017, 1, 4, 10 ,0, 0), new DateTime(2017, 1, 4, 10 ,5, 0),sort = True);
df = option_history.GetAllData();
print(df.tail());

        

Update Backtest







0

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.


Hey Andreas,

The example you posted is for the research environment in python. You can access historical data for options in the C# backtesting environment. You can do this using a history call for the symbol of the contract you are interested in. You can learn more about options here.

Here is a simple example of using of retrieving the historical data for an options contract.
 

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed