Glossary#

This page defines the key terms used throughout the QF-Lib documentation.

AlphaModel#

An abstract signal generator that, given a Ticker and its current Exposure, returns a new desired Exposure. Implement calculate_exposure(ticker, current_exposure) -> Exposure. See Create an Alpha Model based strategy.

AlphaModelStrategy#

A pre-built Strategy that drives one or more AlphaModel objects. On each event it calls calculate_exposure() for every ticker, generates Signal objects, and passes them to the PositionSizer.

BacktestTradingSession#

The central object that wires together all components of a backtest: data provider, broker, portfolio, order factory, event manager, monitors, and exporters. Created by BacktestTradingSessionBuilder.

BacktestTradingSessionBuilder#

The fluent builder used to configure and create a BacktestTradingSession. Set frequency, data provider, commission model, slippage model, and position sizer before calling .build(start_date, end_date).

CommissionModel#

Determines the commission charged per transaction. Built-in models: FixedCommissionModel, BpsTradeValueCommissionModel, IBCommissionModel. See Customize your backtest.

DataProvider#

The interface for fetching market data. Implementations include CSVDataProvider, BloombergDataProvider, AlpacaDataProvider, etc. All share the same get_price / historical_price interface. Inside a backtest, use ts.data_provider (or self.data_provider on a strategy); it respects the simulation clock so that requests at time t only see data up to and including t.

Event#

The core primitive of the event-driven architecture. Every time step in the backtest corresponds to dispatching one or more events (e.g. MarketOpenEvent, CalculateAndPlaceOrdersRegularEvent, MarketCloseEvent). Strategies subscribe to events and are called when those events fire. See Backtest flow.

ExecutionStyle#

Specifies how an Order is filled:

  • MarketOrder - fills at the next available price.

  • StopOrder - becomes a market order when price crosses the stop level.

  • MarketOnCloseOrder - fills at the market close price.

Exposure#

Enum with three values used by AlphaModel to express a directional view. The model returns only direction; PositionSizer turns it into order size.

  • Exposure.LONG - buy / hold a long position (profit when price rises).

  • Exposure.SHORT - hold a short position (profit when price falls).

  • Exposure.OUT - no position (flat).

Frequency#

Enum defining bar size: DAILY, MIN_1, MIN_5, MIN_15, MIN_30, MIN_60, WEEKLY, MONTHLY. Set on the session builder with session_builder.set_frequency(Frequency.DAILY).

InitialRiskStatsFactory#

Scores parameter combinations from Monte Carlo scenarios against a target return and maximum drawdown criterion. See Fast Alpha Model Testing.

Order#

An instruction to buy or sell a quantity of a Ticker with a given ExecutionStyle (MarketOrder, StopOrder, MarketOnCloseOrder) and TimeInForce (DAY, GTC).

OrderFactory#

A helper on the BacktestTradingSession (ts.order_factory) that converts portfolio-relative targets into explicit Order quantities. Key methods:

  • target_percent_orders(target_dict, execution_style, time_in_force) - generates orders to move each ticker’s weight to the specified fraction of portfolio value.

  • orders(quantity_dict, execution_style, time_in_force) - generates orders for explicit quantities.

OrdersFilter#

A pre-execution hook that adjusts or cancels orders before they reach the simulated broker. See How-To Guides.

Portfolio#

Tracks the current holdings, cash balance, and total value in real time during a backtest. Accessible as ts.portfolio. Key methods:

  • portfolio_eod_series() - time series of end-of-day portfolio value.

  • closed_positions() - list of all closed Position objects.

  • open_positions_dict - dict of currently open positions keyed by ticker.

Position#

An open or closed holding of one asset in the portfolio. The BacktestPosition tracks quantity, average entry price, and unrealised P&L in real time during the backtest. Closed positions are collected via ts.portfolio.closed_positions().

PositionSizer#

Converts Signal objects into sized Order objects. Built-in options:

PriceField#

Enum selecting one column of bar data: Open, High, Low, Close, Volume. See Working with Data Providers.

PricesSeries#

A QFSeries that represents a series of prices. Provides .to_log_returns() and .to_simple_returns() for converting to return series.

QFDataArray#

A three-dimensional extension of the containers (ticker × date × field), backed by xarray.DataArray. Returned when get_price is called with multiple tickers and multiple fields simultaneously.

QFDataFrame#

A typed subclass of pandas.DataFrame with a DatetimeIndex. Used for multi-asset price or return data (rows = dates, columns = tickers or fields).

QFSeries#

A typed subclass of pandas.Series with a DatetimeIndex, used throughout QF-Lib for time-indexed scalar data (prices, returns, signals).

ReturnsSeries#

A QFSeries of returns (either simple or log). Provides .to_prices() to reconstruct a price series.

ScenariosGenerator#

Bootstraps a trade return distribution into a matrix of Monte Carlo equity curves. Used in the Fast Alpha Model Testing workflow.

SecurityType#

Enum that classifies an instrument: STOCK, CRYPTO, FUTURE, etc. Used together with a Ticker subclass to tell the data provider what kind of instrument is being requested.

Signal#

The output of an AlphaModel. Contains:

  • suggested_exposure - the recommended Exposure (LONG, SHORT, or OUT).

  • fraction_at_risk - the ATR-normalised distance from entry to stop-loss level.

  • confidence - optional scalar in [0, 1].

  • expected_move - optional scalar indicating the model’s price target.

Slippage#

The difference between the expected fill price and the actual fill price, caused by market impact and bid-ask spread. Built-in models: FixedSlippage, PriceBasedSlippage, SquareRootMarketImpactSlippage. See Customize your backtest.

Strategy#

Any class that extends AbstractStrategy and implements calculate_and_place_orders(). The method is called each time the subscribed event fires. See How to backtest your strategy.

Tearsheet#

A one-page PDF summary of a strategy’s performance. Three variants: TearsheetWithoutBenchmark, TearsheetWithBenchmark, TearsheetComparative. See Analysing Backtest Results.

Ticker#

A typed identifier for a tradable instrument. QF-Lib uses different subclasses per data provider so the provider can interpret the symbol correctly (e.g. BloombergTicker for Bloomberg, AlpacaTicker for Alpaca). Use DummyTicker for demo and test data.

TimeseriesAnalysis#

A utility that computes a full set of risk/return metrics (Sharpe, Sortino, CAGR, Max Drawdown, etc.) from any price or return series. See Analysing Backtest Results.

Trade#

A round-trip: all Transaction objects that open and then close one directional position in a given Ticker. Computed post-backtest by TradesGenerator.

Transaction#

A record of a single fill event: ticker, quantity filled, fill price and commission. Multiple transactions can belong to the same logical Trade.