Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# self.get_historical_prices_for_assets

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.

  Parameters:

    - assets (list(str/asset)) – The symbol string representation (e.g. AAPL, GOOG, …) or asset objects. Cryptocurrencies 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, …). If you need, you can specify the width of the bars by adding a number before the timestep (e.g. “5 minutes”, “15 minutes”, “1 day”, “2 weeks”, “1month”, …)

    - timeshift (timedelta) – `None` by default. If specified indicates the time shift from the present. If backtesting in Pandas, use integer representing number of bars.

    - include_after_hours (bool) – `True` by default. If `False`, only return bars that are during regular trading hours. If `True`, return all bars. Currently only works for Interactive Brokers.

  Returns:

    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

  Example

      >>> # 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)

      >>> # Get the price data for EURUSD for the last 2 days
      >>> from lumibot.entities import Asset
      >>> asset_base = Asset(symbol="EUR", asset_type="forex")
      >>> asset_quote = Asset(symbol="USD", asset_type="forex")
      >>> bars =  self.get_historical_prices_for_assets(asset_base, 2, "day", quote=asset_quote)
      >>> df = bars.df