Data Sources#
Data Source#
- class lumibot.data_sources.data_source.DataSource(api_key=None, delay=None)#
Bases:
ABC
- DEFAULT_PYTZ = <DstTzInfo 'America/New_York' LMT-1 day, 19:04:00 STD>#
- DEFAULT_TIMEZONE = 'America/New_York'#
- IS_BACKTESTING_DATA_SOURCE = False#
- MIN_TIMESTEP = 'minute'#
- SOURCE = ''#
- TIMESTEP_MAPPING = []#
- calculate_greeks(asset, asset_price: float, underlying_price: float, risk_free_rate: float)#
Returns Greeks in backtesting.
- static convert_timestep_str_to_timedelta(timestep)#
Convert a timestep string to a timedelta object. For example, “1minute” will be converted to a timedelta of 1 minute.
- Parameters:
timestep (str) – The timestep string to convert. For example, “1minute” or “1hour” or “1day”.
- Returns:
timedelta – A timedelta object representing the timestep.
unit (str) – The unit of the timestep. For example, “minute” or “hour” or “day”.
- get_bars(assets, length, timestep='minute', timeshift=None, chunk_size=10, max_workers=200, quote=None, exchange=None, include_after_hours=True)#
Get bars for the list of assets
- abstract get_chains(asset: Asset, quote: Asset = None) dict #
Obtains option chain information for the asset (stock) from each of the exchanges the options trade on and returns a dictionary for each exchange.
- Parameters:
- Returns:
Format: - Multiplier (str) eg: 100 - ‘Chains’ - paired Expiration/Strike info to guarentee that the strikes are valid for the specific
expiration date. Format:
chains[‘Chains’][‘CALL’][exp_date] = [strike1, strike2, …]
Expiration Date Format: 2023-07-31
- Return type:
dictionary of dictionary
- get_datetime(adjust_for_delay=False)#
Returns the current datetime in the default timezone
- Parameters:
adjust_for_delay (bool) – Whether to adjust the current time for the delay. This is useful for paper trading data sources that provide delayed data.
- Return type:
datetime
- get_datetime_range(length, timestep='minute', timeshift=None)#
- abstract get_historical_prices(asset, length, timestep='', timeshift=None, quote=None, exchange=None, include_after_hours=True)#
Get bars for a given asset
- Parameters:
asset (Asset) – The asset to get the bars for.
length (int) – The number of bars to get.
timestep (str) – The timestep to get the bars at. For example, “1minute” or “1hour” or “1day”.
timeshift (datetime.timedelta) – The amount of time to shift the bars by. For example, if you want the bars from 1 hour ago to now, you would set timeshift to 1 hour.
quote (Asset) – The quote asset to get the bars for.
exchange (str) – The exchange to get the bars for.
include_after_hours (bool) – Whether to include after hours data.
- get_last_day()#
- get_last_minute()#
- abstract get_last_price(asset, quote=None, exchange=None)#
Takes an asset and returns the last known price
- get_last_prices(assets, quote=None, exchange=None)#
Takes a list of assets and returns the last known prices
- get_round_day(timeshift=0)#
Returns the current datetime rounded to the day and applies a timeshift in days :param timeshift: The number of days to shift the datetime by :type timeshift: int
- Returns:
Rounded datetime with the timeshift applied
- Return type:
datetime
- get_round_minute(timeshift=0)#
Returns the current datetime rounded to the minute and applies a timeshift in minutes :param timeshift: The number of minutes to shift the datetime by :type timeshift: int
- Returns:
Rounded datetime with the timeshift applied
- Return type:
datetime
- get_strikes(asset) list #
Return a set of strikes for a given asset
- get_timestamp()#
Returns the current timestamp in the default timezone :rtype: float
- get_timestep()#
- get_yesterday_dividend(asset, quote=None)#
Return dividend per share for a given asset for the day before
- get_yesterday_dividends(assets, quote=None)#
Return dividend per share for a list of assets for the day before
- classmethod localize_datetime(dt)#
- query_greeks(asset)#
Query for the Greeks as it can be more accurate than calculating locally.
- classmethod to_default_timezone(dt)#