Backtesting and research toolkit for Taiwan equities, with data and market support for the US, Japan, Korea, and Hong Kong.
FinLab gives you market, fundamental, and alternative data through one function, a pandas-based FinLabDataFrame that aligns daily, monthly, and quarterly data automatically, and a Cython backtest engine that produces an interactive report.
Features
Data access: data.get() loads prices, financial statements, monthly revenue, institutional flows, and more as a date × symbol table. Browse the catalog at studio.finlab.finance/chat/database.
Frequency alignment: quarterly and monthly data are aligned to each company's disclosure date when combined with daily data, so a report is not used before it was published.
Backtesting: sim() runs portfolio backtests with rebalancing schedules, transaction costs, stop-loss and take-profit rules, and position limits.
Reports: an interactive report with the equity curve, drawdowns, yearly and monthly returns, trades, and risk metrics.
Charts: candlesticks with indicators, market treemaps, and fundamental radar charts built on Plotly.
Markets: Taiwan stocks and convertible bonds, plus US, Japan, Korea, Hong Kong, and UK equities and funds.
Live trading: turn a backtest into orders through supported Taiwan and US brokers.
Installation
pip install finlab
python -m finlab quickstart
These two commands take about a minute: sign in with Google in your browser (the first time creates a free account with a 7-day full trial, no credit card needed), download the data, run a Taiwan stock backtest and open its report. Your strategy is saved as finlab_quickstart.py; change it and run it again. For US stocks, add --market us.
FinLab supports Python 3.10 to 3.14. To log in without running anything, use . In Google Colab, call instead. For servers and CI, see .
Dependency security: FinLab requires certifi 2026.10.19 or newer. On Python 3.11+ (macOS 12+ on Mac), it also requires PyArrow 26 or newer. Python 3.10 remains supported with PyArrow 14.0.1 or newer. On macOS before 12, PyArrow stays below 18 to retain compatible wheels, including in universal lockfiles. PyArrow 26 has no compatible wheels for those environments. If you use PyArrow separately to read encrypted Parquet with a custom KMS client in those environments, upgrade Python/macOS or explicitly set a trusted KMS URL in KmsConnectionConfig, as described in the Apache Arrow security advisory. FinLab's Feather data reads do not use Parquet decryption.
Using Claude Code, Codex, or Cursor? Run python -m finlab skill install so your AI can backtest with FinLab.
Quickstart
Here is the same strategy in Python. Select the 20 companies with the strongest recent revenue growth, keep those trading above their 60-day average, and rebalance monthly:
from finlab import data
from finlab.backtest import sim
close = data.get('price:收盤價') # daily close
revenue = data.get('monthly_revenue:當月營收') # monthly revenue
growth = revenue.average(3) / revenue.average(12)
position = growth.is_largest(20) & (close > close.average(60))
report = sim(position, resample='M')
report.display()
Monthly revenue is aligned to its reporting deadline and combined with daily prices automatically. report.display() opens the interactive report in Jupyter; use report.to_html('report.html') elsewhere.
Illustrative in-sample backtest. Past results do not indicate future returns.
The report
The report opens on the performance view. Five scorecards (profit, risk, risk-adjusted return, win rate, liquidity) each check the strategy against a threshold and open their own charts:
Performance
Trades
Strategy vs. benchmark by year
Risk
Risk-adjusted return
Win rate
Liquidity and capacity
Current holdings
Search any stock from the report (⌘K) to open its chart, fundamentals, revenue, institutional flows, and margin data beside the results:
Working with data
Each data.get() call returns a FinLabDataFrame: dates as the index, symbols as the columns. Tables of different frequencies combine directly, and FinLab aligns quarterly and monthly values to their publication dates first.
from finlab import data
close = data.get('price:收盤價') # daily
revenue = data.get('monthly_revenue:當月營收') # monthly
roe = data.get('fundamental_features:ROE稅後') # quarterly
uptrend = close > close.average(60)
growing = (revenue.average(3) / revenue.average(12)).rise(3)
quality = roe.rank(axis=1, pct=True) > 0.7
position = uptrend & growing & quality & revenue.average(3).is_largest(100)
print(position.sum(axis=1).tail()) # stocks selected on each of the last five days
Frequently used methods include average, rise, fall, sustain, is_largest, is_smallest, industry_rank, and hold_until. See the FinLabDataFrame reference.
Backtest options and results
sim() accepts rebalancing frequency, execution price, position limits, exits, and trading costs:
from finlab.backtest import sim
report = sim(
position,
resample='W', # rebalance weekly
trade_at_price='open', # execute at the next open
position_limit=0.1, # at most 10% per stock
stop_loss=0.08,
take_profit=0.3,
fee_ratio=1.425 / 1000,
tax_ratio=3 / 1000,
)
stats = report.get_stats() # CAGR, max drawdown, Sharpe, ...
print({k: round(stats[k], 3) for k in ['cagr', 'max_drawdown', 'daily_sharpe']})
trades = report.get_trades() # one row per trade
print(trades[['stock_id', 'entry_date', 'exit_date', 'return']].dropna().tail(3))
print(report.next_weights.head(3)) # target weights for the next rebalance
Convert the latest target weights into share quantities and place orders through a broker account:
from finlab.online.order_executor import Position, OrderExecutor
from finlab.online.sinopac_account import SinopacAccount
position = Position.from_report(
report, 1_000_000, odd_lot=True
) # TWD 1M, odd lots allowed
executor = OrderExecutor(position, account=SinopacAccount())
print(position) # target lots per stock
executor.create_orders(view_only=True) # preview before sending
Output, for an account with no current holdings (quantities in lots; 1 lot = 1,000 shares):
symbol stock_id quantity order_condition
2301 2301 0.175 CASH
2303 2303 0.312 CASH
2330 2330 0.02 CASH
2357 2357 0.052 CASH
2377 2377 0.326 CASH
... (15 more stocks)
BUY 2615 X 0.429 @ 113.5 CASH
BUY 2330 X 0.02 @ 2500.0 CASH
BUY 3034 X 0.09 @ 545.0 CASH
BUY 3037 X 0.045 @ 1160.0 CASH
BUY 3044 X 0.092 @ 543.0 CASH
... (15 more orders)
Supported brokers: SinoPac, Fubon, Masterlink, E.SUN (Fugle), and Pocket for Taiwan; Charles Schwab for the US. Each broker requires its own SDK and credentials; see the order API guide.
Charts
Candlesticks with Bollinger Bands, volume, and KD for any Taiwan stock:
from finlab.plot import plot_tw_stock_candles
plot_tw_stock_candles('2330', recent_days=250)
A market treemap sized by market value and colored by return over a period:
from finlab.plot import plot_tw_stock_treemap
plot_tw_stock_treemap(
start='2026-08-24', end='2026-09-22', area_ind='market_value', item='return_ratio'
)
Fundamental decile ranks for a group of stocks:
from finlab.plot import plot_tw_stock_radar
plot_tw_stock_radar(portfolio=['2330', '2454', '2317'])
Other markets
Switch the data source with data.set_market() and pass the matching market to sim():
from finlab import data
from finlab.backtest import sim
from finlab.markets.us import USMarket
data.set_market('us')
close = data.get('price:adj_close')
position = close == close.rolling(200).max() # 200-day high
report = sim(
position,
resample='2W',
position_limit=0.2,
stop_loss=0.2,
market=USMarket(),
fee_ratio=0.001,
tax_ratio=0,
)
print(close.shape) # (dates, symbols)
print(position.iloc[-1].sum(), 'stocks at a 200-day high on', position.index[-1].date())
Output:
(2696, 10460)
95 stocks at a 200-day high on 2026-09-22
Market classes are available for Taiwan (TWMarket), US (USMarket), Japan (JPMarket), Korea (KRMarket), Hong Kong (HKMarket), and the UK (UKMarket), with fund variants for ETFs.
FinLab is software for research and education. Nothing in this package or its documentation is investment advice. Backtest results depend on data quality and modeling assumptions and do not predict future performance. You are responsible for your own trading decisions.
Alternatives
Use instead of finlab: tools that do the same job, closest first.