Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the MTMD model on Alpha360 #1728

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Empty file added .Rhistory
Empty file.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -13,6 +13,7 @@ Recent released features
| -- | ------ |
| KRNN and Sandwich models | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/1414/) on May 26, 2023 |
| Release Qlib v0.9.0 | :octocat: [Released](https://github.com/microsoft/qlib/releases/tag/v0.9.0) on Dec 9, 2022 |
| MTMD models | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/1728) on Dec 7, 2022 |
| RL Learning Framework | :hammer: :chart_with_upwards_trend: Released on Nov 10, 2022. [#1332](https://github.com/microsoft/qlib/pull/1332), [#1322](https://github.com/microsoft/qlib/pull/1322), [#1316](https://github.com/microsoft/qlib/pull/1316),[#1299](https://github.com/microsoft/qlib/pull/1299),[#1263](https://github.com/microsoft/qlib/pull/1263), [#1244](https://github.com/microsoft/qlib/pull/1244), [#1169](https://github.com/microsoft/qlib/pull/1169), [#1125](https://github.com/microsoft/qlib/pull/1125), [#1076](https://github.com/microsoft/qlib/pull/1076)|
| HIST and IGMTF models | :chart_with_upwards_trend: [Released](https://github.com/microsoft/qlib/pull/1040) on Apr 10, 2022 |
| Qlib [notebook tutorial](https://github.com/microsoft/qlib/tree/main/examples/tutorial) | 📖 [Released](https://github.com/microsoft/qlib/pull/1037) on Apr 7, 2022 |
Expand Down Expand Up @@ -355,6 +356,7 @@ Here is a list of models built on `Qlib`.
- [ADD based on pytorch (Hongshun Tang, et al.2020)](examples/benchmarks/ADD/)
- [IGMTF based on pytorch (Wentao Xu, et al.2021)](examples/benchmarks/IGMTF/)
- [HIST based on pytorch (Wentao Xu, et al.2021)](examples/benchmarks/HIST/)
- [MTMD based on pytorch (Mingjie Wang, et al.2021)](examples/benchmarks/MTMD/)
- [KRNN based on pytorch](examples/benchmarks/KRNN/)
- [Sandwich based on pytorch](examples/benchmarks/Sandwich/)

Expand Down
Binary file added examples/.DS_Store
Binary file not shown.
Binary file added examples/benchmarks/.DS_Store
Binary file not shown.
Binary file added examples/benchmarks/HIST/.DS_Store
Binary file not shown.
Binary file added examples/benchmarks/MTMD/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/benchmarks/MTMD/README.md
@@ -0,0 +1,3 @@
# MTMD
* Code: [https://github.com/MingjieWang0606/MTMD-Public/tree/main](https://github.com/MingjieWang0606/MTMD-Public/tree/main)
* Paper: "[MTMD: Multi-Scale Temporal Memory Learning and Efficient Debiasing Framework for Stock Trend Forecasting](https://arxiv.org/abs/2212.08656)".
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions examples/benchmarks/MTMD/requirements.txt
@@ -0,0 +1,6 @@
numpy==1.22.0
pandas==1.2.3
scipy==1.6.1
torch==1.8.0
scikit_learn==0.24.1
tqdm==4.61.1
90 changes: 90 additions & 0 deletions examples/benchmarks/MTMD/workflow_config_mtmd_Alpha360.yaml
@@ -0,0 +1,90 @@
qlib_init:
provider_uri: "~/.qlib/qlib_data/cn_data"
region: cn
market: &market csi300
benchmark: &benchmark SH000300
data_handler_config: &data_handler_config
start_time: 2008-01-01
end_time: 2020-08-01
fit_start_time: 2008-01-01
fit_end_time: 2014-12-31
instruments: *market
infer_processors:
- class: RobustZScoreNorm
kwargs:
fields_group: feature
clip_outlier: true
- class: Fillna
kwargs:
fields_group: feature
learn_processors:
- class: DropnaLabel
- class: CSRankNorm
kwargs:
fields_group: label
label: ["Ref($close, -2) / Ref($close, -1) - 1"]
port_analysis_config: &port_analysis_config
strategy:
class: TopkDropoutStrategy
module_path: qlib.contrib.strategy
kwargs:
signal: <PRED>
topk: 50
n_drop: 5
backtest:
start_time: 2017-01-01
end_time: 2020-08-01
account: 100000000
benchmark: *benchmark
exchange_kwargs:
limit_threshold: 0.095
deal_price: close
open_cost: 0.0005
close_cost: 0.0015
min_cost: 5
task:
model:
class: MTMD
module_path: qlib.contrib.model.pytorch_mtmd
kwargs:
d_feat: 6
hidden_size: 64
num_layers: 2
dropout: 0
n_epochs: 200
lr: 1e-4
early_stop: 20
metric: ic
loss: mse
base_model: LSTM #GRU
model_path: "benchmarks/LSTM/model_lstm_csi300.pkl" #"benchmarks/GRU/model_gru_csi300.pkl"
stock2concept: "benchmarks/MTMD/qlib_csi300_stock2concept.npy"
stock_index: "benchmarks/MTMD/qlib_csi300_stock_index.npy"
GPU: 0
dataset:
class: DatasetH
module_path: qlib.data.dataset
kwargs:
handler:
class: Alpha360
module_path: qlib.contrib.data.handler
kwargs: *data_handler_config
segments:
train: [2008-01-01, 2014-12-31]
valid: [2015-01-01, 2016-12-31]
test: [2017-01-01, 2020-08-01]
record:
- class: SignalRecord
module_path: qlib.workflow.record_temp
kwargs:
model: <MODEL>
dataset: <DATASET>
- class: SigAnaRecord
module_path: qlib.workflow.record_temp
kwargs:
ana_long_short: False
ann_scaler: 252
- class: PortAnaRecord
module_path: qlib.workflow.record_temp
kwargs:
config: *port_analysis_config
1 change: 1 addition & 0 deletions examples/benchmarks/README.md
Expand Up @@ -70,6 +70,7 @@ The numbers shown below demonstrate the performance of the entire `workflow` of
| HIST(Wentao Xu, et al.) | Alpha360 | 0.0522±0.00 | 0.3530±0.01 | 0.0667±0.00 | 0.4576±0.01 | 0.0987±0.02 | 1.3726±0.27 | -0.0681±0.01 |
| KRNN | Alpha360 | 0.0173±0.01 | 0.1210±0.06 | 0.0270±0.01 | 0.2018±0.04 | -0.0465±0.05 | -0.5415±0.62 | -0.2919±0.13 |
| Sandwich | Alpha360 | 0.0258±0.00 | 0.1924±0.04 | 0.0337±0.00 | 0.2624±0.03 | 0.0005±0.03 | 0.0001±0.33 | -0.1752±0.05 |
| MTMD(Mingjie Wang, et al.) | Alpha360 | 0.0538±0.00 | 0.3849±0.01 | 0.0672±0.00 | 0.4656±0.01 | 0.1022±0.02 | 1.4031±0.26 | -0.0664±0.01 |


- The selected 20 features are based on the feature importance of a lightgbm-based model.
Expand Down
Binary file added qlib/.DS_Store
Binary file not shown.
Binary file added qlib/contrib/.DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion qlib/contrib/model/__init__.py
Expand Up @@ -34,8 +34,9 @@
from .pytorch_sfm import SFM_Model
from .pytorch_tcn import TCN
from .pytorch_add import ADD
from .pytorch_mtmd import MTMD

pytorch_classes = (ALSTM, GATs, GRU, LSTM, DNNModelPytorch, TabnetModel, SFM_Model, TCN, ADD)
pytorch_classes = (ALSTM, GATs, GRU, LSTM, DNNModelPytorch, TabnetModel, SFM_Model, TCN, ADD, MTMD)
except ModuleNotFoundError:
pytorch_classes = ()
print("ModuleNotFoundError. PyTorch models are skipped (optional: maybe installing pytorch can fix it).")
Expand Down