Data Sources¶
Data Source¶
- class lumibot.data_sources.data_source.DataSource¶
Bases:
object
- 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 = []¶
- get_bars(assets, length, timestep='minute', timeshift=None, chunk_size=100, max_workers=200, quote=None, exchange=None, include_after_hours=True)¶
Get bars for the list of assets
- get_datetime()¶
- get_datetime_range(length, timestep='minute', timeshift=None)¶
- get_greeks(asset, implied_volatility=False, delta=False, option_price=False, pv_dividend=False, gamma=False, vega=False, theta=False, underlying_price=False)¶
Returns Greeks in backtesting.
- get_historical_prices(asset, length, timestep='', timeshift=None, quote=None, exchange=None, include_after_hours=True)¶
Get bars for a given asset
- get_last_day()¶
- get_last_minute()¶
- get_last_price(asset, timestep=None, quote=None, exchange=None, **kwargs)¶
Takes an asset and returns the last known price
- get_last_prices(assets, timestep=None, quote=None, exchange=None, **kwargs)¶
Takes a list of assets and returns the last known prices
- get_round_day(timeshift=0)¶
- get_round_minute(timeshift=0)¶
- get_timestamp()¶
- get_timestep()¶
- get_tradable_assets(dt, length=1, timestep='minute', timeshift=0)¶
- 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
- is_tradable(asset, dt, length=1, timestep='minute', timeshift=0)¶
- classmethod localize_datetime(dt)¶
- classmethod to_default_timezone(dt)¶
Pandas¶
- class lumibot.data_sources.pandas.PandasData(pandas_data, config=None, auto_adjust=True, **kwargs)¶
Bases:
lumibot.data_sources.data_source.DataSource
- IS_BACKTESTING_DATA_SOURCE = True¶
- MIN_TIMESTEP = 'minute'¶
- SOURCE = 'PANDAS'¶
- TIMESTEP_MAPPING = [{'timestep': 'day', 'representations': ['1D', 'day']}, {'timestep': 'minute', 'representations': ['1M', 'minute']}]¶
- clean_trading_times(dt_index, pcal)¶
- get_asset_by_name(name)¶
- get_asset_by_symbol(symbol, asset_type=None)¶
Finds the assets that match the symbol. If type is specified finds the assets matching symbol and type.
- Parameters
symbol (str) – The symbol of the asset.
type (str) – Asset type. One of: - stock - future - option - forex
- Returns
- Return type
list of Asset
- get_assets()¶
- get_chain(chains, exchange='SMART')¶
Returns option chain for a particular exchange.
Takes in a full set of chains for all the exchanges and returns on chain for a given exchange. The the full chains are returned from get_chains method.
- Parameters
chains (dictionary of dictionaries) – The chains dictionary created by get_chains method.
exchange (str optional) – The exchange such as SMART, CBOE. Default is SMART
- Returns
A dictionary of option chain information for one stock and for one exchange. It will contain:
Underlying conId (int)
TradingClass (str) eg: FB
Multiplier (str) eg: 100
Expirations (set of str) eg: {20230616, …}
Strikes (set of floats)
- Return type
dictionary
- get_chains(asset)¶
Returns option chains.
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
asset (Asset object) – The stock whose option chain is being fetched. Represented as an asset object.
- Returns
dictionary of dictionary for ‘SMART’ exchange only in
backtesting. Each exchange has –
Underlying conId (int)
TradingClass (str) eg: FB
Multiplier (str) eg: 100
Expirations (set of str) eg: {20230616, …}
Strikes (set of floats)
- get_expiration(chains, exchange='SMART')¶
Returns expiration dates for an option chain for a particular exchange.
Using the chains dictionary obtained from get_chains finds all of the expiry dates for the option chains on a given exchange. The return list is sorted.
- Parameters
chains (dictionary of dictionaries) – The chains dictionary created by get_chains method.
exchange (str optional) – The exchange such as SMART, CBOE. Default is SMART.
- Returns
Sorted list of dates in the form of 20221013.
- Return type
list of str
- get_greeks(asset, implied_volatility=False, delta=False, option_price=False, pv_dividend=False, gamma=False, vega=False, theta=False, underlying_price=False)¶
Returns Greeks in backtesting.
- get_last_price(asset, timestep=None, quote=None)¶
Takes an asset and returns the last known price
- get_last_prices(assets, timestep=None, quote=None)¶
Takes a list of assets and returns the last known prices
- get_multiplier(chains, exchange='SMART')¶
Returns option chain for a particular exchange.
Using the chains dictionary obtained from get_chains finds all of the multiplier for the option chains on a given exchange.
- Parameters
chains (dictionary of dictionaries) – The chains dictionary created by get_chains method.
exchange (str optional) – The exchange such as SMART, CBOE. Default is SMART
- Returns
Sorted list of dates in the form of 20221013.
- Return type
list of str
- get_strikes(asset)¶
Returns a list of strikes for a give underlying asset.
Using the chains dictionary obtained from get_chains finds all of the multiplier for the option chains on a given exchange.
- Parameters
asset (Asset object) –
Asset object as normally used for an option but without the strike information.
Example: asset = self.create_asset(
”FB”, asset_type=”option”, expiration=self.options_expiry_to_datetime_date(“20210924”), right=”CALL”, multiplier=100,
)
expiration can also be expressed as datetime.datetime.date()
- Returns
Sorted list of strikes as floats.
- Return type
list of floats
- get_tradable_assets(dt, length=1, timestep='minute', timeshift=0)¶
- get_trading_days_pandas()¶
- get_yesterday_dividend(asset)¶
Return dividend per share for a given asset for the day before
- get_yesterday_dividends(assets)¶
Return dividend per share for a list of assets for the day before
- is_tradable(asset, dt, length=1, timestep='minute', timeshift=0)¶
- load_data()¶
- update_date_index()¶
Yahoo¶
- class lumibot.data_sources.yahoo.YahooData(config=None, auto_adjust=True, **kwargs)¶
Bases:
lumibot.data_sources.data_source.DataSource
- MIN_TIMESTEP = 'day'¶
- SOURCE = 'YAHOO'¶
- TIMESTEP_MAPPING = [{'timestep': 'day', 'representations': ['1D', 'day']}]¶