class qf_lib.backtesting.alpha_model.futures_model.FuturesModel(num_of_bars_needed: int, risk_estimation_factor: float, data_provider: qf_lib.data_providers.data_provider.DataProvider, cache_path: Optional[str] = None)[source]

Bases: qf_lib.backtesting.alpha_model.alpha_model.AlphaModel

Type of alpha model, which can be easily integrated with any type of Tickers (plain Ticker objects, as well as FutureTickers). It provides the functionality which allows to download the daily OHLCV prices data frame, regardless of ticker type (the get_data function).

  • num_of_bars_needed (int) – number of bars necessary to compute the exposure

  • risk_estimation_factor (float) – float value which estimates the risk level of the specific AlphaModel. Corresponds to the level at which the stop-loss should be placed.

  • data_provider (DataProvider) – DataProvider which provides data for the ticker. For backtesting purposes the Data Handler should be used.

  • cache_path (Optional[str]) – path to a directory, which could be used by the model for caching purposes. If provided, the model will cache the outputs of get_data function.


get_data(ticker_str, end_date, frequency, …)

Downloads the OHCLV Prices data frame for the given ticker.

get_signal(ticker, current_exposure, …)

Returns the Signal calculated for a specific AlphaModel and a set of data for a specified Ticker

get_data(ticker_str: str, end_date: datetime.datetime, frequency: qf_lib.common.enums.frequency.Frequency, aggregate_volume: bool = False)[source]

Downloads the OHCLV Prices data frame for the given ticker. In case of a FutureTicker, the function downloads the Futures Chain and applies backward adjustment to the prices.

  • ticker_str (str) – string representing the ticker for which the data should be downloaded

  • end_date (datetime) – last date for the data to be fetched

  • frequency (Frequency) – frequency of the data

  • aggregate_volume (bool) – used only in case of future tickers - if set to True, the volume data would not be the volume for the given contract, but the volume aggregated across all contracts (for each day the volume will be simply the sum of all volumes of the existing contracts of the given future asset)

get_signal(ticker: qf_lib.common.tickers.tickers.Ticker, current_exposure: qf_lib.backtesting.alpha_model.exposure_enum.Exposure, current_time: datetime.datetime, frequency: qf_lib.common.enums.frequency.Frequency)qf_lib.backtesting.signals.signal.Signal[source]

Returns the Signal calculated for a specific AlphaModel and a set of data for a specified Ticker

  • ticker (Ticker) – A ticker of an asset for which the Signal should be generated

  • current_exposure (Exposure) – The actual exposure, based on which the AlphaModel should return its Signal. Can be different from previous Signal suggestions, but it should correspond with the current trading position

  • current_time (datetime) – current time, which is afterwards recorded inside each of the Signals. The parameter is optional and if not provided, defaults to the current user time.

  • frequency (Frequency) – frequency of data obtained by the data provider for signal calculation


Signal being the suggestion for the next trading period

Return type