Skip to main content

FinLab

瞬間的閃念之中,揭示過去十年2000支股票的歷史數據,這就是finlab package!不僅如此,它與pandas無縫整合,讓你在策略創建的旅程中,如同進行一場華麗的交響樂演奏。其語法之簡潔,讓你撰寫策略時有如神助。

你只需要撰寫人類懂得邏輯,而程式會自動融合各種頻率的歷史數據來選股,這不僅是程式設計上的巧思,更是對簡潔的極致追求。當你以為這已經是頂峰,它的詳細回測結果,又將你帶入更深一層的分析維度,每一筆數據都讓你的決策更加精準。 在幾秒鐘之內,2000支股票的回測,這速度,這效率,它不僅是一個 package,這是一個交易者的夢想加速器!這是finlab,一個為熱血操盤手量身打造的回測神器!

功能

  • 📊 快速存取龐大資料集:單一指令即可取得2000支股票過去十年的歷史數據。
  • 🐼 Pandas整合:利用熟悉且功能強大的pandas函式庫,輕鬆設計交易策略。
  • 🔍 用戶友好的語法✍️:採用簡潔直觀編碼語法。
  • 🕒 多頻率數據處理:自動整合管理不同時間頻率的歷史數據。
  • 🔬 全面的回測分析:透過詳細的回測報告,獲得深入的洞察。
  • 🚀 高速計算:得益於 Cython 優化的性能,幾秒鐘內即可執行2000支股票的回測。
  • 🤖 機器學習:結合 qlib 研發機器學習策略。

相關連結

簡易教學

下載資料

輸入以下程式碼,即可下載資料。可以查詢有哪些歷史資料可以下載。

from finlab import data

data.get('price:收盤價')
date 0015 0050 0051 0052 0053
2007-04-23 9.54 57.85 32.83 38.4 nan
2007-04-24 9.54 58.1 32.99 38.65 nan
2007-04-25 9.52 57.6 32.8 38.59 nan
2007-04-26 9.59 57.7 32.8 38.6 nan
2007-04-27 9.55 57.5 32.72 38.4 nan

撰寫策略

可以用非常簡單的 Pandas 語法來撰寫策略邏輯,以創新高的策略來說,可以用以下的寫法:

from finlab import data

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

# 創三百個交易日新高
position = close >= close.rolling(300).max()
position
date 0015 0050 0051 0052 0053
2007-04-23 00:00:00 False False False False False
2007-04-24 00:00:00 False False False False False
2007-04-25 00:00:00 False False False False False
2007-04-26 00:00:00 False False False True False
2007-04-27 00:00:00 False False False False False

這邊的 position 是一個 False/True 的查詢表,當數值為 True ,代表該股票在當天有創新高,而數字 False 則代表沒有創新高。由於創新高的股票很少,上面的範例中,只有少數股票的數值會是 True。

假設我們希望每個月底,搜尋上表中數值為 True 的股票並且買入持有一個月,可以用以下的語法:

回測績效

from finlab import backtest

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

image

Release files for finlab 2.0.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for finlab 2.0.20
File
finlab-2.0.20-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
finlab-2.0.20-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details
finlab-2.0.20-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 Details
finlab-2.0.20-cp314-cp314-macosx_10_15_universal2.whl CPython 3.14 CPython 3.14 macOS 10.15+ universal2 (ARM64, x86-64) Details
finlab-2.0.20-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
finlab-2.0.20-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
finlab-2.0.20-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 Details
finlab-2.0.20-cp313-cp313-macosx_10_15_universal2.whl CPython 3.13 CPython 3.13 macOS 10.15+ universal2 (ARM64, x86-64) Details
finlab-2.0.20-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
finlab-2.0.20-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
finlab-2.0.20-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 Details
finlab-2.0.20-cp312-cp312-macosx_10_15_universal2.whl CPython 3.12 CPython 3.12 macOS 10.15+ universal2 (ARM64, x86-64) Details
finlab-2.0.20-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
finlab-2.0.20-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
finlab-2.0.20-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 Details
finlab-2.0.20-cp311-cp311-macosx_10_15_universal2.whl CPython 3.11 CPython 3.11 macOS 10.15+ universal2 (ARM64, x86-64) Details
finlab-2.0.20-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
finlab-2.0.20-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
finlab-2.0.20-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 Details
finlab-2.0.20-cp310-cp310-macosx_10_15_universal2.whl CPython 3.10 CPython 3.10 macOS 10.15+ universal2 (ARM64, x86-64) Details

Total release size: 91.8 MB

Release files / finlab-2.0.20-cp314-cp314-win_amd64.whl

Download URL finlab-2.0.20-cp314-cp314-win_amd64.whl
Size 2.1 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
c6bda196e52f21e5b8fb75fda473e082f230c2ea8c01c1775029f343ffd70ad5
BLAKE2b-256 checksum
How to use checksums
c0b60430d946ce1064305d9aaf34899218e57ecd52f83d5cad86dc0267959cd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL finlab-2.0.20-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 6.9 MB
Tags CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
57681ccb66c822ae8d8fa0ae1201170bc605e435d2a59cf6c8159982a2341f18
BLAKE2b-256 checksum
How to use checksums
546a71bf1672e5e0f9f9f196432bb9c52675b4d5855a856dee5a4b7825583813
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL finlab-2.0.20-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 6.7 MB
Tags CPython 3.14 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
1dabdcd2fa9738c13dd8759322e333ff1176c4b5908f09aa20aa287c21adcd36
BLAKE2b-256 checksum
How to use checksums
d9a5c7a6067c95bcb3e59a7f6470bf89e6ea5b607f720479e7f7afcab6a666b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp314-cp314-macosx_10_15_universal2.whl

Download URL finlab-2.0.20-cp314-cp314-macosx_10_15_universal2.whl
Size 2.7 MB
Tags CPython 3.14 macOS 10.15+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
f96089fbc7e927e41b29bd06f76dea8a9419fc8418cbd9b7a5b7a56d0d0012cd
BLAKE2b-256 checksum
How to use checksums
a7890ced28558b6f320ccdaa455aa6cd2d0ead723a5d61b35fb5cc47cc7a88a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp313-cp313-win_amd64.whl

Download URL finlab-2.0.20-cp313-cp313-win_amd64.whl
Size 2.1 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
c94e6544b8a672a8c957859839b0965c3ba220b9a5457916452d27bc35f67d39
BLAKE2b-256 checksum
How to use checksums
04d706fb5fff28d5fdeb994740a2fa5650b71bf10480e6f125e0388a5ff4d86b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL finlab-2.0.20-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 7.0 MB
Tags CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
155401805c01d9f63a56466250db347ac7874249a09eb24db165b0a2c997e0cb
BLAKE2b-256 checksum
How to use checksums
eff1e4136fa456315fc3c6dda255d9cf8ccd23b7804c2161ade47905f7b8f1b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL finlab-2.0.20-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 6.7 MB
Tags CPython 3.13 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
1fa4aac1f72c9b5970936d68d92a3b4b3fb4704bb5fe78f9b9df442bd6cc9c2c
BLAKE2b-256 checksum
How to use checksums
5e776c81dbf0a119d215ea02bc10ffeb9850a9fffdbc38e1790485c62958ea77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp313-cp313-macosx_10_15_universal2.whl

Download URL finlab-2.0.20-cp313-cp313-macosx_10_15_universal2.whl
Size 2.7 MB
Tags CPython 3.13 macOS 10.15+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
786b8e83ce6b085f7f0c0d88f60098aec809b698915c489940267def677ed040
BLAKE2b-256 checksum
How to use checksums
44e428d652b2694b34a9a87b2c28757b639d2d80606aa5113ec3bbb8c4d4b793
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp312-cp312-win_amd64.whl

Download URL finlab-2.0.20-cp312-cp312-win_amd64.whl
Size 2.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
164a902b31b2c580c5f77f17bf003dc366726eb3e1972edf5eab0fe50788fdda
BLAKE2b-256 checksum
How to use checksums
d4df2d2d6b8d1b590c0a1d09293e26aa564b3a4b234f3d5347f4b99f5e45f9c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL finlab-2.0.20-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 7.0 MB
Tags CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
fcb48bc8a6e69affb2e86b9dba73d29272225a854e4310c952496ab8007a978f
BLAKE2b-256 checksum
How to use checksums
f1318e2d3edc8451917e6c31ecb1923444e803b366f538ae8905620e28647c55
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL finlab-2.0.20-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 6.7 MB
Tags CPython 3.12 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
d59fecb5744cc46a00cc677010cdf522093005d123499223f61303f31151e7c3
BLAKE2b-256 checksum
How to use checksums
d4a17cd0e0e8967063653d17f3fc29757b8de0e809b52e84a21bab89d5cef68c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp312-cp312-macosx_10_15_universal2.whl

Download URL finlab-2.0.20-cp312-cp312-macosx_10_15_universal2.whl
Size 2.7 MB
Tags CPython 3.12 macOS 10.15+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
a77b12b473173331fc1c99b806e29bccebe32cc863f4efbae7ca496e1f2b4de0
BLAKE2b-256 checksum
How to use checksums
ef3c19dc75b89724934960ab4b0f22b88bd0dba66a99c69d8f284dff8d13783e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp311-cp311-win_amd64.whl

Download URL finlab-2.0.20-cp311-cp311-win_amd64.whl
Size 2.1 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
ee6cf689032f8c9ee7e192a2aa70163107ff984116ad9a29e7788df2bad8ee5b
BLAKE2b-256 checksum
How to use checksums
20fa152b99a774a72a0767136df1db80afbffe5f83b48c7a6558fb20ce9aa862
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL finlab-2.0.20-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 7.1 MB
Tags CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
aaa35f0dfc961389d09c4744613fc92e49d069096c90f194a18c0d7cd9c0d8c7
BLAKE2b-256 checksum
How to use checksums
4598025b1752e21c52641c708f97c2ac705a3c25ce437f287ceb82033d6d907d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL finlab-2.0.20-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 6.8 MB
Tags CPython 3.11 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
694c6535bee354804b62b306df2074f7f07176b1a03d7eea394fd4e8ae7c5fcd
BLAKE2b-256 checksum
How to use checksums
a0f775b24fa54fd69935a6b04e74c40f2a4ff10ede639092fcc6b77a2ae60302
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp311-cp311-macosx_10_15_universal2.whl

Download URL finlab-2.0.20-cp311-cp311-macosx_10_15_universal2.whl
Size 2.7 MB
Tags CPython 3.11 macOS 10.15+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
4e34f3d849f96449751180f852c9bc6d1d30758010f72ad593865855d2293877
BLAKE2b-256 checksum
How to use checksums
864e6ef11d11ed76b017034e0989d541e9e5d4b55572127cd6542125c7a833af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp310-cp310-win_amd64.whl

Download URL finlab-2.0.20-cp310-cp310-win_amd64.whl
Size 2.1 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
2cbb5d97720175452ba07205bfb944b7076a52845fd232a1ad88fa500de9deb2
BLAKE2b-256 checksum
How to use checksums
7631e6d2907fc4788f723b96189a1367753c6107cff699f284ea6f78aca1d3d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL finlab-2.0.20-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 6.6 MB
Tags CPython 3.10 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
1caf3eb8878967c4efcd315614cb02b864385d36140bb53f4e3803185494ddc0
BLAKE2b-256 checksum
How to use checksums
079ba6b4c7083aaa54e25d72986c5420f1d050e974c30084ddd45bdb7797f7ae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL finlab-2.0.20-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 6.3 MB
Tags CPython 3.10 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
1f626d813e0c570cf1b3ea10a358eaa903802d25cb323a64326ade20f26cd6b5
BLAKE2b-256 checksum
How to use checksums
254f3a97360ea9fad707f51a9a23c4b601e3ebd015447711fd1c81e0d95bfb21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release files / finlab-2.0.20-cp310-cp310-macosx_10_15_universal2.whl

Download URL finlab-2.0.20-cp310-cp310-macosx_10_15_universal2.whl
Size 2.7 MB
Tags CPython 3.10 macOS 10.15+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
9b8d8f3e95a42364654823f13550991a76414a0e8130621f8ad708af72a47211
BLAKE2b-256 checksum
How to use checksums
d6938eac9cdade7196438c9e1cb87795c96e56005ba4fecfecaf6b71bb7ef834
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.3

Release history Release notifications | RSS feed

2.1.1

20 release files

2.1.0

20 release files

This release

2.0.20 This release

20 release files

2.0.9

20 release files

2.0.8

20 release files

2.0.7

20 release files

2.0.3

20 release files

2.0.2

24 release files

2.0.1

25 release files

2.0.0

24 release files

1.5.7

24 release files

1.5.6

28 release files

1.5.5

28 release files

1.5.4

26 release files

1.4.0

24 release files

1.2.6

30 release files

1.2.5

30 release files

1.2.4

30 release files

1.2.3

28 release files

1.2.2

30 release files

1.2.1

30 release files

1.2.0

30 release files

1.1.6

30 release files

1.1.5

30 release files

1.1.4

30 release files

1.1.3

23 release files

1.1.2

30 release files

1.1.1

30 release files

1.0.9

30 release files

1.0.8

30 release files

1.0.7

30 release files

1.0.6

30 release files

1.0.5

30 release files

1.0.4

30 release files

1.0.3

30 release files

1.0.2

30 release files

1.0.1

30 release files

1.0.0

30 release files

0.5.3

25 release files

0.5.2

25 release files

0.5.1

25 release files

0.5.0

25 release files

0.4.6

25 release files

0.4.4

25 release files

0.4.3

25 release files

0.4.2

25 release files

0.4.1

16 release files

0.3.9

23 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page