Hi, I have this simple algo that screens for a new universe each month (top 2000 US stocks). As you can see the log, it is doing what it is supposed to do. However, from the log, each Monday morning, Ondata is only getting a small number of stocks' data, as opposed to 2000 stocks' data. Any idea?
Zicai Feng
import statistics
from My_Universe_Selection import QC2000UniverseSelectionModel
class FocusedRedOrangeDragonfly(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 4, 1) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.SetExecution(ImmediateExecutionModel())
self.UniverseSettings.Resolution=Resolution.Daily
self.AddUniverseSelection(
QC2000UniverseSelectionModel())
def OnData(self, data):
'''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
'''
all_keys=list(data.keys())
if len(all_keys)>=1000:
for i in range(2):
self.Debug('hi, some symbols are {}'.format(str(all_keys[i])))
else:
self.Debug('not enough stock in universe? length is {}'.format(len(all_keys)))
Varad Kabade
Hi Zicai Feng,
The above algorithm is set to daily resolution. Therefore the daily candles will be time-stamped Tuesday-Saturday. In this case, the Slice objects passed to the OnData method on Monday is to notify the algorithm for information about dividends and splits. See the attached backtest for reference.
Best,
Varad Kabade
Zicai Feng
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!