I am confusted about the following.
1) can we set dynamic strike price in a future based on its equity performanace.as of now i know is by using setfilter(-6,6).
2) i have tried a lot on how to do put and call based o the condition.
The condition is based on the future underlying asset performing in 2 consecutive 30 min bar at the opening of market.I need to liquidate the contract at the end.
class NadionTachyonProcessor(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 11, 4) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.AddEquity("SPY", Resolution.Minute)
self.future = self.AddFuture(Futures.Indices.SP500EMini)
self.future.SetFilter(-6,6,timedelta(0), timedelta(182))
# self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.BeforeMarketClose("SPY", 10), self.ClosePositions)
def OnData(self, slice):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data
'''
if self.Portfolio.Invested or self.openingBar is None or self.secondaryBar is None:
return
for kvp in slice.OptionChains:
if kvp.Key != self.option_symbol: continue
chain = kvp.Value
contracts = sorted(sorted(sorted(chain, \
key = lambda x: abs(chain.Underlying.Price - x.Strike)), \
key = lambda x: x.Expiry, reverse=True), \
key = lambda x: x.Right, reverse=True)
if (self.secondaryBar.Close > self.openingBar.High) and (self.openingBar.High>self.secondaryBar.Low>self.openingBar.High):
#call at price self.openingBar.Low
if (self.secondaryBar.Close < self.openingBar.Low) and (self.openingBar.High>self.secondaryBar.High>self.openingBar.High):
#call at price self.openingBar.High
def OnDataConsolidated(self, bar):
if bar.Time.hour == 9 and bar.Time.minute == 30:
self.openingBar = bar
if bar.Time.hour == 10 and bar.Time.minute == 0:
self.secondaryBar = bar
def ClosePositions(self):
self.secondaryBar = None
self.openingBar = None
self.Liquidate("SPY")
I have tried to implement it,but facing problem while making a call and put.It will be highly apprecieted if you can help in this.
I am providing the code that i write till now.
Derek Melchin
Hi Akash,
The code and description provided creates ambiguity on whether this is an options or futures strategy. Therefore, I have left the contract selection and purchasing code unattended. To assist, I have attached a backtest that uses a RollingWindow to fix the error of selecting the `openingBar` and `secondaryBar` and determining the purchasing price.
To complete the strategy, I recommend reviewing our documentation on futures or options. Additionally, the futures Bootcamp lesson or the options tutorial series will prove quite helpful. For a more involved, 1-1 session, consider our new tutoring initiative.
Best,
Derek Melchin
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.
Akash
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!