Hi,
sorry I'm sure you are cretainly respond to this answer 1 million times, but I didn't find my answser and from documentation it seems I do right.
So I wrote a simple algo and when I launch BT, it' work but I have any time yhe same result, I changed the data frame minute to daily, buy to sell, date range,... but any time the same result!!
Could you telle me please, where I do wrongly?
Thanks in advance.
Ps: sorry for my english.
my code is:
def Initialize(self):
self.SetStartDate(2015, 4, 1)
self.SetEndDate(2017, 5, 30)
self.SetCash(100000)
equity = self.AddEquity("GOOG", Resolution.Daily)
option = self.AddOption("GOOG", Resolution.Daily)
self.symbol = option.Symbol
# set our strike/expiry filter for this option chain
option.SetFilter(-15, 15, timedelta(35), timedelta(50))
# use the underlying equity GOOG as the benchmark
self.SetBenchmark(equity.Symbol)
for i in optionchain:
if i.Key != self.symbol: continue
chain = i.Value
# sorted the option chain by expiration date and choose the furthest date
expiry = sorted(chain,key = lambda x: x.Expiry, reverse=True)[0].Expiry
# filter the call options from the contracts expires on that date
call = [i for i in chain if i.Expiry == expiry and i.Right == 0]
call_contracts = sorted(call,key = lambda x: x.Strike)
if len(call_contracts) == 0: continue
# choose the deep OTM call option
self.call = call_contracts[-1]
put_contracts = sorted([i for i in chain if i.Expiry == expiry and i.Right == 1], key = lambda x: x.Strike)
# choose the deep OTM put option
self.put = put_contracts[0]
self.Sell(self.call.Symbol ,1)
self.Sell(self.put.Symbol ,1)
Jing Wu
We don't have daily data for options. You should request the Resolution.Minute. You should retrieve the option chain in OnData() instead of Initialize().
def OnData(self, data): for i in data.OptionChains: if i.Key != self.symbol: continue chain = i.Value
Please find more option examples here
Dupont
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!