Hi, how can I change the resolution (to 5 minute bars) for the assets filtered through coarse and fine filters?
appriciate any help on this!
QUANTCONNECT COMMUNITY
Hi, how can I change the resolution (to 5 minute bars) for the assets filtered through coarse and fine filters?
appriciate any help on this!
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.
Omid Abdi
this is what I tried to do. The first time OnData is called, I create a consolidated data for each security in the universe, but the fiveMinHandler only has the first security's bar.
class main(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2019, 7, 21)
self.SetEndDate(2019, 7 ,23)
self.SetCash(100000)
self.priceTarget = [1,10]
self.outstandingShares = 10e06
self.UniverseSettings.Resolution= Resolution.Minute
self.AddUniverse(self.coarseFilter, self.fineFilter)
self.subscribe = True
self.TF= True
def coarseFilter(self, coarse):
result = [x.Symbol for x in coarse if (x.HasFundamentalData and x.AdjustedPrice > self.priceTarget[0] and x.AdjustedPrice < self.priceTarget[1])]
return [x for x in result]
def fineFilter(self,fine):
result = [x.Symbol for x in fine if x.EarningReports.BasicAverageShares.OneMonth < self.outstandingShares]
return [x for x in result]
def OnData(self, data):
if self.subscribe:
for security in data.Values:
fiveMinConsolidator = TradeBarConsolidator(timedelta(minutes=5))
fiveMinConsolidator.DataConsolidated += self.fiveMinHandler
self.SubscriptionManager.AddConsolidator(security.Symbol, fiveMinConsolidator)
self.subscribe = False
def fiveMinHandler(self, sender, bar):
if self.TF:
self.Debug(bar.Symbol)
self.TF= False
Alethea Lin
Hi Omid,
To change the data resolution for assets filtered through universe selection, we need to create a dictionary symbolData{} to store the Securities and their Consolidators. Then, in the OnSecuritiesChanged() method, we can update this dictionary after each Universe Selection and remove old consolidators so we no longer receive data from them. Please see the attached backtest and log as an example. In this example, I have limited fine selection to 2 securities and changed the data resolution to 30 minutes to show enough information without exceeding the log data maximum, but you can easily modify the code to suit your desired strategy.
Hope this helps!
Omid Abdi
Thank you Alethea, this is very helpful!
Omid Abdi
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!