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

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.11-cp314-cp314-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.14Windows x86-64

finlab-2.0.11-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (6.8 MB view details)

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

finlab-2.0.11-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.11-cp314-cp314-macosx_10_15_universal2.whl (2.6 MB view details)

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

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

Uploaded CPython 3.13Windows x86-64

finlab-2.0.11-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.11-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.11-cp313-cp313-macosx_10_15_universal2.whl (2.6 MB view details)

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

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

Uploaded CPython 3.12Windows x86-64

finlab-2.0.11-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.11-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.11-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.11-cp311-cp311-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.11Windows x86-64

finlab-2.0.11-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.11-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.11-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.11-cp310-cp310-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.10Windows x86-64

finlab-2.0.11-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.11-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.11-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.11-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: finlab-2.0.11-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.11-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 7339cda864c84555dca9dfb0669138b985977ab2aa939b9c465f6a821b393467
MD5 11e68af1fd5ac3041ac91a08d0487ca2
BLAKE2b-256 c3bec5aea2f1438c9bbf4239790be01b1abfbe9dcd9ea4cf6e6c1adcf68cb413

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 53c46bbfe01a468c803fd1202526dc0e333966da478d8792c418e6f577580ca9
MD5 ed67a2b57bca53bfff43f2738667fa4a
BLAKE2b-256 a37cbbb9ef481cc18f9953eda371a2cf65c1102a169a8065f81830e445f2c113

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fa415be0027b7b1ec34d43835852733a9d4097b0093ab8aea40d6486504bf3dd
MD5 cd63618001a699f3750fa8ed56aa1042
BLAKE2b-256 2168730c0517d28ceca94271e69f75f99f41acca531e3b37be3671fa6b166982

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 955ff09da5c104c0e943ab11e7d88cc26b9319a9bb076cf0f2b521d6aec3074c
MD5 4a8d07cb7e1b69ba927c98ebe99d79c9
BLAKE2b-256 1c210e0564641efe0a0ee3fe6007e6edf363b9b470f54f679853a05f19c3b6ec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: finlab-2.0.11-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.11-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 3a896ac94061387e9d162c9da0f3de2493dd988ebef3608c842d339a73d0da11
MD5 21d80ef93f3d6a81e5b4713863158623
BLAKE2b-256 a58b13a6102c519ecf415492ac85ee762684b13f2caef092f3fe2f2e4a6097b6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d956606e739afb0b0c4d35781d1bbf7b1192fe8d15f1a7f9d7ee58fe87da90ed
MD5 6b0b49d0cd42e12af12c47e7d09f205c
BLAKE2b-256 3fb77cbc635cfa6e8c059974d4fd1758ee57b05f8c658f089dacf45c8167376f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f68890c77bb98b93b1d160af749aabaf730757a2d46be4efd7e244db0e223b04
MD5 e4ecf4a2d9c71584e1b933533692457e
BLAKE2b-256 be7f9cdc5eb35457e757f61bf6213e0e93b2d69c68b527bd525fa96c85f1e829

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp313-cp313-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 8888888fd0e611c2d477f48728342db41e01e5fac45f16d835c95333cc01b4d6
MD5 00b49b639b63f9002c6b6382489ae0a3
BLAKE2b-256 8972feeb3f4043b788820d8d6971ed1dae700df9b3fc7d77e29a2431a9e6047d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: finlab-2.0.11-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.11-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 140eb79d269f2a01076a4ddadaf2aa994a215e6c239e3acbf5fc37b8d1542860
MD5 91400c7f97cd9da4ea509c04105d6d21
BLAKE2b-256 96e178bc18fd464a914a45afab96bb48729b0176e6f9ad9fd098d88bc033e39f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5630d1ebb1e189c69371561e48cf4cee1abc3e44626fe894a1a2268e6977788e
MD5 8cf7349583285eda296cb8bd0fdd5212
BLAKE2b-256 83fc03dab6ea2f603fcecf639ee19f0bde6b0c16d8d481ffe39dfac3b62253cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e93a8b505557238c24818136cd7d908dc46af865939543232f0df0e515cd7cac
MD5 16183956c6d17b1f4f6757d7c81c9bad
BLAKE2b-256 b431ec896ca2a219b8d7c6cf1fd9ef5940ed5bc67ac21ce110519a31f9da0c03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp312-cp312-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 123b07295325d8a40f757e699911f185efcb2b402965ee00d4fbdba6135af094
MD5 13d6555f6be63d9c38073090f8b85503
BLAKE2b-256 029088eb3c5effb102f97eb140b627425cf8f186eb9bf68629cda1154f0cc253

See more details on using hashes here.

File details

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

File metadata

  • Download URL: finlab-2.0.11-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.11-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 ca62d0785ca2e31d5798c1af8b733dca8b748083f566a5079cf03dc9c058d94c
MD5 4abf939f5895de7a059c696d9a7f3928
BLAKE2b-256 bbb7f724b88bc12a9f5b455af497ba71736eae39c305059a507a16ee77475133

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 cd571ef24521fd4743d880d99c2ab9448ea22e87f86f70c28134f1a9df3dd545
MD5 e99aa98a1b56cc38d9b96616fe95fb2d
BLAKE2b-256 62b8fe3c98633e3f47b0a8a1454c584dfc9f6e130ab2c9edb328af6d69392df4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e76fea9a340363f6ac628e8d5d562e0d0c30f0b8864f36b6fe46a16cdeb31f21
MD5 673ef4c6cdc662054a9aca2cf9248b8f
BLAKE2b-256 57cfa88cf7ac51f18e6eea163b7bd606a24f8940d9160a5c5e135e7fbe050161

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 4548e019d6e9b136e2df0522c2b6ea9d87d23cb943f0e81033199e70f52d743c
MD5 7058c0aba4fd193d64a662e3534323bb
BLAKE2b-256 d6eff7c90b2c9f4b3cb204186ec5a4ff250296111586470c6dcc75ba1e7f7628

See more details on using hashes here.

File details

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

File metadata

  • Download URL: finlab-2.0.11-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.11-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8024102701f6c9dfece3f35513d3ff274c65a8f63363dbc86562284808d6db50
MD5 d2ad06580ce93e02ba9ffce7a0d019f5
BLAKE2b-256 f6dfe3ae5d838f8827737ba03d39984badb72c4249adc25124af1f84d112f5ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ef42e9cde6a3892feb42097a3a47b5684ec96baea07aff210aad20d5b1598b19
MD5 cc703b4924e83b2f84ab74e909929ecc
BLAKE2b-256 454d849948dcb4c0e42fec60203c9bb9e61f6e14705a565f7236f32ab96aaec7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 eae6ed8238d64ee12ecb340b2478e340e8758d6d8633649452fcedd5a47c6064
MD5 8a03ed35a7726d6d7e31d4fd17457fda
BLAKE2b-256 3ce1332d2657e13e2d973f2bb7e8c7626cb9cd6a81153c14103142e47338234e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.11-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 e7ab95c2bf3bdd404c88d033c13b38e7db3b4e58001285fb6ebe8f3d73b9909e
MD5 eac2649cecc3a928bac8bea48911822b
BLAKE2b-256 c1c5009e894da486d7b217eed29723ac841a19ab5c2a54acca893340959d5d65

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