- lumibot.strategies.strategy.Strategy.get_historical_prices_for_assets(self, assets, length, timestep='minute', timeshift=None, chunk_size=100, max_workers=200, exchange=None, include_after_hours=True)¶
Get historical pricing data for the list of assets.
Return data bars for a list of symbols or assets. Return a dictionary of bars for a given list of symbols. Works the same as get_historical_prices but take as first parameter a list of assets. Any number of bars can be return limited by the data available. This is set with length in number of bars. Bars may be returned as daily or by minute. And the starting point can be shifted backwards by time or bars.
assets (list(str/asset)) – The symbol string representation (e.g AAPL, GOOG, …) or asset objects. Crypto currencies must specify the quote asset. Use tuples with the two asset objects, base first, quote second. ‘(Asset(ETH), Asset(BTC))’
length (int) – The number of rows (number of timesteps)
timestep (str) – Either
"minute"for minutes data or
"day"for days data default value depends on the data_source (minute for alpaca, day for yahoo, …)
timeshift (timedelta) –
Noneby default. If specified indicates the time shift from the present. If backtesting in Pandas, use integer representing number of bars.
include_after_hours (bool) –
Trueby default. If
False, only return bars that are during regular trading hours. If
True, return all bars. Currently only works for Interactive Brokers.
dictionary – Return a dictionary bars for a given list of symbols. Works the same as get_historical_prices take as first parameter a list of symbols.
- Return type
Asset : bars
>>> # Get the data for SPY and TLT for the last 2 days >>> bars = self.get_historical_prices_for_assets(["SPY", "TLT"], 2, "day") >>> for asset in bars: >>> self.log_message(asset.df)
>>> # Get the data for AAPL and GOOG for the last 30 minutes >>> bars = self.get_historical_prices_for_assets(["AAPL", "GOOG"], 30, "minute") >>> for asset in bars: >>> self.log_message(asset.df)