Hi Community!
I'm new to Quant Connect and struggling with some custom features on my own. Would really appreciate some help if anyone has time.
I am trying to create a Rolling Daily High price for the S&P500 future, which resets at 2100 London each day, for the continous futures contract series. Eg I want to observe all available price points in the last 24h each day at 9pm London and store that as a daily value.
I have been attempting to do this using a mixture of code from other forum Qs but am failing. Any help would be great!
from datetime import timedelta
from AlgorithmImports import *
class DCAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018,10, 10)
self.SetEndDate(2018,10,25)
self.SetCash(100000)
self.symbol = "ES"
self.SetBenchmark(self.symbol)
self.continuous_future_symbol = Symbol.Create(Futures.Indices.SP500EMini, SecurityType.Future, Market.CME)
self.contract_symbols = self.FutureChainProvider.GetFutureContractList(self.continuous_future_symbol, self.Time)
self.contract_symbol = sorted(self.contract_symbols, key=lambda symbol: symbol.ID.Date)[0]
self.AddFutureContract(self.contract_symbol, Resolution.Minute, extendedMarketHours=True)
self.consolidator = QuoteBarConsolidator(timedelta(1))
self.Schedule.On(self.DateRules.EveryDay(self.contract_symbol), self.TimeRules.At(21, 0, TimeZones.London), self.OnDailyData);
self.window = RollingWindow[float](2)
def OnDailyData(self):
self.window.Add(self.consolidator.WorkingData)
self.consolidator = QuoteBarConsolidator(timedelta(1))
def OnData(self, data):
self.consolidator.Update(data[self.contract_symbol].High)
currBar = self.window
self.Plot("Custom", "CurrB", currBar)
Mia Alissi
Hi Joe,
It seems like you're on the right track with your code, but there are a few things that might need to be adjusted.
Firstly, you're trying to create a rolling window of the daily high price for the S&P500 futures. In QuantConnect, you can use the
RollingWindow
class to store the last 'n' pieces of data. You've correctly initialized aRollingWindow
in yourInitialize
method. However, you're trying to addself.consolidator.WorkingData
to the window, which might not be the correct data you want. Instead, you should add the high price of the current bar to the window.Secondly, you're using a
QuoteBarConsolidator
to consolidate the data into daily bars. However, you're creating a newQuoteBarConsolidator
in yourOnDailyData
method, which might not be necessary. You should create and register the consolidator in yourInitialize
method, and then use itsDataConsolidated
event to update your rolling window.Here's a simplified example of how you can do this:
In this example,
OnDataConsolidated
is called every time the consolidator produces a new consolidated bar, and the bar is added to the rolling window. Then, in theOnData
method, you can access the most recent bar in the window withself.window[0]
.Please note that this is a simplified example and you might need to adjust it according to your needs. For example, you might need to handle rolling over the futures contract, or adjust the time zone for the consolidator.
I hope this helps! Let me know if you have any other questions.
Sources:
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.
SNDBOX
I am still unable to get a rolling 24 hour high price, resetting at 9pm London, if anyone reading has the key :)
Mia Alissi
Hi Joe,
To get a rolling 24-hour high price that resets at 9pm London time, you can use a combination of data consolidation and rolling windows. However, the provided extracts do not contain enough information to provide a confident answer on how to implement this in QuantConnect.
I would recommend checking out the QuantConnect documentation on data consolidation and rolling windows for more information on how to implement these features.
You might also find it helpful to look at the QuantConnect forum for examples of similar implementations.
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.
SNDBOX
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!