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()
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
Close
Hashes for finlab-1.2.4-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52673e981185de2404848c720206265efcf3227c291ee637c53e522b597c9f8b |
|
MD5 | b195fff2a5e7e60109253bfd91d3d244 |
|
BLAKE2b-256 | 1b284c46299592b71efbaa90622511b8c4d00db111461d3c2d8a37bc357208fd |
Close
Hashes for finlab-1.2.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b661ad4374c4ca1ad12a848fb8c053a2ba979fe86b5bf252e065cea61f70ff9 |
|
MD5 | 873ab4d6245bd5e8ff69683424e296d2 |
|
BLAKE2b-256 | bd1cafc0b34352b0ca8380c8ce359803540a2dc6bfb5de614b39cf10d4334b80 |
Close
Hashes for finlab-1.2.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b75f562942694e02eecb8028a25eaf8ac6c394eab142c51141c54bc1aa8b164 |
|
MD5 | 6677ce66d276a45f9b9975f85244b296 |
|
BLAKE2b-256 | 52799d5fa3fe95eff6ef64295c5e31524b8e99353a8113ed58b6cf2486936a80 |
Close
Hashes for finlab-1.2.4-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1a8c5f98a89037d9187eabcd7b85d621469d8bf0a82a387a089eee083303603 |
|
MD5 | 181dbeff9a264c970df82ef1b99b5f7d |
|
BLAKE2b-256 | 95ac4b1ea83ae77687156082136ca5a53ba602e1d5c7408a3c404303cbf91bc6 |
Close
Hashes for finlab-1.2.4-cp312-cp312-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cc5bd1defee971463b79b5b5099f25983f77e4f4d0ae5bea206f5b521eb8a71 |
|
MD5 | ed3374f867790f9e132058873ed1cfe0 |
|
BLAKE2b-256 | c6204b50a14945de983206c56f0843048d57792caa68c30e4e18debc9e2df063 |
Close
Hashes for finlab-1.2.4-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24b8a08ebd0edf0609f09a82ea03bb2cefe8b06472b6881316d3aa6821c8f1ba |
|
MD5 | 49e99929978ceeb8c10fcf5a24958c87 |
|
BLAKE2b-256 | ffad7c27ff11f248364c67dcf302cb2a3a266e6e7649193cb666962f4e882b3d |
Close
Hashes for finlab-1.2.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6f339c64dc3e4b06468d77ad0089fc965a2cfa40733ff5357f85df9394d84ff |
|
MD5 | 0d63c16670edc9e57eb044e25fbd42e2 |
|
BLAKE2b-256 | c2758262e9986823009e8fcc5123ce6d0d3238e3d829e40a78c632c2a1d76b1d |
Close
Hashes for finlab-1.2.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e207c40db73c2221e691ce81d2aba2e98db5d6a8d7661af88b45c7c57e864eee |
|
MD5 | 2bd073dea66f01bd2846072abc687153 |
|
BLAKE2b-256 | 4a01ef6ea970d406ed2491a5b912eb131cf6fb3f387283d16e8cbb456c7e333c |
Close
Hashes for finlab-1.2.4-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b05b2b438e7ca370cdd2bd3675552528bdafa5363bedb7843d8cc8cc75ec4f9 |
|
MD5 | 381d9bab1f57fdc1b36a2120595159b4 |
|
BLAKE2b-256 | c4ea33ea8caee0272208b966dae6d47d3d423c3ff0c23594fd6d84e634129c65 |
Close
Hashes for finlab-1.2.4-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f7dd3e9d735d44050af76df55ca0f861c1af406045756705dfda325a4675fba |
|
MD5 | d01430e6041912e934ed7f056f989c38 |
|
BLAKE2b-256 | a045c1dcde3ac4b0dd396f823921e878d3f215c84d2b58d6a48935f974bf4088 |
Close
Hashes for finlab-1.2.4-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e70d78a1eb22e0bd1ed82a4719fb8e66bb87edb20408e055b0f9bd449ac74817 |
|
MD5 | 633584b1d3e0ad91113319a5e8445be9 |
|
BLAKE2b-256 | 85c9cacdfb69d6e11c6d5e782b5ec972079b7b60fc808fcd40081654a0fb04c2 |
Close
Hashes for finlab-1.2.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 673cd3c74c8ccff964e187d46aff0e1a352ae44f23ae76cbd603c474a6b36266 |
|
MD5 | 960b04de3ff65be6d99278216b0eeed6 |
|
BLAKE2b-256 | 937fb01ea5bee09882633b74aa02a2c2d31563f555d338ae783b4ba5fe8ec302 |
Close
Hashes for finlab-1.2.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac1ccce97c25b5009f0203f20b09fb8d0187a199e4b95179e469585a611dbd78 |
|
MD5 | 4f725c1747bacc38539a8e619097bb52 |
|
BLAKE2b-256 | 2dff33ffb34d46c370583ef4f0fa17e2d84d0b512a1a1cc327345b560dbbc259 |
Close
Hashes for finlab-1.2.4-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7103e4b5883f6ee5594202551f784db031d348411ad242ef821402b0625e00a5 |
|
MD5 | 2dc9e4a8a98540914a01cbecb91a2584 |
|
BLAKE2b-256 | 9e0d953cece9ee2b72188675cac85e20546f640f2565c6c3e93da27ce50a338d |
Close
Hashes for finlab-1.2.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | da040b514bf1153f3322bf779e0db68b8faf61a132ea32257d7b4320ffd3fd1d |
|
MD5 | fde5283e8157658b1de7b7ec58536841 |
|
BLAKE2b-256 | c7723f75f885587d7c6f53cccbce1e36a84565280c10df02d87d1fd3ce9da615 |
Close
Hashes for finlab-1.2.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d306926ffa3ad316fe0d971c51636f68982e6b5782192c0c59fd12057313ad74 |
|
MD5 | 141d59b7b1520fa6d59c7bb8f74097a3 |
|
BLAKE2b-256 | 4fde481a6be6aa2d6ad7848295738dbcf09eaa69caf616f1b57bf417a482e268 |
Close
Hashes for finlab-1.2.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9c9ae5d0371a235d0cd9e2a0ab93488937b59f75d718c32c3891c8bef606ee7a |
|
MD5 | 1de158bce66dbe02ecb86454ba2432ae |
|
BLAKE2b-256 | 6ef1974c91de562fd8d34c85cb4c404072552f1a2ce5853481120d59f6b6fd0b |
Close
Hashes for finlab-1.2.4-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b896796dde4bcb02c60bfa6eb829d0900921226b97b13604ad7298714e51b14b |
|
MD5 | 9c83730c2c01d60617f6408503517b62 |
|
BLAKE2b-256 | 703d39db430270d91c036936e01d2ec595495d7e3358e01e84a4a5122ba8f3db |
Close
Hashes for finlab-1.2.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5051285e205d9b47712c93165ee89b0a43dc59a034d1dba1d1b3521b3c211df |
|
MD5 | d0032fb869f2a8e065d98cdfd265ca14 |
|
BLAKE2b-256 | 5843eda59df6d48e5fbf144c70aacc33261f599bddb3b5cef3a002d114735741 |
Close
Hashes for finlab-1.2.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5443b313d6ee0c251af9d8e43616d01fa560bd4bacbd5eb160b0580013e55574 |
|
MD5 | 429c4207243aa1626ad4512f014f2a45 |
|
BLAKE2b-256 | 7e95e0d6cea271a55dce143a38fc7f8321936d20f3fdf215fc85fa6cc8441b51 |
Close
Hashes for finlab-1.2.4-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d0839c394604cdfe2737a5ca6d5bd7ee732b115666fb5867364bbf49918fe65 |
|
MD5 | fda2e511fc5c557d64fe924a4f6b3c7b |
|
BLAKE2b-256 | 3c5f7085c0a886e4cd4087f2f16e92f4327ecf51356493e7166152894e6f55b0 |
Close
Hashes for finlab-1.2.4-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfd227fac3696b1720b4cee3c27abd54a00fd73ef5f52fda3cea621d11e6dc90 |
|
MD5 | d5d755fe423b19e762d7a031f6f31a3d |
|
BLAKE2b-256 | 931706756ad0071b9d66e44b35ba0fa09448fc42f6a6c1c2368292f1dae72d52 |
Close
Hashes for finlab-1.2.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de0f5828f0ab3875b627c4e4fbb1ef2be10a68703f76116f79f8f72d5d7e815c |
|
MD5 | 85838780fe147bd55df0db4e2b8c8d1d |
|
BLAKE2b-256 | a882492b2ea6c5ba54d599227f53cfdebb5198df70de44021df9a3f4f87a27f9 |
Close
Hashes for finlab-1.2.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdbe12b2f622f8c62eb6b6abf3089505a903b2584d75a02939fc88de05137d3e |
|
MD5 | de37a55642e192510363acb056e56508 |
|
BLAKE2b-256 | c8206a7e0206927d252a3051fdb267c2667b0d6be33dba9233ebd5be5d21367a |
Close
Hashes for finlab-1.2.4-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72e131c6b3ef071a0e2f414ff4742cd1bf58a20e7c5841f34b481a4c33b32964 |
|
MD5 | 356ecd2fe22296f196f5a139bc60919e |
|
BLAKE2b-256 | 22db6236a070ea67d62283c80dc89e649995f397f0362740bb3960e22342a537 |
Close
Hashes for finlab-1.2.4-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 886126b33a5ec648eb4b720927dd0bf7643fd0c5842b47b45bccd1110ab6c590 |
|
MD5 | bd092be0889a09f730680663b3d5df81 |
|
BLAKE2b-256 | d0df663de232a620b518e923105a2ee754289c3916e9d21cc37e6dd4c2f977d3 |
Close
Hashes for finlab-1.2.4-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d48bdca02a6a182998379db82d632c7e6d596302c0730924ea46842a3300fdd |
|
MD5 | be0c56d36f4b29962417f0df36fcd002 |
|
BLAKE2b-256 | dc4bf72a0a7dcf125be8473042d7139c2559f8d44ada6f463ff2ba6c9b1b92c6 |
Close
Hashes for finlab-1.2.4-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ab9ea1f380461ec4a892b4f4d74e8edf8044a44bc97de35425a670af6522b95 |
|
MD5 | 48de77a8c7710e38b168c494caef302b |
|
BLAKE2b-256 | c90b0f94ebae737671536a3da2ed78f147b3a0e884d5111b178d465fc9653b0d |
Close
Hashes for finlab-1.2.4-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 505e4c9f1a39a8fb30a18163e0a12aa5e145f22fa37c7895faf40db233d50344 |
|
MD5 | a1404b5bfbda5c23cc419f5430aad5d3 |
|
BLAKE2b-256 | 1e2b2a8521d45655f0fa5f9d77f45599dda5fcaa9e0b907241daba035da395f2 |
Close
Hashes for finlab-1.2.4-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 508c2c7d2385168c64a9ad67dbf6f3ac4b277fc95656d08c1baaf8bd9eb59afc |
|
MD5 | ae856feffc4529a56df375eb409c8d1d |
|
BLAKE2b-256 | f7ff898248dba6ae677775bf1049833349eeb35487b8abb8ac7ae53649783572 |