Features#
QF-Lib is a Python library that provides high quality tools for quantitative finance. Among the features, there are modules for portfolio construction, time series analysis, risk monitoring and a diverse charting package. The library allows analyzing financial data in a convenient way, while providing a wide variety of tools for data processing and presentation of the results.
QF-Lib is a convenient environment for conducting your own analysis. The results will be presented in a practical form and include a number of charts and statistical measures.
An extensive part of the project is dedicated to backtesting investment strategies. The backtester uses an event-driven architecture and simulates events such as daily market opening or closing. Thanks to the architecture based on interfaces, it is easy to introduce custom settings. Tested strategies can consist of different alpha models, position-sizing techniques, risk management settings and can specify commission pricing or slippage models. After testing a strategy on historical data, you can put it into a trading environment without modifications.
A powerful, event-driven backtester#
A large part of the project is dedicated to backtesting investment strategies. The backtester uses an event-driven architecture and simulates events such as daily market opening or closing. It is designed to test and evaluate any custom investment strategy.
Tech specs
Modular design (alpha models, risk management, position sizing)
Easy to build custom strategies
Tools to prevent look-ahead bias
Detailed summary of the backtest
Deploy strategies on testing or production environments
Applications
Financial engineering
Investment strategy development, evaluation and testing
Risk management
Financial analysis
Verification of investment ideas
Start with How to backtest your strategy or read Backtest flow.
Multi-tool for any financial research#
QF-Lib provides tools for portfolio construction, time series analysis, and risk monitoring. It allows analysing financial data in a convenient way and provides a wide variety of tools to process data and to present the results.
Tech specs
Flexible data sourcing (Bloomberg, Yahoo Finance, Alpaca, CSV, Quandl, and more)
Adapted data containers (based on Pandas)
Rich charting package
Export to Excel, PDF, or email notifications
Applications
Financial analysis
Building custom market indicators
Financial products evaluation
Portfolio construction
Risk management
Academic research
Time series analysis
See Portfolio Construction, plotting, and data_providers.
Examples of backtest reports#
After a backtest completes, QF-Lib generates tearsheets, portfolio analysis sheets, and trade statistics.
Walkthrough: Analysing Backtest Results.
Key capabilities#
- Flexible data sourcing
Choose Bloomberg, Yahoo Finance, Alpaca, CSV, Quandl, Haver, Portara, and other providers. Extend the
DataProviderinterface for custom sources; preload data to speed up research runs.- Look-ahead bias protection
Wrap providers with a data handler so backtests never see future bars.
- Adapted data containers
Time-indexed 1D/2D/3D structures for prices, returns, and log returns with straightforward casting from Pandas.
- Summary generation
Export studies to PDF, Excel, or HTML. See document_utils.
Project history#
QF-Lib is maintained by the CERN Pension Fund and is available under License. See Release Notes for version history.
Get started#
Installation
Install QF-Lib, optional data providers, and settings.json.
Tutorials
Backtesting, alpha models, data providers, and portfolio construction.
Tutorials →API reference
Auto-generated module and class reference.
API Reference →Community
Questions and collaboration on Discord.
Contact us →Flexible data sourcing#
The project supports an easy selection of the data source. It currently provides financial data from
Bloomberg, Yahoo Finance, Alpaca, Quandl, Haver Analytics, Portara, Binance, Interactive Brokers,
and CSV files. The DataProvider interface can be extended for any other source. For complex
computations, operation time can be reduced using data preloading. Data structures can be cached to
avoid excess requests when tests run multiple times. Incomplete data can be cleaned - for example
using regression.
See data_providers.
Tools to prevent look-ahead bias#
All DataProvider types (including custom ones) can be wrapped with a DataHandler, usable in
both live and backtest environments. It ensures data from the future is not passed into testing
components - essential in the backtester.
Adapted data containers#
QF-Lib introduces custom time-indexed data structures for prices, returns, and log returns. The
structures are 1-, 2-, and 3-dimensional and simplify conversion between data types. Any
time-indexed pandas DataFrame or Series can be cast using cast_dataframe and
cast_series.
See containers.
Summary generation#
Studies can be summarised in practical documents with charts, financial statistics tables, and custom sections. Supported formats include PDF, Microsoft Excel, and HTML. Documents can be published automatically to configured e-mail addresses.
See document_utils and Analysing Backtest Results.
Simple adjustment and extensibility#
The architecture supports miscellaneous tests and studies. QF-Lib works as a financial multi-tool for developers who want to facilitate research while keeping full control over custom logic.