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 sameget_price/historical_priceinterface. Inside a backtest, usets.data_provider(orself.data_provideron a strategy); it respects the simulation clock so that requests at timetonly see data up to and includingt.- 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 withsession_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) andTimeInForce(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
BacktestPositiontracks quantity, average entry price, and unrealised P&L in real time during the backtest. Closed positions are collected viats.portfolio.closed_positions().- PositionSizer#
Converts Signal objects into sized Order objects. Built-in options:
SimplePositionSizer- 100% of portfolio per signal (default).FixedPortfolioPercentagePositionSizer- allocates a fixed percentage of portfolio per signal.InitialRiskPositionSizer- sizes so that hitting the stop loss risks at mostinitial_riskof portfolio.InitialRiskWithVolumePositionSizer- same as initial-risk sizing, capped by recent average volume.
- 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 whenget_priceis called with multiple tickers and multiple fields simultaneously.- QFDataFrame#
A typed subclass of
pandas.DataFramewith aDatetimeIndex. Used for multi-asset price or return data (rows = dates, columns = tickers or fields).- QFSeries#
A typed subclass of
pandas.Serieswith aDatetimeIndex, 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, orOUT).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
AbstractStrategyand implementscalculate_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.
BloombergTickerfor Bloomberg,AlpacaTickerfor Alpaca). UseDummyTickerfor 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.