I am sure this is a very simple question for those with more experience with QC
I am trying to get the minute data from the past 3 minutes (current - 2 min, current - 1 min, current) to send to a function to determine what action to take. This process should be repeated every minute from 10:02 AM until 3:59 PM at which point all assets would be liquidated. What I have is partially as follows:
def Initialize(self):
self.SetStartDate(2020, 1, 1) # Set Start Date
self.SetEndDate(2020, 1, 10) # Set end Date
self.SetCash(100000) # Set Strategy Cash
self.symbol = self.AddEquity("SPY", Resolution.Minute).Symbol
# get minute data self.Schedule(self.DateRules.EveryDay(self.symbol),self.TimeRules.Every(TimeSpan.minutes(1)),Action(self.CheckDirection))
# close all positions at the end of the day
self.Schedule(self.DateRules.EveryDay(self.symbol),self.TimeRules.At(15,59),self.ClosePositions)
def OnData(self, data):
self.Plot("Data", self.symbol, self.Securities)
# some action
def CheckDirection(self):
timeMinus = self.History(self.symbol, 2, Resolution.Minute)["timeMinus"]
A = timeMinus(2)
B = timeMinus(1)
C = timeMinus(0)
... (the rest of this is just calculations, not relevant to getting the time-based data)
my intention is to get the 'timeMinus' matrix to update each minute with the last 3 minutes of data and then to assign current-2min to variable A, etc
I seem to be missing something syntactically, but am not sure what. If you are able to help I would be most appreciative.
-J
Derek Melchin
Hi Miles32000,
Performing a History request each minute is inefficient. Consider replacing this logic with a RollingWindow. We then just need to setup a consolidator to keep the RollingWindow updated with the 3 latest minutes bars.
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.
Miles32000
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!