Skip to content

Getting Started

Installation

Supports Windows, macOS, Linux, and Colab; Docker also available.

Visit studio.finlab.tw to write strategies through AI conversation — no installation required.

# Run in a new Colab notebook
!pip install finlab
pip install finlab

Compatibility note

If you encounter dependency issues, try the Docker version instead.

docker pull finlab/jupyter-finlab
docker run -p 8888:8888 finlab/jupyter-finlab
# Open JupyterLab using the URL shown in the terminal

Download Data

Use the following code to download data. You can browse available datasets.

from finlab import data
close = data.get('price:收盤價')
close.tail()
from finlab import data
data.set_market('us')
close = data.get('price:adj_close')
close.tail()

Write a Strategy

Use simple Pandas syntax to write strategy logic. For example, a 300-day high breakout strategy:

from finlab import data

close = data.get('price:收盤價')

# Buy stocks making 300-day highs
position = close >= close.rolling(300).max()
position
from finlab import data

data.set_market('us')
close = data.get('price:adj_close')
close = close[close.index.dayofweek < 5]  # remove weekends

# Buy stocks making 300-day highs
position = close >= close.rolling(300).max()
position

Backtest

from finlab import backtest

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