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

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

Uploaded CPython 3.14Windows x86-64

finlab-2.0.4-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.4-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.4-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.4-cp313-cp313-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.13Windows x86-64

finlab-2.0.4-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.4-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.4-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.4-cp312-cp312-win_amd64.whl (1.7 MB view details)

Uploaded CPython 3.12Windows x86-64

finlab-2.0.4-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (6.7 MB view details)

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

finlab-2.0.4-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.4-cp312-cp312-macosx_10_15_universal2.whl (2.5 MB view details)

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

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

Uploaded CPython 3.11Windows x86-64

finlab-2.0.4-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.4-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl (6.5 MB view details)

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

finlab-2.0.4-cp311-cp311-macosx_10_15_universal2.whl (2.5 MB view details)

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

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

Uploaded CPython 3.10Windows x86-64

finlab-2.0.4-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (6.3 MB view details)

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

finlab-2.0.4-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.4-cp310-cp310-macosx_10_15_universal2.whl (2.5 MB view details)

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

File details

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

File metadata

  • Download URL: finlab-2.0.4-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.12

File hashes

Hashes for finlab-2.0.4-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 3247c0704b0f631b8484355118e83024552b104ac6ff7f64c2a953c442505e56
MD5 41562a0f17af02a15003f18874527a25
BLAKE2b-256 1561ad0267cb56cde906db12a748922df07f6b613aebffe52a8d43c0c616b33a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2abcfd4fab22aeb78787d8b9c58e92cf373b21aa7d8b59d4d2005cadc9c23099
MD5 4fc8d96128bfff958fd36e38dc03e2e4
BLAKE2b-256 992a6e756f272f6c671e8b2482a7d2ac2ba8ae7908f93c9f24b1ec7e762acfe1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 70df23d8d8bfd757157c939cf61c2893262060905afe6cd8d2ec251ba373a07b
MD5 d823b74e41d0f6a9b74e3c98a89904cc
BLAKE2b-256 72cde1c22c6ade1568d79ed3a144288195021c007e9b7060d687ebeb90e6b693

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp314-cp314-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 d2933a8c98b6e5225e2fb611e0c646e249c1636309bca027758d490aa9944cf7
MD5 56bed1598a5beddf7ba9103a8b315afe
BLAKE2b-256 5617bc944e05ded15800073565e69dee06f10b8848c8326e8ce692cf1304b744

See more details on using hashes here.

File details

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

File metadata

  • Download URL: finlab-2.0.4-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.12

File hashes

Hashes for finlab-2.0.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5c44ce832d1f1dc3dc32a4a8e98630257ddc9e423e78a551ab5fa0e9c139767d
MD5 c543e814ff518ceecbc82bb85bb6e151
BLAKE2b-256 8555b458b64e19751f938591dccd086912fed799c1d8b0f3fc90de696349a257

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7b1133e6344c90d565b2e726f78c04f5d7d34f2fb1f8ea876a847a04e8073a76
MD5 cc9041a05f8fafa9d253cecaf1d20d87
BLAKE2b-256 5c0d80368741585d12e90bdea3ac2ec191c640478d9a5fd542ed8d28a76d7756

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp313-cp313-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fe379db9294af4cd658d1091c2403bef5880c25681567eabf244e63e84e48053
MD5 4038cca23141008cdb9e05513980dfe3
BLAKE2b-256 7b9ab7b47cb49eedaadb7d732fb8712a8fdfa1c3f39098c8a599bd6aa5106858

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp313-cp313-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 a8d26df43977006d5c1cfd28e54d62555769cf562f5a53f8af19c0dc3b82e7ce
MD5 5b732e2f02e6fccb0bd30ce765357d10
BLAKE2b-256 b89d2104acb5c5da374e0b7aff0550b052c89cc266557534f963fa6089161360

See more details on using hashes here.

File details

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

File metadata

  • Download URL: finlab-2.0.4-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.12

File hashes

Hashes for finlab-2.0.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9d31fcc5c18c39bb5f6101d501b6bc45bd1551ba44b1129a717524b84b54282e
MD5 77fdaa0a7bbd4ceba9142f0c47dab6b8
BLAKE2b-256 7b4bd90fcdea9d056cc0211110f5a1d02b1bd63672ddc9cb97b5d00fcf68ef20

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 07fcb44756e171ec471f5dab57750245b0cdefce072f5e376285d828eefe707a
MD5 f4622de58f1689e9f50c63c35b2ae2d7
BLAKE2b-256 bf716ea7646510d90e36612f075b1149c9d009b7403bfda4edca87045d499a93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 96f9630cf3633428ea193df1c22d0ba0cb6d7ea60f72fa5a31bfe8d466609d9c
MD5 b9bf4e534267db83dfe9383b15869822
BLAKE2b-256 c1488d1afef8942ed7fc08a8fa85378342b50462e4b0f460e35e98e8a9718708

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp312-cp312-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 7de23c6f6c765d8781ac9225ea245040df9ea2f8a26481472067742b5a984a50
MD5 cb197f44b3eb70cd9e39f2b89b1385fb
BLAKE2b-256 441fbd7ac1685727fd610c665882ebd7a6f3bead549f67ad5cffc83bc1a3a546

See more details on using hashes here.

File details

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

File metadata

  • Download URL: finlab-2.0.4-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.12

File hashes

Hashes for finlab-2.0.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 285c9542592a6a932703ddb0832dd773b001bc3446e976af390ed752a973f7b8
MD5 e459aff47fb2a36c64c061e8b22d4c16
BLAKE2b-256 057986934d3160adb6092c311d41de5a121d89d84c7bde71a3c3b42382ecdf6e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a476102f50e28706d6cb81630abe64cc4e254d3ed22b82dcd4e526f378aaa530
MD5 6fef863fc7d7209a9267e53dca10da05
BLAKE2b-256 39900bd50c1d1b593b7fb705bdb206267c4383801f271356d6137e20ecae57c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 934d14b3339cd1bad436bf3b9cca6dc7f07653ac42f7a0de005e4dff6781d86c
MD5 5b4dd00d9a533049d553ef05a1a546ba
BLAKE2b-256 d085e8523ad7c4841efe13b18ef6be85e3dee8f75ba46efe9867f0be13d43808

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp311-cp311-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 2805871e487004730fdd71da9fc71c3a2cca97a0e656e274aea84c690005af4b
MD5 d54fa1c31cda182e39cc5d40f6f99b2e
BLAKE2b-256 29ace9875696da67604db24ea1e242e49a40735aca5b321e0fdc8e01cbe5de4f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: finlab-2.0.4-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.12

File hashes

Hashes for finlab-2.0.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 e906ab9c16e92bdb6b7059267b14cee1ca4766ca6e1840b65835d7d2a219b3d5
MD5 f726910eae6c50e3e66cc7ce46515218
BLAKE2b-256 09cb064778829c6b518d0613604cd68fd2d05144f8853fe7ccdc82d9fd817a37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d6083558cb14a7955a0e4ac251e1ca4e982c46dd91d42c23eb68b86c08681da1
MD5 41bd102f09be0b1f083b9c2f4fe42808
BLAKE2b-256 09b19f7b5563f1bbefdfdfe7c329049556eb8081e9b8c997a0eb8652ac82b564

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7f4e372b6c72a75d9e83f40d6a7454097c6b0d075b829612c233548b32a7874f
MD5 3e7b5e1198e5e9d4f5f7c9339702c812
BLAKE2b-256 6d9a499b5f8573df351b991fd8ba0ba7470971dd83e8f4c83694c9262a8d827c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlab-2.0.4-cp310-cp310-macosx_10_15_universal2.whl
Algorithm Hash digest
SHA256 6d6320f90fd663780bad158bbabd2c2c3e34710583b6477fc9353448c69e1768
MD5 6009a06b7978dad6061ab0f5aee48d27
BLAKE2b-256 bf301ad4d317cf70cf79f2cbdd61a68aa51664302d5a35574df57d5bb99d75ff

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