API reference
API Reference Overview
On this page4
This page lists every module in the FinLab package and what each one does. Writing a strategy usually takes four of them, in this order:
from finlab import data, backtest
data.set_market('us')
close = data.get('price:adj_close') # finlab.data: load data
position = close >= close.rolling(300).max() # FinlabDataFrame: write the rule
report = backtest.sim(position, resample='M') # finlab.backtest: backtest
report.display() # finlab.report: read the resultsLook up the others when you need them. Each page opens with a "Which function to use" table, then documents every function with its call, parameters and defaults, return value and examples.
From data to backtest
| Module | Purpose |
|---|---|
| finlab | Sign in to FinLab and manage your credentials. |
| finlab.data | Load U.S. and other market data, search datasets, set the stock universe and cache, and compute technical indicators. |
| FinlabDataFrame | Align data of different frequencies, write selection rules, take the top names by rank, and set entry and exit signals. |
| finlab.backtest | Turn a position signal into a historical backtest, with rebalancing, stops and trading costs. |
| finlab.report | Read the backtest report: metrics, equity curve, trade log, uploading and sharing. |
Analyze and improve a strategy
| Module | Purpose |
|---|---|
| finlab.analysis | Check liquidity, MAE/MFE, stability across periods, drawdowns and excess return. |
| finlab.optimize | Backtest every combination of several conditions and compare them. |
| finlab.tools | Event studies and factor analysis. |
| finlab.ml | Build machine-learning features and labels and train prediction models. |
| finlab.plot | Plot price candlesticks, treemaps, radar and river charts of financial data, and strategy performance. |
Combine strategies and trade live
| Module | Purpose |
|---|---|
| finlab.portfolio | Combine strategies, allocate weights, and sync positions with the cloud. |
| finlab.online | Connect broker accounts, compare holdings and place orders. |
| finlab.market | Define a market's price data, benchmark and trading rules, or add a market of your own. |
Next steps
- Quickstart Run your first backtest in five minutes.
- Module architecture How the modules fit together.
- Load data Fundamentals, filings and how to find a dataset's name.
- Backtesting Rebalance frequency, stops, fees and the trade log.
Was this page helpful?