Hi,

I'm trying to get a pandas dataframe of historical prices for the last year from my universe. 

Right now I'm getting the error: 

During the algorithm initialization, the following exception has occurred: Framework algorithms must specify a portfolio selection model using the 'UniverseSelection' property.

How would I fix this?

Some other questions I have are:

How would I get historical prices from the Universe?

Could I filter based on historical prices in the fine selection function?

 

Here is what I have so far.

from clr import AddReference AddReference("System") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Common") from System import * from QuantConnect import * from QuantConnect.Orders import * from QuantConnect.Algorithm import * from QuantConnect.Algorithm.Framework import * from QuantConnect.Algorithm.Framework.Alphas import * from QuantConnect.Algorithm.Framework.Portfolio import * from QuantConnect.Algorithm.Framework.Selection import * from datetime import datetime, timedelta class HistoricalPriceUniverse(QCAlgorithmFramework): def Initialize(self): self.UniverseSettings.Resolution = Resolution.Daily self.SetStartDate(2017, 1, 1) self.SetEndDate(2017, 2, 1) self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction) self._changes = None def CoarseSelectionFunction(self, coarse): filtered = [ x.Symbol for x in coarse if x.HasFundamentalData ] return filtered[:] def FineSelectionFunction(self, fine): # for possible future implimentation return fine def OnData(self, data): # liquidate securities that were removed from universe for security in self._changes.RemovedSecurities: self.Liquidate(security.symbol) # This is where I would like to get dataframe of historical prices for securities self.Debug(Portfolio.keys) self._changes = none # this event fires whenever we have changes to our universe def OnSecuritiesChanged(self, changes): self._changes = changes self.Log(f"OnSecuritiesChanged({self.UtcTime}):: {changes}")

 

Author