Hi, I couldn't find a lot of useful documentation for writing up option tradings. I need some serious help. For example, in theBasicTemplateOptionsAlgorithm.py:
1. what data type 'option' is in option = self.AddOption("GOOG"). It seems like a list but when I tried to find it in the API tab, it says AddOption returns QuantConnect.Securities.Option.Option, which has property 'Strike'. This doesn't look like a list. How can a list of options only have one strike attribute?
2. variable 'option' was not used when the code was trying to retrieve option quotes. Instead, it uses slice.OptionChain. Then I couldn't find how does the OptionChain structure look like. How is the filtered option in the initializing phase impacting the chain? I don't know.
3. I found self.Sell(OptionStrategies.Straddle(self.option_symbol, atmStraddle.Strike, atmStraddle.Expiry), 2) in another example but I couldn't find a list of available strategies under OptionStrategies in the API tab. I tried to guess, it tells me that OptionStrategies doesn't have IronCondor.
4. How can I exam a variable? like what value or structure it is? I tried to log and print with no luck. I need this if the type is not fully documented.
5. How is OnData is called? Is it a loop called every minute when reads in a minute bar? If I have some calculation in OnData, will it update the self.attributes I put under BasicTemplateOptionsAlgorithm class?
6. How can I filter option based on delta? How can I get IV30 for a symbol at each minute other than writing my own calculation functions?
7. If I want to do some machine learning, how to properly train a model? It seems that I can only write it in the main.py and train it on the fly? How can I preserve the model and use it later in live trading and keep optimizing it?
8. I think I can get started faster if I can just get access to the option data and write my own functions from scratch, is this an option here? Is downloading data an option?
Chi Zhou
I accidentally found this page. It seems answering a few questions above. I don't know how I got there and I don't see it in the navigation bar in the documentation page. I guess I will just bookmark it.
I also figured out how to use Log for simple string. But does it support concatination like print, e.g. Self.Log('var x: ', x)?
Chi Zhou
Do I have to iterate through the entire OptionChains like this "for kvp in slice.OptionChains: if kvp.Key != self.option_symbol: continue" every time I want to get the IV of a certain option contract? Is there something similar to OptionChains['SPY']? I am adding 100 stock options but I don't need to monitor all of them every day.
Chi Zhou
How can I place order on an option strategy and set taking profit or stop loss on it? For example: assuming same expiration date, how to implement this:
1. place order on an iron condor: sell 1 googl 1000 put, sell 1 googl 1100 call, buy 1 googl 950 put, buy 1 googl 1150 call. This resulted credit X
2. take profit:
when the price on the above strategy falls to 0.5X, close it: buy 1 googl 1000 put, buy 1 googl 1100 call, sell 1 googl 950 put, sell 1 googl 1150 call. This resulted debit 0.5X
OR
stop loss:
when the price on the above starty raise to 2X, close it: buy 1 googl 1000 put, buy 1 googl 1100 call, sell 1 googl 950 put, sell 1 googl 1150 call. This resulted debit 2X
Jing Wu
1) Option dataset is huge and there could be hundreds of contracts for one underlying asset. Therefore, unlike equity, the options data are stored in option chains. You can only access the price data in option chains. The majority of online brokers and stock trading platforms display option quotes in the form of an option chain using real-time or delayed data.
"OptionChains['SPY']['SPY181116C00290000']" is not a reasonable way to retrieve the option data as the option contract have expiry. In backtest at time t, you have no idea which contract is still available in the market. That's why you need to loop contracts in the option chain and select the contract with expiry and strike in the available contracts list. "SPY181116C00290000" is option contract name. It is SPY call option expiring on 11/16/2018 with the strike price 290. "SPY" is the underlying symbol. You can get the underlying symbol from the option contract with contract.Symbol.Underlying. See the following example
https://github.com/QuantConnect/Lean/blob/fdc866fda04e3de5a2c4ec892a4569b3face5700/Algorithm.Python/OptionRenameRegressionAlgorithm.py#L60
2) You can get the option chain for the specified underlying assets with GetValue() method. For example
# in Initialize() option = AddOption("GOOG") # in OnData(self, data) chain = slice.OptionChains.GetValue(option.Symbol) Â Â if chain is None: Â return Â
Where chain is a list of available contracts.
Please see this example
https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/BasicTemplateOptionsAlgorithm.py
3) For limit order and stop loss orders, please see the documentation
https://www.quantconnect.com/docs/algorithm-reference/trading-and-orders
4) You can make the paper trade with QC paper trade or with your IB paper account. We provide the live data feed for equity and forex. If you want to do paper trading with options or futures, you need to subscribe the options/futures data with IB.
5) At this time, LEAN does not have the feature to save the training model but you can import the custom data with the link into the current algorithm.
6) Options data is not available to download. You can conduct the research with the options historical data in research notebook.
Chi Zhou
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!