Docs
Open Studio

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 results

Look 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.

Meet every module in one round first: each card is a job, so tap the module that does it. The first four are the code above.

Interactive level

Module dispatch: which module does each job?

Mission 1 of 3 Read the code on the card and tap the module below that runs it, for 4 cards

Card 1 of 10 Which module is this line?
close = data.get('price:adj_close')
0 first try
From data to backtest
Analyze and improve
Combine and trade live

Each module's purpose comes from this page's tables; the first four cards are the page's opening code.

From data to backtest

ModulePurpose
finlabSign in to FinLab and manage your credentials.
finlab.dataLoad U.S. and other market data, search datasets, set the stock universe and cache, and compute technical indicators.
FinlabDataFrameAlign data of different frequencies, write selection rules, take the top names by rank, and set entry and exit signals.
finlab.backtestTurn a position signal into a historical backtest, with rebalancing, stops and trading costs.
finlab.reportRead the backtest report: metrics, equity curve, trade log, uploading and sharing.

Analyze and improve a strategy

ModulePurpose
finlab.analysisCheck liquidity, MAE/MFE, stability across periods, drawdowns and excess return.
finlab.optimizeBacktest every combination of several conditions and compare them.
finlab.toolsEvent studies and factor analysis.
finlab.mlBuild machine-learning features and labels and train prediction models.
finlab.plotPlot price candlesticks, treemaps, radar and river charts of financial data, and strategy performance.

Combine strategies and trade live

ModulePurpose
finlab.portfolioCombine strategies, allocate weights, and sync positions with the cloud.
finlab.onlineConnect broker accounts, compare holdings and place orders.
finlab.marketDefine a market's price data, benchmark and trading rules, or add a market of your own.

Next steps

↑↓ Move Enter Open Esc Close