Hello
I am trying to use Universe Selection to find pre-market losers (that lost more than 10%, since last regular hours close), using the following code:
class CreativeFluorescentYellowGoshawk(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 6, 24) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.UniverseSettings.Resolution = Resolution.Minute
self.UniverseSettings.ExtendedMarketHours = True
self.AddUniverse(self.CoarseSelectionFunction, self.TopLosers)
def CoarseSelectionFunction(self, coarse):
return [x.Symbol for x in coarse if x.HasFundamentalData and x.Market == 'usa']
def TopLosers(self, data):
fine = []
lsrs = {}
for x in data:
c = self.History(x.Symbol, 2, Resolution.Daily)['close'].values[0]
p = x.Price
pct = (p-c)/c * 100
lsrs[x] = pct
return [x for x in lsrs.keys() if lsrs[x]<-10]
My question is: Does this work as expected? And if so. is this the best and more idiomatic way to find pre-market losers?
Furthermore, I have some questions regarding UniverseSettings that were not very clear to me in the documentation.
- How often is Universe Selection Preformed?
- Does UniverseSettings.Resolution = Resolution.Minute mean that Universe Selection is going to be run on a minute basis? Or does it mean that the data available inside the corase and fine filtering functions has minute reselution?
- Does UniverseSettings.ExtendedMarketHours = True mean that Universe Selection is going to be preformed outside regular market hours? Or does it mean that the data available inside the corase and fine filtering functions provides data outside regular market hours?
Fred Painchaud
Hi Jose,
I won't answer your first question as I don't really know if this is the optimal way or more idiomatic or anything like that.
However:
1- Once a day, during the night, in live trading. Samething during backtest, but maybe at 00:00.
2- UniverseSettings are the settings for the Universe Selection mechanism and most settings in it refer to the securities that are going to be put inside it. See https://lean-api-docs.netlify.app/classQuantConnect_1_1Data_1_1UniverseSelection_1_1UniverseSettings.html.
So Minute resolution here means securities will have minute res by default in it.
3- The latter.
Fred
Jose Filipe
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!