I am trying to find a way to test a program on hundreds of different stocks, specifically the 500 in the SPY or the 500 in the QC500 stocks. Problem is, I've tried everything I can to use these but nothing works.
Here is my code I am trying to run:
from AlgorithmImports import *
# endregion
from Selection.FundamentalUniverseSelectionModel import FundamentalUniverseSelectionModel
from itertools import groupby
from math import ceil
from QuantConnect.DataSource import *
class SwimmingYellowGreenKitten(QCAlgorithm):
filteredByPrice = None
coarse = None
def Initialize(self):
# Set the start date to June 2021 and the cash to 100000.
self.SetStartDate(2021, 6, 1)
self.SetEndDate(2023, 6, 1)
self.SetCash(100000)
# qcDataStuff = qcData.QC500
#self.Universe = self.SetUniverseSelection(QCAlgorithm)
# all this stuff is attempts to import 500 stocks/use them
# self.Universe = self.SetUniverseSelection( QC500UniverseSelectionModel() )
#self.AddUniverse(self.Universe.QC500)
#self.Debug("universe 1 unused is " + JSON.stringify(self.Universe.QC500))
#self.Universe = "SPY"
#self.Universe = QC500UniverseSelectionModel()
#self.AddUniverse(self.CoarseSelectionFilter)
#self.AddData(QCData.QC500)
self.daily_returns = {}
self.consecutive_increases = {}
def OnData(self, data: Slice):
# Loop through all the symbols in the stock "universe"?
self.Debug("data received")
for symbol in self.Universe:
if symbol not in self.daily_returns:
self.daily_returns[symbol] = [0]
if symbol not in self.consecutive_increases:
self.consecutive_increases[symbol] = 0
close = data[symbol].Close
# ETC, do stuff with the data
Basically, I can't figure out how to add and use the 500 stocks no matter what I try. I'm out of ideas. Any help or ways to do this would be amazing.
Kailo owhadi
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!