FinLab Getting Started: Build Your First Backtest in 3 Minutes
The fastest path is to choose an execution environment, download closing price data, write the first stock-selection condition, then run backtest.sim(). If you want AI-assisted strategy writing, start directly from FinLab Studio.
| Use case | Recommended entry | Next step |
|---|---|---|
| No installation, test a strategy immediately | FinLab Studio | Describe the strategy in natural language |
| First time using FinLab | Google Colab | Run the examples on this page |
| Existing Python environment | Local pip install finlab |
Download data and backtest |
| Complex dependency environment | Docker | Open JupyterLab |
Related guides: Data Download, Backtesting, and FAQ.
Installation
Supports Windows, macOS, Linux, and Colab; Docker also available.
Visit FinLab Studio to write strategies through AI conversation — no installation required.
Compatibility note
If you encounter dependency issues, try the Docker version instead.
Download Data
Use the following code to download data. You can browse available datasets.
Write a Strategy
Use simple Pandas syntax to write strategy logic. For example, buy the S&P 500 stocks that close at a 250-day high:
from finlab import data
from finlab import backtest
data.set_market('us')
with data.us_universe(index='SP500'):
close = data.get('price:adj_close')
# S&P 500 stocks closing at a 250-day high
position = close == close.rolling(250).max()
Backtest
data.us_universe(index='SP500') uses today's S&P 500 members for the whole history, so past results are overstated (survivorship bias); see Historical index backtests for a point-in-time version.