Hi, I am just messing around with the long straddle tutorial algorithim and I am a bit confused.
Once a call is executed, then that means I own some of the stock right? How do I sell the stock right away and restart the straddle strategy?
Sorry if this is a stupid question :/
Kevin Falk
I figured out my question.
Douglas Stridsberg
Always useful to share your insights with the wider community!
Squirrel24
Yes please. I didnt even figure out how to access optionchains in the slice object parameter of onData function yet. It seems to be null. Please link the tutorial.
Link Liang
Hi Kevin,
Yes you could definitely sell right after each buy. It will just make the algorithm not profitable at all. Simple put a self.Sell() after each self.Buy() statement would achieve the strategy you mentioned. Here is a code snippet with this modification:
from datetime import timedelta class BullCallSpreadAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2017, 4, 1) self.SetEndDate(2017, 6, 30) self.SetCash(1000000) equity = self.AddEquity("GOOG", Resolution.Minute) option = self.AddOption("GOOG", Resolution.Minute) self.symbol = option.Symbol # set our strike/expiry filter for this option chain option.SetFilter(-6, 6, timedelta(30), timedelta(60)) # use the underlying equity GOOG as the benchmark self.SetBenchmark(equity.Symbol) def OnData(self,slice): for i in slice.OptionChains: chains = i.Value if not self.Portfolio.Invested: self.TradeOptions(chains) def TradeOptions(self,chains): # sorted the optionchain by expiration date and choose the furthest date expiry = sorted(chains,key = lambda x: x.Expiry, reverse=True)[0].Expiry # filter the call and put contract call = [i for i in chains if i.Expiry == expiry and i.Right == OptionRight.Call] put = [i for i in chains if i.Expiry == expiry and i.Right == OptionRight.Put] # sorted the contracts according to their strike prices call_contracts = sorted(call,key = lambda x: x.Strike) if len(call_contracts) == 0: return self.call = call_contracts[0] for i in put: if i.Strike == self.call.Strike: self.put = i self.Buy(self.call.Symbol, 1) self.Buy(self.put.Symbol ,1) self.Sell(self.call.Symbol, 1) self.Sell(self.put.Symbol ,1) def OnOrderEvent(self, orderEvent): self.Log(str(orderEvent))
@Rupert I believe this is the tutorial example that Kevin was working on.
Hope it helps!
Kevin Falk
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!