LEAN is the open source
algorithmic trading engine powering QuantConnect. Founded in 2013 LEAN has been built by a
global community of 80+ engineers and powers more than a dozen hedge funds today.
Alpha League Competition: $1,000 Weekly Prize Pool
Qualifying Alpha Streams Reentered Weekly Learn
more
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.
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.
Kevin Falk
19
,
I figured out my question.
0
Douglas Stridsberg
5.1k
,
Always useful to share your insights with the wider community!
1
Rupert
76
,
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.
1
Link Liang
6.1k
,
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:
# 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)
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...
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!