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.13-cp312-cp312-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6044ce308a7745dac8f06d006b730cfb21e9a6dd89321341fdd38aed3204392e |
|
MD5 | bbc5cb5106e6c44501cbca7375e2362a |
|
BLAKE2b-256 | eba450c5c7586d9b1dae305fe840bffff1900f911dee50e29b496712027f74ad |
Close
Hashes for finlab-1.2.13-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 311e68ea774dc1a37462c036e4a0758d944338ddcc71659257ec0443709d7d37 |
|
MD5 | c93ecb0326a46c888b56794626dbd2a1 |
|
BLAKE2b-256 | fb17f44dcb00c99f58ba3b9541cc78a4ee93095469a7636307b905c027e16198 |
Close
Hashes for finlab-1.2.13-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3b9862a84a0abf80893d496e518fb8b2a646649360bc1fccb4c46072b4ec953 |
|
MD5 | adfd5c99faa96c2252fad554aa7e3318 |
|
BLAKE2b-256 | cdef0f1afa2d1a9b7bfbc594f5171bf988a3ee905f387cd613f6d1c8fb602afc |
Close
Hashes for finlab-1.2.13-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b875eaa198495f62c38208f48f4841ccd0e3b34f374eb428006f448c556d7b9 |
|
MD5 | 112a4fb609d3f6fae2dd341581606a98 |
|
BLAKE2b-256 | 1e33355373270b8d96967bca2d4fb81a523092150d6dbf6ded0a069d09ba59f2 |
Close
Hashes for finlab-1.2.13-cp312-cp312-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8775b2cf3462930184ee7a7ec9e7733906066cc8ddacfe9e649a3b976c918558 |
|
MD5 | c05d75900d2605d0592418e294d60156 |
|
BLAKE2b-256 | 709668d1ea3e100a85a7398564594d0c019660d599fad4fbe7a532f2680f747d |
Close
Hashes for finlab-1.2.13-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7311fa91d81f16821d816f4f47b90366d96c19133f0ae914c0d6598d889568db |
|
MD5 | b4f43161b18544816c0b8e89b4f4762a |
|
BLAKE2b-256 | cac51a0831d95280af4c4f9c1b7b654d4b1ee429eb48681993625606b50cbeee |
Close
Hashes for finlab-1.2.13-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a74cd8c5f331e4fd6449ea2f587dec03552cd94502bf338276c41dcde492ceca |
|
MD5 | 3e5d079d6cde54de85906bfd31524035 |
|
BLAKE2b-256 | 31881f28b13ea3239385f00114c79154e09202e379763a2bc8e5f0f87e29cc24 |
Close
Hashes for finlab-1.2.13-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ccb6507c195dd49041d4049b9cbade0f174b15137d27488d4a3c5cf3e9dabc18 |
|
MD5 | 203253c1fa39056eb8b81e72e70710cf |
|
BLAKE2b-256 | 5b35d899d34191b949576b816da75064bca343b82a1f71184ed8a407486d2dd0 |
Close
Hashes for finlab-1.2.13-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b3214e302d9b0510f80a80b88f522db76169086fd9e4fa3582269363df7aeb8 |
|
MD5 | 0ccfb8debbf0ca8138a42a916c349bd6 |
|
BLAKE2b-256 | 06ec5a7b302a09f79ec3db23805453d66ec2831efe48b636447edc46a623ddee |
Close
Hashes for finlab-1.2.13-cp311-cp311-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79aeb29127aa9873b5b8c19abf0def7105d3cdd34a66178539e1b1bfa96047b7 |
|
MD5 | dfc829bf4d6fbd4fc52bbef4a4fc8d85 |
|
BLAKE2b-256 | 11088f4dab18635d44b8688f259d549f532c246d19cc66d01cc3245b1b301091 |
Close
Hashes for finlab-1.2.13-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d90f3f6b5fa1a559a8bb482feb4fc302e5ac29490f92800ef3fb24b1c1a5ee4 |
|
MD5 | 3ebe5bc8558d809555bfbf78acd8f477 |
|
BLAKE2b-256 | 92804ffc8f5de1bbbe74a9dce9b039c1cb46832229822360fcb4c31996b1c80a |
Close
Hashes for finlab-1.2.13-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbddcd2b7d86ba90a7b235146ec202710259f4632346db1efe49e05f1d2ad176 |
|
MD5 | e686edee81effa29fb01a33ff2572146 |
|
BLAKE2b-256 | 854c135559c295028b66a6c34119ef43a63e94b572c9ef9ca8b69b0304a9d13b |
Close
Hashes for finlab-1.2.13-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bc1304bf33f619a3eb7e4aa61e60358a2480e63d24f23e7ac6d11f2358be359 |
|
MD5 | 55f2ba5dd5ad87f644675c70d0e9e2ec |
|
BLAKE2b-256 | c39f11daa93053e406c3579882c1370d9ec54c3b9735ed00766fc2e4f21f1fff |
Close
Hashes for finlab-1.2.13-cp310-cp310-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cda36d60cf0a1b45c9b274f74c526b5e1685189ba7905db1aa2348450b65c07f |
|
MD5 | 5a145419540b580423b296fda303695d |
|
BLAKE2b-256 | ff3800e90726f4c669e0186c1b7b1ad830862d87adecb6400033bfdda8c3bf7c |
Close
Hashes for finlab-1.2.13-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a22c832b168eee0926b814351e598be8671f4b85ad783b9a4f0aad8232c5eb1 |
|
MD5 | cc796e48d77ca558014071adde87bd2e |
|
BLAKE2b-256 | 2d175b306bfec6b109a72f58466f19dca10ade28ae91940d4f4e8204132d3a61 |
Close
Hashes for finlab-1.2.13-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3365e522919d1b2276af6b4e35f1b8ab2e3e3ab1eb1a5de869b4fcb7aa746888 |
|
MD5 | b42ce4a67a8d35341bca43ff8e155f41 |
|
BLAKE2b-256 | 2520a1bd482ea5ad50af413e9ead4fbb69676ab1f7fe249219985829fb28f76c |
Close
Hashes for finlab-1.2.13-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 815d5db03a4e287834aed52d2221439a5a7c76215d51ed392b5cb31a8c8c2562 |
|
MD5 | 4d56d51ba8244e6797c4207cea573a0d |
|
BLAKE2b-256 | c61d6dc906118516ae4dfe7b05377b3df56074a91cae2c7215345d5794a5b3e5 |
Close
Hashes for finlab-1.2.13-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9b97c4e4af3022037aa60898b495c3a55146f1a1083b6f3e9f5c51eecbe690c |
|
MD5 | 9b7e757235a6b09bfe9cd369672cd20c |
|
BLAKE2b-256 | fc08dadeb3d42993ba340cc2b980b51ad4e3a87fd36acc8194ff31aa8ce64f26 |
Close
Hashes for finlab-1.2.13-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2032c8838c627d1fbf038b5ade86b433e8ce41b4157ac56817b55eb9b6116782 |
|
MD5 | 34c4f86a2e9498ce4572ff09a82d35be |
|
BLAKE2b-256 | a365873c78f8c12d037d96c3de1b06690df37a3d2bb5810bbcfb4490be56fb39 |
Close
Hashes for finlab-1.2.13-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f7bddc2e8ababf024f47ab1c145fe44ed1ca0ac1bb411f1b1ae2cb2b119fad7 |
|
MD5 | c826957ea2a7fcef3db9c93b9f2e4e3c |
|
BLAKE2b-256 | 415b8bc5d3427c6692a8c47131311c085ee79387a30e1613eda3327078af4cca |
Close
Hashes for finlab-1.2.13-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8393f94dd8f69b0d7618f89982a8cddb4e427505143d54552404db190ea9749c |
|
MD5 | a24d7bb430a3ea5f8e5b5e2ba4ca3a9e |
|
BLAKE2b-256 | 8227770e6797280679d170de98464ea15381f135e77923de7201f9721d9e48f9 |
Close
Hashes for finlab-1.2.13-cp38-cp38-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be8b78b2578796d0479dc61e5f3b1a906a15a44d5b0f936d9106db2a75152705 |
|
MD5 | 3b4986f85d45a53d56ffa98ac274f48e |
|
BLAKE2b-256 | 5c8d764db248fd69a1d9af75b8b43b4d76276578e48be1da79b1ac95935c11e1 |
Close
Hashes for finlab-1.2.13-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | edc40c12aab6c91ef01bacde0a81c0132645246ac1273a37d405958330b131ff |
|
MD5 | f58fcdd72872910988271e52fb47f438 |
|
BLAKE2b-256 | 3356c29d8123dc883b9ac8e389cef39ab4ec29173fb2e0a09f0d7918f2fc5297 |
Close
Hashes for finlab-1.2.13-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22c4e1b65662f606cc59fbbe7412a1128328f2d07f46f84a7699853ad1b6722f |
|
MD5 | fcb2880555255925a5da74946ee29059 |
|
BLAKE2b-256 | 6efdacb6a02f1c10f588566131f495d017f97b06ac9471a3a833e4b82d532eb8 |
Close
Hashes for finlab-1.2.13-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b9e02bb76d20874318ad41373ef19ea38acdbdd84091e4b7206eda4a2b23ec9 |
|
MD5 | 06f736bd2749f3b67072c01def5c10c6 |
|
BLAKE2b-256 | 2d788b955d23b109406ed871472e89937d1d7a7db593f1f873323377c4b5e8e5 |
Close
Hashes for finlab-1.2.13-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc43783a0bf6d268b08c57a56eb9231f04dd0184b297122d66beb0ffa31c4540 |
|
MD5 | 66d619e25a28f6c58e38d974e3ed04ad |
|
BLAKE2b-256 | 2bfddb67cb008d1a911d7dec6b3654a9851a8a2e77474e4901cb1c00c286f5b0 |
Close
Hashes for finlab-1.2.13-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 056a1025200af5ad898898701da6a172ec10f9d3e56ae9da85c6b909e4ca7895 |
|
MD5 | 91b7f089b938bf136c8703562e2f571d |
|
BLAKE2b-256 | 35a41678ac3d66c62808b5937e9fffb745d76cb3ca72674171424f7dbebd88e9 |
Close
Hashes for finlab-1.2.13-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86cad358cb5683566eca9413e05e95c721c7152ea0c54f16b1372e012ad29c80 |
|
MD5 | c5d88174e68c26cc049c39e9d6d105ae |
|
BLAKE2b-256 | a3fdabd8e0ee132a3a5c44c5d5cbff4f9d437685884eaa63cf01bc0e4b1ce2dc |
Close
Hashes for finlab-1.2.13-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1af6f97dbefd45c17da67d5d50e2ad275f666fad1f26cdbc4cef6d61a17f2b11 |
|
MD5 | b66396d8ca14a6c709ebf2fd128625f5 |
|
BLAKE2b-256 | c2eda599267ae9f9fe93775c08f8c58f1a2c2f29019b000d764e01a05ea898ee |
Close
Hashes for finlab-1.2.13-cp36-cp36m-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dde74ffc87c6e7033ad00985d53968c3707e502da8824b3498ac7a2ac61a2ae6 |
|
MD5 | 698d2dc5f2f6f2ab42250d4bbf805d6b |
|
BLAKE2b-256 | 8160dc6f85e4421a62f02103f859adf481e07ba39554411b2f0563af6cdde19e |