Docs
Open Studio

Get started

Quickstart

On this page4

This page takes you from nothing to your first backtest: install → load data → write a rule → backtest, in about five minutes. Every snippet runs as is.

  1. 1 Get data
    data.get('price:adj_close')

    Dates down, stocks across

  2. 2 Write a condition
    close > close.average(60)

    True = hold that day

  3. 3 Backtest
    sim(position, resample='M')

    Returns, drawdown, trades

  4. 4 Go live
    PortfolioSyncManager

    Updates and orders every day

Pick where to run it

For a first try, use Google Colab: it runs in your browser, with nothing to install.

Open a new notebook in Google Colab and run this in the first cell:

!pip install finlab

Run your first backtest

Load closing prices

data.get() loads a dataset by its "table:field" name. The first run opens your browser to sign in to FinLab; a free account is enough.

from finlab import data

data.set_market('us')
close = data.get('price:adj_close')
close.tail()
dateAAPLMSFTNVDAAMZN
2026-10-26382.38612.12221.88249.09
2026-10-27385.93610.66223.87253.1
2026-10-28382.29610.3221.24254.6
2026-10-29387.94609.3219.47243.79
2026-10-30383.18599.84210.21240.35

You get back a table: one row per trading day, one column per stock (only a few are shown). Every FinLab dataset has this shape, including fundamentals and filings.

Write a stock-selection rule

Compare whole tables with Pandas. This line means "the close is at a 300-trading-day high":

position = close >= close.rolling(300).max()

The result is a table of the same shape, each cell True or False; True means hold that stock on that day. A comparison works on the whole table at once, as this example of "close above its 60-day average" shows:

close Closing price
AAPLMSFTNVDA
10/279851120
10/2810150118
10/2910449121
10/3010352117
close.average(60) 60-day average
AAPLMSFTNVDA
10/2710052115
10/2810051116
10/2910151117
10/3010151118
position What to hold
AAPLMSFTNVDA
10/27FalseFalseTrue
10/28TrueFalseTrue
10/29TrueFalseTrue
10/30TrueTrueFalse
Each cell is one stock on one day. A comparison works on whole tables at once, matching dates and stocks for you; each True is a stock to hold that day. Numbers are illustrative.

Backtest

Hand the rule to backtest.sim(). resample='M' checks the rule at each month end and trades on the next trading day:

from finlab import backtest

report = backtest.sim(position, resample='M')
report.display()

report.display() draws the full report. This is what the code above produces; you can explore it right here:

Backtest report · interactive Open full size

Read the report

The top of the report shows the equity curve and the figures people check first:

MetricWhat it means
Annual returnThe whole backtest's return, as an average per year
Max drawdownThe deepest fall from a peak: the hardest stretch to sit through
Sharpe ratioReturn per unit of volatility; higher is steadier
Win rateThe share of trades that made money

To get these figures in code, use report.get_stats(); to see every trade, use report.get_trades().

Next steps

  • Write better rules Take the top names by rank, combine conditions, set entries and exits.
  • Load more data Fundamentals, filings and how to find a dataset's name.
  • Tune the backtest Rebalance frequency, stops, fees and the trade log.
  • Run it daily Rerun the strategy every day and get rebalance alerts or place orders.

Not sure what a dataset is called? Search fields in the data catalog, or install the FinLab Skill in an AI coding assistant (Claude Code, Cursor and others) and ask "which datasets cover revenue?".

↑↓ Move Enter Open Esc Close