Skip to main content

Analyzing stock has never been easier.

Project description

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

Project details


Release history Release notifications | RSS feed

This version

2.0.6

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

finlab-2.0.6-cp314-cp314-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.14Windows x86-64

finlab-2.0.6-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (6.7 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

finlab-2.0.6-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (6.5 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

finlab-2.0.6-cp314-cp314-macosx_10_15_universal2.whl (2.5 MB view details)

Uploaded CPython 3.14macOS 10.15+ universal2 (ARM64, x86-64)

finlab-2.0.6-cp313-cp313-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.13Windows x86-64

finlab-2.0.6-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (6.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

finlab-2.0.6-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (6.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

finlab-2.0.6-cp313-cp313-macosx_10_15_universal2.whl (2.5 MB view details)

Uploaded CPython 3.13macOS 10.15+ universal2 (ARM64, x86-64)

finlab-2.0.6-cp312-cp312-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.12Windows x86-64

finlab-2.0.6-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (6.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

finlab-2.0.6-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (6.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

finlab-2.0.6-cp312-cp312-macosx_10_15_universal2.whl (2.6 MB view details)

Uploaded CPython 3.12macOS 10.15+ universal2 (ARM64, x86-64)

finlab-2.0.6-cp311-cp311-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.11Windows x86-64

finlab-2.0.6-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (6.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

finlab-2.0.6-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (6.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

finlab-2.0.6-cp311-cp311-macosx_10_15_universal2.whl (2.6 MB view details)

Uploaded CPython 3.11macOS 10.15+ universal2 (ARM64, x86-64)

finlab-2.0.6-cp310-cp310-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.10Windows x86-64

finlab-2.0.6-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (6.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

finlab-2.0.6-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (6.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ ARM64manylinux: glibc 2.28+ ARM64

finlab-2.0.6-cp310-cp310-macosx_10_15_universal2.whl (2.6 MB view details)

Uploaded CPython 3.10macOS 10.15+ universal2 (ARM64, x86-64)

File details

Details for the file finlab-2.0.6-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: finlab-2.0.6-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for finlab-2.0.6-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 10274390e9d9e91c44664cd92696b2cc00a5d5f3f9555e6341a1c633919ecab6
MD5 9b00f6e5af1e4857a86c39d49b1d3525
BLAKE2b-256 d05e0126f68cf347bf8e2e0a7c29a8abd4893f26904b3d5982e7b2fff50aa790

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 bf6ca4ff738d169839e7ab04de06be8cd6235bb05736853c35a88cdae73217f4
MD5 696b1bdd7e858e8da03cacf5605f6584
BLAKE2b-256 24c16fff91cccdd03b96095b401f5bd91e445909d9d4c5df3db984e61d986b71

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 025e00eb89ebcccca0ecee98d5bbea3ba1b618da20106b3491bc93b73b3582a0
MD5 7e889fe8cc7e908c35b02a5523690a66
BLAKE2b-256 38cc563d6090abc29db29de581d9ffc6d3eacba9ccd1837810a6cb6050e688af

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp314-cp314-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 7d1f87667473290a3ce0983e7278d49be5a9c405c49fff0752d0163daff3a57e
MD5 a05ba2a68e3cd4e364c50b213758f0e0
BLAKE2b-256 b55964db70bf9c29e1ce8d07e90d6c2cd7f14aee3afd4c81969b804963149415

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: finlab-2.0.6-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for finlab-2.0.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 acacd21263d6a66868b519090406d137d617bf43b911556b670fb4ab5fc473ca
MD5 77675dc42cec60cd32bade1156f3829d
BLAKE2b-256 1d9ee054b1127469ada94b5bc5d4f1f8f6eb276379007579337206973275d7ea

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d4bc2f04baaebf2f5bc13adea05370ff6da9e192048f5a53241b8558a2294f17
MD5 0e3baddbf92a2314c2f3562b0f30885a
BLAKE2b-256 05b1024a067ac742cda4181422e20dfe196e06a5d00af6c580e001c08e59c7b1

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3ed0755da30c2eb2d5a699119ce66f755511cb2c51cf05fcb65f34a6c8519318
MD5 dd0492a5ce09008136ded40d1b1c6d78
BLAKE2b-256 8ec4025e5e99f4271dcb869c77d02c77cdf1d74cbbce27a5b89708682af3c7ba

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp313-cp313-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp313-cp313-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 8b46964e3b99c9f748dbcb94bb11525d77cf2214a60129b9a969ef9193d9f5e5
MD5 b3c918dd72957be27cf75c881229d320
BLAKE2b-256 d865fe82e407bffc24311cf0bbcc811089a9b41fc9e77e57681fc1b986cd683d

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: finlab-2.0.6-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for finlab-2.0.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 0ded71b2c9e32276641b391bd2908d83464327d468213c6636ca4397729da2e9
MD5 c029d194f43c36de98084a51f1b8db24
BLAKE2b-256 6ad39d28c595bc8265027defb836bba26140bdffd599c4dd185b5d2b88b75992

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 70f56eaeb0d96be4fd3880a21acaad333923bc4486009592f9ac6c818c8ffa13
MD5 f5df482622be93212814bcf4d372835e
BLAKE2b-256 579e7ba84d2fdc6f21ba89eaf6e8cf0d86fb0fabbb046c3b9b9ab1355f974170

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 3272b4e739616363e2bfc67a26b4979a99ad62d6f7a3fd90d26d89e7596bbe4d
MD5 d787cf55a8f80b05fc9c5223f1ae9526
BLAKE2b-256 b7b78b1b38d74075976f355638e59c22b32ca6ca7c9ef3a29c24f751e48d95b4

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp312-cp312-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp312-cp312-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 a69efb1d2ebb73ac1bd85f524a9301c1749b8861d2db29a9f490e39d77644951
MD5 cf81c592dd592acb98503056353c2ac2
BLAKE2b-256 ce118a6c8a20dbd5f6ed3893a1afdab12e4dbf6a03af0649afefb143e40ddd0c

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: finlab-2.0.6-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for finlab-2.0.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 56f67b38d545323eff9be0dda2a7979355ee2b3f259421eefd5a254fc2d16222
MD5 555d5622b4bd91e7587236d001e218a8
BLAKE2b-256 822cb038291e931e20c1be9e63bef73d568d7104578d6d4506c0f90fe68eacbc

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b49071cad71c0f8f1d58309308e38919b1a1a472e66d2ef142b9c05ff7988da0
MD5 f668625fe9483d9bb0903f288c66f2ea
BLAKE2b-256 136be5c04ca4c0f577f3c90d3e23c4c107cbd82e1d80ce0e273846659cec13f2

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 75438c3454e922776318ed8015fa0cc21254185df8a40c1c80f5b119a47eca4c
MD5 57d59a1fd73db81fbe0b5db137776f97
BLAKE2b-256 cbf08f0f8f2bee3eb8bdaa0ede2f46c93990de3242c7180c5ce09be61b5600cc

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp311-cp311-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 ec599413e7e7b657924cfea75b154f57dd5272c18399e4258f0449973ec2d8ae
MD5 3d3e6deaa7aeb6a10ace87b82fbb473f
BLAKE2b-256 5a2e7746e4a9dc84599a62128aa27d4a7e2d439d2fc978678350230177e0542b

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: finlab-2.0.6-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for finlab-2.0.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 16177a45963c6e05d2b076516bdc737e51b2be54a4fba3c35ac78ea9206a42dd
MD5 316a3936c6e2c40ed2ac899a0a265688
BLAKE2b-256 bced26c4395c73a911758064c5b3feaed3f6ece6d88a99fa789047876642da9a

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cab5ff222158f3f6216e343384d12346598c5b22c081fe88350c135c251b5d1c
MD5 cfb521f3c9d06d4846fce3cbd6c02d5b
BLAKE2b-256 8e98d5b6f44f58c61f9a94f2606db67271e0824d5443e1da91810023b81d8b10

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 76ad2136c07e66394a776491e9882b5d34064721ffc0ec4a562aa12ae3456f4d
MD5 f0aceb2eea305731e613497f1e10ab14
BLAKE2b-256 778140e78c57eb0f49ae6875c51f1138780ac6db3902bfa597f3e895ccb6db90

See more details on using hashes here.

File details

Details for the file finlab-2.0.6-cp310-cp310-macosx_10_15_universal2.whl.

File metadata

File hashes

Hashes for finlab-2.0.6-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 798a52d41ed3798b69e6d2fdb5977f528e26339b855078fb570adc85f586044e
MD5 25ffb91792a869b824afeb7001ec3308
BLAKE2b-256 e0933edc74c5a8da0b26ee75a816ecacc7b8d61674dcf3c771a3acff46391a7a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page