Howdy QC Community!

What is the most efficient way of creating a dataframe of historical price data in an algorithm?

Every day, I create a pandas dataframe of historical daily prices for 100+ securities and use that to calculate a portfolio.

My initial attempt was to do something like this:

history = self.History(symbols, 365, Resolution.Daily)

Grabbing this data has slowed down my algo significantly to about 3 real hours per 1 year of simulated time.

It reads in the docs:

> History call fetches the whole requested period and synchronizes the data.

So I tried this approach:

def Initialize(self):
   ...
   for symbol in symbols:
       self.Consolidate(
           symbol  = symbol,
           period  = Resolution.Daily,
           handler = self.process_daily_bar)

   self.history = {}

def process_daily_bar(conosolidated):   
   symbol = str(consolidated.Symbol)
   date  = consolidated.EndTime.date()
   self.history[symbol, date] = consolidated.Close

But this ended up taking the algo significantly longer. Almost 24 real hours per 1 year of simulated time.

Is there something I'm missing? Is there a better approach?

Thank you so much!