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

1.5.0

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

finlab-1.5.0-cp313-cp313-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.13Windows x86-64

finlab-1.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

finlab-1.5.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

finlab-1.5.0-cp313-cp313-macosx_10_13_universal2.whl (3.0 MB view details)

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

finlab-1.5.0-cp312-cp312-win_amd64.whl (2.3 MB view details)

Uploaded CPython 3.12Windows x86-64

finlab-1.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

finlab-1.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

finlab-1.5.0-cp312-cp312-macosx_10_13_universal2.whl (3.0 MB view details)

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

finlab-1.5.0-cp311-cp311-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.11Windows x86-64

finlab-1.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

finlab-1.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

finlab-1.5.0-cp311-cp311-macosx_10_9_universal2.whl (3.0 MB view details)

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

finlab-1.5.0-cp310-cp310-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.10Windows x86-64

finlab-1.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

finlab-1.5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

finlab-1.5.0-cp310-cp310-macosx_10_9_universal2.whl (3.0 MB view details)

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

finlab-1.5.0-cp39-cp39-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.9Windows x86-64

finlab-1.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

finlab-1.5.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

finlab-1.5.0-cp39-cp39-macosx_10_9_universal2.whl (3.0 MB view details)

Uploaded CPython 3.9macOS 10.9+ universal2 (ARM64, x86-64)

finlab-1.5.0-cp38-cp38-win_amd64.whl (2.4 MB view details)

Uploaded CPython 3.8Windows x86-64

finlab-1.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.2 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

finlab-1.5.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.1 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

finlab-1.5.0-cp38-cp38-macosx_10_9_universal2.whl (3.0 MB view details)

Uploaded CPython 3.8macOS 10.9+ universal2 (ARM64, x86-64)

File details

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

File metadata

  • Download URL: finlab-1.5.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for finlab-1.5.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 7559c69c7010721fe1b3854d27265823dbf0ed990cbeae45bd5f665a95dac904
MD5 5b11d20e60e26b7ca1f3985340e125a6
BLAKE2b-256 2ae81e2a5854305727ce93c214494530d3a0c041b90552b76eb5dcac2f98591a

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1a09f8e7c63bbe750261ea202c9374e6187c3bebdcf3a50362d2b549b93dac12
MD5 c9604c976221ca7a2bac7adc6c5b4d64
BLAKE2b-256 d325b52b59f689cd62adf0d152f935c5b10c3d3c3c10c1f4d538373935e874a8

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f8b4a8a2211af0ba8fa54b3d1039a1a20b312a1ee834acd1766d525c2175982e
MD5 3363799dd20fdc06514619b2b0f68bbf
BLAKE2b-256 9cccf6f3d81f7445359074ff47f8bb8b3c088c3f0df783c2c09dcfa54e08c45e

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp313-cp313-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp313-cp313-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 f346c22f9338ac2482ff08e540e385da327faadd3e9374c79d8dff0586af6107
MD5 a0e75b5a551768457d4b4b7414720149
BLAKE2b-256 d14217bb4e7629129be4fe0a56fd87ca9761896c584ab90320baf7342e318cf7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: finlab-1.5.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for finlab-1.5.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ca9f5be224da7042339224cdb2e31f7db43f65c50aba37fc60f05550b25b2f39
MD5 8f70ff9e29cbd80ac1272832721ed0e5
BLAKE2b-256 1596b20096b327e50c8a358677f91c447a3abe02b08d5c810bc5b32e45011e4e

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c643286c3d100228a51a81aaa44b8bffbb2439d76cfe408025a13d0618cd5d56
MD5 345da51bbe458f97adc4cdf94f6b1a5f
BLAKE2b-256 2ef7e954f73e500cd235e07103d939fb226e9e6e3e6caa664494ad38f3704404

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cede5c372ee5d1a1cc9dd59afd917e1ecd548543369137497c6553fe156212c3
MD5 4d43d2a280244815d9218c2cdb02bc7e
BLAKE2b-256 aab89b4abfce4a0944208b0110747d1e2feeb7908d58d1db3027da81f07aa12e

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 86b8e6ded739e7bcd0f992e54bf5125c9a2116b4c63a7cdd751648bdd21fe8ca
MD5 571b029ffac1291f8b9147c61327bccc
BLAKE2b-256 b24bb3fd918589bbfd95fd313aa11c71370db12fe63fac05775049cd23661cc1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: finlab-1.5.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for finlab-1.5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 5a61ece398b6204bdf172c78e82fd860f7b06a0706a070763c2cd315e0d4cd1b
MD5 2907cf76a9e4d1c318db6c5dba462895
BLAKE2b-256 aaf883b14964011be96f17effbeb1d14de0d2ba21cfc001bab53c11bd1f89bd7

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b8ab829a89a3a3ab53fbbb8339485ef9c52763e53991d97e7cbd2bb3db83eae6
MD5 61e777eb7fe64d853ead4166daf4613e
BLAKE2b-256 732a985753a957b7ee485225b7c60bbbf24663d0be45eb1aa2e6a775f0c4cc7a

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1a00a16beae096cbe67326fdce410f6b42ea315ceaaf79ea030ff3f6959ca072
MD5 e7d3310757bb585f5c4a5dce6290c557
BLAKE2b-256 c9994baa320bb0c0a355da35f161864061b096d8f8f37b44705e6ec0311101c2

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp311-cp311-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp311-cp311-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 3e8cb6c26e58bdcd0fcb74de54b75c556fb806195c18d7f080b5af59e4df67bd
MD5 051e771d00921ca441f362a110822724
BLAKE2b-256 407d766ff02ca7af9570967f9a1a8c589af3d5f35f1e83083b465474ace0722a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: finlab-1.5.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for finlab-1.5.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8bf283aa71bca393931a83b905e1d6d76e8e42161896edcb271827676a4349cf
MD5 ae2ee7eceb7bde10ff12eaf13b052ab2
BLAKE2b-256 7e1e552c1192b4ded0752d8cdab126670c7e8dee28f5f21bb9e95a35220b3f4c

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e09793d1c74ac77ccd659f3c179881d0892fa6bf022fbb689060e8590be6f38a
MD5 be447211b2908078efe02e9958a45418
BLAKE2b-256 2444c8e2d1de0535f1e669da80578763768e1e6804ef418e2edb92a8d07c3d81

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c2c089e87a172ed98b9e582e9fdfc018305e8006c5360452a2ce0bb36e1bffda
MD5 12c6229081b2a615114a46d4fef0e4f7
BLAKE2b-256 468b7f256c89c9e5579052eb92352921f666e395a6fde748b19316feff7174bf

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp310-cp310-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp310-cp310-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 6f720e5c3ad35df9a53cac5c66c72b45da385e91c036a921898fcfc5cc7d3c19
MD5 30f2d524d33f19cb398613fd16fc3130
BLAKE2b-256 4ef08f92a35355d08a5d1e2e9e543e963ab7da001534b4f6dbecb368e5f20f83

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: finlab-1.5.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for finlab-1.5.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2a7d7a4e86c186f90770980f839304eadfb49dd382f196cc334531ef2ebb8bda
MD5 4a20fa21dbcea82ded5367432ceabf98
BLAKE2b-256 ba586394fc7ef5d66435bc42205c5429fd99c53bc2a9bacd5080b54883821384

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 66cca31e321323b1b499eefb9e97b07aa3a2b293e9ff11fe7792ac539381aea6
MD5 6404ef1cab72b7680fa769f2dd6c5646
BLAKE2b-256 4c8fe6196c7f3fcc1d57588651c9c559fb30e1b652581a7257ed278cf5500e5d

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 deab4c407a8ef7675e03c754466b5fb35d5c4bc85dd5869493aedd57a205d18e
MD5 eee94db5b91d6ffea2eab60a49422431
BLAKE2b-256 d6cac0cc1bf26250c1bdc319ce58f07140db19f6723c15e904cddd3078e92b08

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp39-cp39-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 f094d9463e626f70abd6cc6e16b01dbf94841af5a59b5736eb0bb9909f23f370
MD5 2bbbb86cf7114eedbdd8fa16cae30939
BLAKE2b-256 41ebbccc0e97a078c0910fd0174088f88be609f8234a5b58ffa0abe6fbb6f3f5

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: finlab-1.5.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 2.4 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for finlab-1.5.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 e90a0b0e7ab69a7bbf570f93cfb2b10cdb0deb10e11bb2eef3732f23d7eec972
MD5 663c2f8ab50c5b25bcfe8ce0918728fd
BLAKE2b-256 9a9217f067f6116852c29372f226caf3dcc729c3a6bcfd03d82b6be145da5580

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 61b0aece3fac1a6a3bb86de9a5cd32032f789a50ea2540f407d9177d03307b4f
MD5 6214ce3738a0a3a49294e15ee898a08f
BLAKE2b-256 aac3481c494ff6a05346bc40eeb2e1724863160514eff1ac8d7d1ff55b230819

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a56bf066ae011c5f7f25d12b47522b619c10e423f4b0b768d3e5292936558f95
MD5 2a56191b58ec76e7e43e7fea72ab0530
BLAKE2b-256 9082ebb518129ba752760a12a3367128cd3af9134510cacd1d6cad128c59d6db

See more details on using hashes here.

File details

Details for the file finlab-1.5.0-cp38-cp38-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for finlab-1.5.0-cp38-cp38-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 05ecfe39d0f297923bb8a3a28204388ec5c73f92f17de9d23d58b896c875c534
MD5 9d27e99e9b463fe8465d9380697d1871
BLAKE2b-256 eabc6e18b06321d75bcae5077c9ddc54d5a4e7fb2bd90b97395456cb5e13d6c5

See more details on using hashes here.

Supported by

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