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.19

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.19
File
finlab-2.0.19-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details
finlab-2.0.19-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
finlab-2.0.19-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.19-cp314-cp314-macosx_10_15_universal2.whl CPython 3.14 CPython 3.14 macOS 10.15+ universal2 (ARM64, x86-64) Details
finlab-2.0.19-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details
finlab-2.0.19-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.19-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.19-cp313-cp313-macosx_10_15_universal2.whl CPython 3.13 CPython 3.13 macOS 10.15+ universal2 (ARM64, x86-64) Details
finlab-2.0.19-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details
finlab-2.0.19-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.19-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.19-cp312-cp312-macosx_10_15_universal2.whl CPython 3.12 CPython 3.12 macOS 10.15+ universal2 (ARM64, x86-64) Details
finlab-2.0.19-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
finlab-2.0.19-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.19-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.19-cp311-cp311-macosx_10_15_universal2.whl CPython 3.11 CPython 3.11 macOS 10.15+ universal2 (ARM64, x86-64) Details
finlab-2.0.19-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
finlab-2.0.19-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.19-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.19-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.7 MB

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

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

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

Download URL finlab-2.0.19-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
a321fe066bc8d7045ec80ada2351fcb125ee76db8b6a451620c99a638c2f62f6
BLAKE2b-256 checksum
How to use checksums
1def743c8869ca3aafc6aaa5efceb9c2d8d5d7383552a5d68ed51332ee25986a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-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
dd8fc49c113798c5c38483f414033dc1c8eb3fb03f3ca7cedb2d40d372861ddf
BLAKE2b-256 checksum
How to use checksums
704c460607bd5d05da044dfe499e9460d9c0da19c90daecb2776e9586733e508
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-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
4c0eb5d418d7e561fdd4579beff1f366751a0e1390108464d294f5c505bd8348
BLAKE2b-256 checksum
How to use checksums
c38ed226e5e6bdea62ce97713e2b11c260f0c717ee4e9327f340845b3362d8dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

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

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

Download URL finlab-2.0.19-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
b2eb99aca016ac45b5fff3c8368e14ff400e041fd75b2ffd05920f731ef3beed
BLAKE2b-256 checksum
How to use checksums
de52f604aa83e92aeb8b0a50c7679e79675584de23655659679196eaa1bdbfdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-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
2d2a0fc4a380edbb455fa31c015958709670d3f69d4e2b6660ae4ad586925dd5
BLAKE2b-256 checksum
How to use checksums
2ff764a5fcc77651af23704c34c7a757ec3428ee51259299b4bdf28c5312e43f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-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
0e64a5318ee9d176f67d259a278a96ec21bfc3170260048020f7dba97c1d3959
BLAKE2b-256 checksum
How to use checksums
b1ec4c26bcdddfd582e531f5aa0b08355c4e4c031856f02416b1f5126a5a910a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-cp312-cp312-win_amd64.whl
Size 2.1 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
8cb89d0e848221a1141f303a9c2bc74e2fe8a4c2cdbba6a38f834029910c3874
BLAKE2b-256 checksum
How to use checksums
2620c2a03119bbe59b0efcd21dd9ebbc2ec7fd56ac7f3a2e12b48b1186484290
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-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
9cac61498fb9bffde15a5972d02121fe6174779cca4071ff816049b09cf849e7
BLAKE2b-256 checksum
How to use checksums
d628d0cb0ed41d26655b59366bb4f4e7d152d9fdbfd2202c13b654a1c4500b5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-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
5fe621355399ca32fc7db6a350d4f1da6c3f0df73af7c41d373ab2a61ff15ecd
BLAKE2b-256 checksum
How to use checksums
a839c0b9b0750ae9a489d8c5019b9425e17ce82fe5e4b560a13f145dcb067f22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-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
78cc8371790a41706b4ed394ff650bffc2d7f2078c3ddf6ab88ff6dbfd36d19c
BLAKE2b-256 checksum
How to use checksums
268a9f9e90321d26c6d43c237b863b8589a2265236dd0eecdf4c319e6f21e149
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-cp311-cp311-win_amd64.whl
Size 2.1 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
7601d3956f8d9526e41513efaff94e9138f6b5512d9635780178f406a0f381d6
BLAKE2b-256 checksum
How to use checksums
45085441ea1fd923d1301a53a3e37c03af4bc245434360a3f2bc5403651eea70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-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
5c3b785f365aa2df1b74dadbfe8b86da6671ccb58a5342b01b1cb9dba090903f
BLAKE2b-256 checksum
How to use checksums
66cf30089cb3dba9b10ad64336e142e7ec8586d8dafb65933bd15ed2431bab32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-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
c549b4d7b87eb61e49ff37f488187e09ea5e974cefb34b85f293a02fc69d641e
BLAKE2b-256 checksum
How to use checksums
62f43a8c70efe4ccd3bd4fda5df51821b49c8e4929a8d063e18ef2f97467d784
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-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
2c8697ba5aa9d8dbeba85d9d9551871715c96829686808707bc0e264fdee0c9d
BLAKE2b-256 checksum
How to use checksums
7ae5f21de9324db9c34a7fd852718c335810ddfdb8842ff7920eff6f65d451b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-cp310-cp310-win_amd64.whl
Size 2.1 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
28ab3f5c295ec38037db6962376d31faf27891b446955dc2f2c2fb33bff1c863
BLAKE2b-256 checksum
How to use checksums
92eb5f6c7d82c5ad38056b109f1421f55ae9e7fb88374adeb81411891641dea3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-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
bf2a4688f99fce5a8abeb1bc6efd2ed80cf8aefe60c7e66aa69a2c7887c2718c
BLAKE2b-256 checksum
How to use checksums
f20ee6f6295a636c0dc019097bf67243a7f46ceff4ad7e21a46c826030755b7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-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
cb92e127f2ac92f13047ff448ea74a79d2318cee8e5a02f92e967a0777e244c3
BLAKE2b-256 checksum
How to use checksums
6dc6372e369920e4ababe0a2d38cb34569ccbb9cb61da2cd9a76c79393deac9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

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

Download URL finlab-2.0.19-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
1188b85a2b49fbe3acee30bddcc1c2b3ea2b7a2e10f640d2fda08e3a1f082b3a
BLAKE2b-256 checksum
How to use checksums
958f98fa70aa1611687b874c2d67e4325c7f8f520481f7bdd34c45f8266b26e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release history Release notifications | RSS feed

2.1.1

20 release files

2.1.0

20 release files

This release

2.0.19 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