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

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

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

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

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

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

Download URL finlab-2.0.21-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
082362dc3821cdd4a5c00bbb38087b918bd5358135432f6aee9dd0ae1d270cde
BLAKE2b-256 checksum
How to use checksums
4140a828c7d03c13ae98834e548ab0cdecac6d62cbd2c30557dba3234258c961
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

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

Download URL finlab-2.0.21-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
cbea14f39e58e2d2f7d6b0007f8f719f576750bedff13959f043e9b09d6e3c5d
BLAKE2b-256 checksum
How to use checksums
3d3c266bb98ef56b6f3f62d70cba0d1d45bf15b1465cb2b6c6c9adc93459d558
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

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

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

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

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

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

Download URL finlab-2.0.21-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
2345754c7f9907458176e1b008185a3ef49adcbe9d6be1af6da658f4fd1a8bef
BLAKE2b-256 checksum
How to use checksums
a78ff9cf0e37c2ac91737568bbcbd77924d51ecb54e37f4ed48544a1917d5031
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

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

Download URL finlab-2.0.21-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
8d60df6caa973ecc91be1ec308268f52f05d095a548d923d8f93b719462f27a2
BLAKE2b-256 checksum
How to use checksums
41768360cc4041e64158b3bb77b0c2add8c9a08dc372fb9d48038b77299aa30b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

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

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

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

Download URL finlab-2.0.21-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
032e65c1f332d53ba8fe8efbf82412bb48f0e20688a6531b1b9192642aa66df8
BLAKE2b-256 checksum
How to use checksums
36f3fbe2cf634814036efd8bb09b5e771fbdd0e0c2b6c9c721b318e8b5d2934e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

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

Download URL finlab-2.0.21-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
09a39835aa8638e9c25dc8034a991023ac67178617c70f2c759549734858be0d
BLAKE2b-256 checksum
How to use checksums
470ac01cb544269514e2a4b09e028a4aeb1534264c2cdedc684ec8cae117b664
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

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

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

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

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

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

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

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

Download URL finlab-2.0.21-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
58a0ef5d1e70662a28f10739509960df6ae554ed30aee599704468457c87a2da
BLAKE2b-256 checksum
How to use checksums
0013e9141f684fd25fa334697e30fe6f6f9d3c43087fe23ed8943a3d759c146f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

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

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

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

Download URL finlab-2.0.21-cp310-cp310-win_amd64.whl
Size 2.1 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
0e9b4a83725705fc3be12ac0c2e5c7fc9181b8f031369cce234dff430e2d04c3
BLAKE2b-256 checksum
How to use checksums
fd76ae13bc0b27ed1f2d2ef2456c61780723d74135ad8ab15f0ac284ae241b85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

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

Download URL finlab-2.0.21-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
750515f98a5157ddcd448f8f713b2297d2c52f504995e4af501922fe0274c5dd
BLAKE2b-256 checksum
How to use checksums
b554d444533bea52796122209021ed31fde6fc115b9d25ed5058b469883671cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

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

Download URL finlab-2.0.21-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
18acf67cfcc25519904f2b8ec0060f9f6478ac885eb36b6621957acaf8146af1
BLAKE2b-256 checksum
How to use checksums
cf4252238381a3b9b2b208f8e2ab75e621689f3873d71821218452049cf4e784
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

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

Download URL finlab-2.0.21-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
1645d1be210fb0f0ca4518e0941e0ce2a39ded6bc64c3c61ba883e8121719fff
BLAKE2b-256 checksum
How to use checksums
13105ef84432ad2e7790f17201b793825775c3db00fabbccf12f5bffde4f30e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release history Release notifications | RSS feed

2.1.1

20 release files

2.1.0

20 release files

This release

2.0.21 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