I am looking for an example how to do backtest on future options in c#,
Let's say the list of trades are available in list and below are some sample data.
for example first row means the future option call with strike 95000 on ZC (CBOT market) contract Mar 2025 was done on 2024-12-05 16:45 , Buy 1 with price of 2.875
Thanks for help
Mia Alissi
To help you get started with backtesting future options in C#, here's a step-by-step guide using the information from the documentation and API references:
Initialize the Algorithm: Set up your algorithm by specifying the start and end dates, initial cash, and the future contracts you want to trade.
Add Future Contracts: Use the
AddFuture
method to add the desired future contracts, such as ZC (Corn) from the CBOT market, and set appropriate filters for the contract months.Add Future Options: Utilize the
AddFutureOption
method to add options on the future contracts, applying filters to narrow down the option chain to your requirements.Access Option Chains: In the
OnData
method, access the option chains using theOptionChains
property from theSlice
object to retrieve available contracts.Select Contracts: Implement logic to select specific option contracts based on criteria such as strike price, expiry date, and option type (e.g., call or put).
Place Orders: Use methods like
MarketOrder
to execute trades on the selected option contracts based on your trading strategy.Handle Order Events: Implement the
OnOrderEvent
method to handle order events and log or debug information about executed trades.Here's a basic example of how you might set up a C# algorithm to backtest future options:
This example sets up a basic framework for trading future options on the Corn futures contract. You can modify the selection criteria and trading logic to suit your specific strategy.
Sources: Basic Template Future Option Algorithm, US Future Options - QuantConnect.com, Future Options - QuantConnect.com, Individual Contracts - QuantConnect.com, Futures Fast Trend Following, with Trend Strength
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.
Ryan Rahmati
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!