mirror of
https://github.com/microsoft/qlib.git
synced 2026-06-06 05:51:17 +08:00
fix(security): use RestrictedUnpickler in load_instance (#2153)
* fix(security): enforce RestrictedUnpickler for load_instance to prevent unsafe pickle deserialization * fix: lint error
This commit is contained in:
3
.github/workflows/test_qlib_from_source.yml
vendored
3
.github/workflows/test_qlib_from_source.yml
vendored
@@ -76,8 +76,11 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
make mypy
|
make mypy
|
||||||
|
|
||||||
|
# Due to issues that cannot be automatically fixed when running `nbqa black . -l 120 --check --diff` on Jupyter notebooks,
|
||||||
|
# we reverted to a version of `black` earlier than 26.1.0 before performing the checks.
|
||||||
- name: Check Qlib ipynb with nbqa
|
- name: Check Qlib ipynb with nbqa
|
||||||
run: |
|
run: |
|
||||||
|
python -m pip install "black<26.1"
|
||||||
make nbqa
|
make nbqa
|
||||||
|
|
||||||
- name: Test data downloads
|
- name: Test data downloads
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import sys
|
|||||||
|
|
||||||
from importlib.metadata import version as ver
|
from importlib.metadata import version as ver
|
||||||
|
|
||||||
|
|
||||||
# -- General configuration ------------------------------------------------
|
# -- General configuration ------------------------------------------------
|
||||||
|
|
||||||
# If your documentation needs a minimal Sphinx version, state it here.
|
# If your documentation needs a minimal Sphinx version, state it here.
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ from qlib.model.base import ModelFT
|
|||||||
from qlib.data.dataset import DatasetH
|
from qlib.data.dataset import DatasetH
|
||||||
from qlib.data.dataset.handler import DataHandlerLP
|
from qlib.data.dataset.handler import DataHandlerLP
|
||||||
|
|
||||||
|
|
||||||
# To register new datasets, please add them here.
|
# To register new datasets, please add them here.
|
||||||
ALLOW_DATASET = ["Alpha158", "Alpha360"]
|
ALLOW_DATASET = ["Alpha158", "Alpha360"]
|
||||||
# To register new datasets, please add their configurations here.
|
# To register new datasets, please add their configurations here.
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import pandas as pd
|
|||||||
|
|
||||||
from qlib.data.dataset import DatasetH
|
from qlib.data.dataset import DatasetH
|
||||||
|
|
||||||
|
|
||||||
device = "cuda" if torch.cuda.is_available() else "cpu"
|
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import pickle
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
import seaborn as sns
|
import seaborn as sns
|
||||||
|
|
||||||
|
from qlib.utils.pickle_utils import restricted_pickle_load
|
||||||
|
|
||||||
sns.set(color_codes=True)
|
sns.set(color_codes=True)
|
||||||
plt.rcParams["font.sans-serif"] = "SimHei"
|
plt.rcParams["font.sans-serif"] = "SimHei"
|
||||||
plt.rcParams["axes.unicode_minus"] = False
|
plt.rcParams["axes.unicode_minus"] = False
|
||||||
@@ -18,7 +19,7 @@ from tqdm.auto import tqdm
|
|||||||
|
|
||||||
# +
|
# +
|
||||||
with open("./internal_data_s20.pkl", "rb") as f:
|
with open("./internal_data_s20.pkl", "rb") as f:
|
||||||
data = pickle.load(f)
|
data = restricted_pickle_load(f)
|
||||||
|
|
||||||
data.data_ic_df.columns.names = ["start_date", "end_date"]
|
data.data_ic_df.columns.names = ["start_date", "end_date"]
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ pd.DataFrame(meta_m.tn.twm.linear.weight.detach().numpy()).T[0].rolling(5).mean(
|
|||||||
|
|
||||||
# +
|
# +
|
||||||
with open("./tasks_s20.pkl", "rb") as f:
|
with open("./tasks_s20.pkl", "rb") as f:
|
||||||
tasks = pickle.load(f)
|
tasks = restricted_pickle_load(f)
|
||||||
|
|
||||||
task_df = {}
|
task_df = {}
|
||||||
for t in tasks:
|
for t in tasks:
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
import fire
|
import fire
|
||||||
|
|
||||||
import qlib
|
import qlib
|
||||||
import pickle
|
|
||||||
from qlib.constant import REG_CN
|
from qlib.constant import REG_CN
|
||||||
from qlib.config import HIGH_FREQ_CONFIG
|
from qlib.config import HIGH_FREQ_CONFIG
|
||||||
|
|
||||||
from qlib.utils import init_instance_by_config
|
from qlib.utils import init_instance_by_config
|
||||||
|
from qlib.utils.pickle_utils import restricted_pickle_load
|
||||||
from qlib.data.dataset.handler import DataHandlerLP
|
from qlib.data.dataset.handler import DataHandlerLP
|
||||||
from qlib.data.ops import Operators
|
from qlib.data.ops import Operators
|
||||||
from qlib.data.data import Cal
|
from qlib.data.data import Cal
|
||||||
@@ -125,10 +125,10 @@ class HighfreqWorkflow:
|
|||||||
del dataset, dataset_backtest
|
del dataset, dataset_backtest
|
||||||
##=============reload dataset=============
|
##=============reload dataset=============
|
||||||
with open("dataset.pkl", "rb") as file_dataset:
|
with open("dataset.pkl", "rb") as file_dataset:
|
||||||
dataset = pickle.load(file_dataset)
|
dataset = restricted_pickle_load(file_dataset)
|
||||||
|
|
||||||
with open("dataset_backtest.pkl", "rb") as file_dataset_backtest:
|
with open("dataset_backtest.pkl", "rb") as file_dataset_backtest:
|
||||||
dataset_backtest = pickle.load(file_dataset_backtest)
|
dataset_backtest = restricted_pickle_load(file_dataset_backtest)
|
||||||
|
|
||||||
self._prepare_calender_cache()
|
self._prepare_calender_cache()
|
||||||
##=============reinit dataset=============
|
##=============reinit dataset=============
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from qlib.utils import init_instance_by_config
|
|||||||
from qlib.tests.data import GetData
|
from qlib.tests.data import GetData
|
||||||
from qlib.tests.config import CSI300_GBDT_TASK
|
from qlib.tests.config import CSI300_GBDT_TASK
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# use default data
|
# use default data
|
||||||
provider_uri = "~/.qlib/qlib_data/cn_data" # target_dir
|
provider_uri = "~/.qlib/qlib_data/cn_data" # target_dir
|
||||||
|
|||||||
@@ -95,7 +95,6 @@ pos 0.000000
|
|||||||
[1706497:MainThread](2021-12-07 14:08:30,627) INFO - qlib.timer - [log.py:113] - Time cost: 0.014s | waiting `async_log` Done
|
[1706497:MainThread](2021-12-07 14:08:30,627) INFO - qlib.timer - [log.py:113] - Time cost: 0.014s | waiting `async_log` Done
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
import qlib
|
import qlib
|
||||||
import fire
|
import fire
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ There are two parts including first_train and update_online_pred.
|
|||||||
Firstly, we will finish the training and set the trained models to the `online` models.
|
Firstly, we will finish the training and set the trained models to the `online` models.
|
||||||
Next, we will finish updating online predictions.
|
Next, we will finish updating online predictions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import copy
|
import copy
|
||||||
import fire
|
import fire
|
||||||
import qlib
|
import qlib
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ NOTE:
|
|||||||
- !!!!!!!!!!!!!!!TODO!!!!!!!!!!!!!!!!!!!:
|
- !!!!!!!!!!!!!!!TODO!!!!!!!!!!!!!!!!!!!:
|
||||||
- Its structure is not well designed and very ugly, your contribution is welcome to make importing dataset easier
|
- Its structure is not well designed and very ugly, your contribution is welcome to make importing dataset easier
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from datetime import date, datetime as dt
|
from datetime import date, datetime as dt
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
import pickle
|
|
||||||
import os
|
import os
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
from qlib.utils.pickle_utils import restricted_pickle_load
|
||||||
|
|
||||||
for tag in ["test", "valid"]:
|
for tag in ["test", "valid"]:
|
||||||
files = os.listdir(os.path.join("data/orders/", tag))
|
files = os.listdir(os.path.join("data/orders/", tag))
|
||||||
dfs = []
|
dfs = []
|
||||||
for f in tqdm(files):
|
for f in tqdm(files):
|
||||||
df = pickle.load(open(os.path.join("data/orders/", tag, f), "rb"))
|
with open(os.path.join("data/orders/", tag, f), "rb") as fr:
|
||||||
|
df = restricted_pickle_load(fr)
|
||||||
df = df.drop(["$close0"], axis=1)
|
df = df.drop(["$close0"], axis=1)
|
||||||
dfs.append(df)
|
dfs.append(df)
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
|
|
||||||
import qlib
|
import qlib
|
||||||
import fire
|
import fire
|
||||||
import pickle
|
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from qlib.constant import REG_CN
|
from qlib.constant import REG_CN
|
||||||
from qlib.data.dataset.handler import DataHandlerLP
|
from qlib.data.dataset.handler import DataHandlerLP
|
||||||
from qlib.utils import init_instance_by_config
|
from qlib.utils import init_instance_by_config
|
||||||
|
from qlib.utils.pickle_utils import restricted_pickle_load
|
||||||
from qlib.tests.data import GetData
|
from qlib.tests.data import GetData
|
||||||
|
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ class RollingDataWorkflow:
|
|||||||
|
|
||||||
def _load_pre_handler(self, path):
|
def _load_pre_handler(self, path):
|
||||||
with open(path, "rb") as file_dataset:
|
with open(path, "rb") as file_dataset:
|
||||||
pre_handler = pickle.load(file_dataset)
|
pre_handler = restricted_pickle_load(file_dataset)
|
||||||
return pre_handler
|
return pre_handler
|
||||||
|
|
||||||
def rolling_process(self):
|
def rolling_process(self):
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ Qlib provides two kinds of interfaces.
|
|||||||
|
|
||||||
The interface of (1) is `qrun XXX.yaml`. The interface of (2) is script like this, which nearly does the same thing as `qrun XXX.yaml`
|
The interface of (1) is `qrun XXX.yaml`. The interface of (2) is script like this, which nearly does the same thing as `qrun XXX.yaml`
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import qlib
|
import qlib
|
||||||
from qlib.constant import REG_CN
|
from qlib.constant import REG_CN
|
||||||
from qlib.utils import init_instance_by_config, flatten_dict
|
from qlib.utils import init_instance_by_config, flatten_dict
|
||||||
@@ -15,7 +16,6 @@ from qlib.workflow.record_temp import SignalRecord, PortAnaRecord, SigAnaRecord
|
|||||||
from qlib.tests.data import GetData
|
from qlib.tests.data import GetData
|
||||||
from qlib.tests.config import CSI300_BENCH, CSI300_GBDT_TASK
|
from qlib.tests.config import CSI300_BENCH, CSI300_GBDT_TASK
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# use default data
|
# use default data
|
||||||
provider_uri = "~/.qlib/qlib_data/cn_data" # target_dir
|
provider_uri = "~/.qlib/qlib_data/cn_data" # target_dir
|
||||||
|
|||||||
@@ -69,10 +69,9 @@ rl = [
|
|||||||
"torch",
|
"torch",
|
||||||
"numpy<2.0.0",
|
"numpy<2.0.0",
|
||||||
]
|
]
|
||||||
# We exclude black version 26.1.0 due to known issues with nbqa when formatting Jupyter notebooks,
|
|
||||||
# which can cause false-positive --check results and inconsistent notebook formatting.
|
|
||||||
lint = [
|
lint = [
|
||||||
"black!=26.1.0",
|
"black",
|
||||||
"pylint",
|
"pylint",
|
||||||
"mypy<1.5.0",
|
"mypy<1.5.0",
|
||||||
"flake8",
|
"flake8",
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ from tqdm.auto import tqdm
|
|||||||
|
|
||||||
from ..utils.time import Freq
|
from ..utils.time import Freq
|
||||||
|
|
||||||
|
|
||||||
PORT_METRIC = Dict[str, Tuple[pd.DataFrame, dict]]
|
PORT_METRIC = Dict[str, Tuple[pd.DataFrame, dict]]
|
||||||
INDICATOR_METRIC = Dict[str, Tuple[pd.DataFrame, Indicator]]
|
INDICATOR_METRIC = Dict[str, Tuple[pd.DataFrame, Indicator]]
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,5 @@
|
|||||||
import fire
|
import fire
|
||||||
from qlib.tests.data import GetData
|
from qlib.tests.data import GetData
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
fire.Fire(GetData)
|
fire.Fire(GetData)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ Two modes are supported
|
|||||||
- server
|
- server
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ from qlib.utils import init_instance_by_config
|
|||||||
|
|
||||||
from qlib.data.dataset import DatasetH
|
from qlib.data.dataset import DatasetH
|
||||||
|
|
||||||
|
|
||||||
device = "cuda" if torch.cuda.is_available() else "cpu"
|
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ from ..data import D
|
|||||||
from ..config import C
|
from ..config import C
|
||||||
from ..data.dataset.utils import get_level_index
|
from ..data.dataset.utils import get_level_index
|
||||||
|
|
||||||
|
|
||||||
logger = get_module_logger("Evaluate")
|
logger = get_module_logger("Evaluate")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,5 +3,4 @@
|
|||||||
|
|
||||||
from .data_selection import MetaTaskDS, MetaDatasetDS, MetaModelDS
|
from .data_selection import MetaTaskDS, MetaDatasetDS, MetaModelDS
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["MetaTaskDS", "MetaDatasetDS", "MetaModelDS"]
|
__all__ = ["MetaTaskDS", "MetaDatasetDS", "MetaModelDS"]
|
||||||
|
|||||||
@@ -4,5 +4,4 @@
|
|||||||
from .dataset import MetaDatasetDS, MetaTaskDS
|
from .dataset import MetaDatasetDS, MetaTaskDS
|
||||||
from .model import MetaModelDS
|
from .model import MetaModelDS
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["MetaDatasetDS", "MetaTaskDS", "MetaModelDS"]
|
__all__ = ["MetaDatasetDS", "MetaTaskDS", "MetaModelDS"]
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ class TabnetModel(Model):
|
|||||||
feature = x_train_values.float().to(self.device)
|
feature = x_train_values.float().to(self.device)
|
||||||
label = y_train_values.float().to(self.device)
|
label = y_train_values.float().to(self.device)
|
||||||
priors = 1 - S_mask
|
priors = 1 - S_mask
|
||||||
(vec, sparse_loss) = self.tabnet_model(feature, priors)
|
vec, sparse_loss = self.tabnet_model(feature, priors)
|
||||||
f = self.tabnet_decoder(vec)
|
f = self.tabnet_decoder(vec)
|
||||||
loss = self.pretrain_loss_fn(label, f, S_mask)
|
loss = self.pretrain_loss_fn(label, f, S_mask)
|
||||||
|
|
||||||
@@ -348,7 +348,7 @@ class TabnetModel(Model):
|
|||||||
S_mask = S_mask.to(self.device)
|
S_mask = S_mask.to(self.device)
|
||||||
priors = 1 - S_mask
|
priors = 1 - S_mask
|
||||||
with torch.no_grad():
|
with torch.no_grad():
|
||||||
(vec, sparse_loss) = self.tabnet_model(feature, priors)
|
vec, sparse_loss = self.tabnet_model(feature, priors)
|
||||||
f = self.tabnet_decoder(vec)
|
f = self.tabnet_decoder(vec)
|
||||||
|
|
||||||
loss = self.pretrain_loss_fn(label, f, S_mask)
|
loss = self.pretrain_loss_fn(label, f, S_mask)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from ...data import D
|
|||||||
from ...config import C
|
from ...config import C
|
||||||
from ...log import get_module_logger
|
from ...log import get_module_logger
|
||||||
from ...utils import get_next_trading_date
|
from ...utils import get_next_trading_date
|
||||||
|
from ...utils.pickle_utils import restricted_pickle_load
|
||||||
from ...backtest.exchange import Exchange
|
from ...backtest.exchange import Exchange
|
||||||
|
|
||||||
log = get_module_logger("utils")
|
log = get_module_logger("utils")
|
||||||
@@ -30,7 +31,7 @@ def load_instance(file_path):
|
|||||||
if not file_path.exists():
|
if not file_path.exists():
|
||||||
raise ValueError("Cannot find file {}".format(file_path))
|
raise ValueError("Cannot find file {}".format(file_path))
|
||||||
with file_path.open("rb") as fr:
|
with file_path.open("rb") as fr:
|
||||||
instance = pickle.load(fr)
|
instance = restricted_pickle_load(fr)
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,5 +3,4 @@
|
|||||||
|
|
||||||
from .analysis_model_performance import model_performance_graph
|
from .analysis_model_performance import model_performance_graph
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["model_performance_graph"]
|
__all__ = ["model_performance_graph"]
|
||||||
|
|||||||
@@ -7,5 +7,4 @@ from .report import report_graph
|
|||||||
from .rank_label import rank_label_graph
|
from .rank_label import rank_label_graph
|
||||||
from .risk_analysis import risk_analysis_graph
|
from .risk_analysis import risk_analysis_graph
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["cumulative_return_graph", "score_ic_graph", "report_graph", "rank_label_graph", "risk_analysis_graph"]
|
__all__ = ["cumulative_return_graph", "score_ic_graph", "report_graph", "rank_label_graph", "risk_analysis_graph"]
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ Here is an example.
|
|||||||
fa.plot_all(wspace=0.3, sub_figsize=(12, 3), col_n=5)
|
fa.plot_all(wspace=0.3, sub_figsize=(12, 3), col_n=5)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
from qlib.contrib.report.data.base import FeaAnalyser
|
from qlib.contrib.report.data.base import FeaAnalyser
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ Assumptions
|
|||||||
- The analyse each feature individually
|
- The analyse each feature individually
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from qlib.log import TimeInspector
|
from qlib.log import TimeInspector
|
||||||
from qlib.contrib.report.utils import sub_fig_generator
|
from qlib.contrib.report.utils import sub_fig_generator
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ from .rule_strategy import (
|
|||||||
|
|
||||||
from .cost_control import SoftTopkStrategy
|
from .cost_control import SoftTopkStrategy
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"TopkDropoutStrategy",
|
"TopkDropoutStrategy",
|
||||||
"WeightStrategyBase",
|
"WeightStrategyBase",
|
||||||
|
|||||||
@@ -5,5 +5,4 @@ from .base import BaseOptimizer
|
|||||||
from .optimizer import PortfolioOptimizer
|
from .optimizer import PortfolioOptimizer
|
||||||
from .enhanced_indexing import EnhancedIndexingOptimizer
|
from .enhanced_indexing import EnhancedIndexingOptimizer
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["BaseOptimizer", "PortfolioOptimizer", "EnhancedIndexingOptimizer"]
|
__all__ = ["BaseOptimizer", "PortfolioOptimizer", "EnhancedIndexingOptimizer"]
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from typing import Union, Optional, Dict, Any, List
|
|||||||
from qlib.log import get_module_logger
|
from qlib.log import get_module_logger
|
||||||
from .base import BaseOptimizer
|
from .base import BaseOptimizer
|
||||||
|
|
||||||
|
|
||||||
logger = get_module_logger("EnhancedIndexingOptimizer")
|
logger = get_module_logger("EnhancedIndexingOptimizer")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"""
|
"""
|
||||||
This order generator is for strategies based on WeightStrategyBase
|
This order generator is for strategies based on WeightStrategyBase
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from ...backtest.position import Position
|
from ...backtest.position import Position
|
||||||
from ...backtest.exchange import Exchange
|
from ...backtest.exchange import Exchange
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ This module is not a necessary part of Qlib.
|
|||||||
They are just some tools for convenience
|
They are just some tools for convenience
|
||||||
It is should not imported into the core part of qlib
|
It is should not imported into the core part of qlib
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import yaml
|
|||||||
|
|
||||||
from .config import TunerConfigManager
|
from .config import TunerConfigManager
|
||||||
|
|
||||||
|
|
||||||
args_parser = argparse.ArgumentParser(prog="tuner")
|
args_parser = argparse.ArgumentParser(prog="tuner")
|
||||||
args_parser.add_argument(
|
args_parser.add_argument(
|
||||||
"-c",
|
"-c",
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
from hyperopt import hp
|
from hyperopt import hp
|
||||||
|
|
||||||
|
|
||||||
TopkAmountStrategySpace = {
|
TopkAmountStrategySpace = {
|
||||||
"topk": hp.choice("topk", [30, 35, 40]),
|
"topk": hp.choice("topk", [30, 35, 40]),
|
||||||
"buffer_margin": hp.choice("buffer_margin", [200, 250, 300]),
|
"buffer_margin": hp.choice("buffer_margin", [200, 250, 300]),
|
||||||
|
|||||||
@@ -3,5 +3,4 @@
|
|||||||
from .record_temp import MultiSegRecord
|
from .record_temp import MultiSegRecord
|
||||||
from .record_temp import SignalMseRecord
|
from .record_temp import SignalMseRecord
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["MultiSegRecord", "SignalMseRecord"]
|
__all__ = ["MultiSegRecord", "SignalMseRecord"]
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ from .cache import (
|
|||||||
MemoryCalendarCache,
|
MemoryCalendarCache,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"D",
|
"D",
|
||||||
"CalendarProvider",
|
"CalendarProvider",
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ from .loader import DataLoader
|
|||||||
from . import processor as processor_module
|
from . import processor as processor_module
|
||||||
from . import loader as data_loader_module
|
from . import loader as data_loader_module
|
||||||
|
|
||||||
|
|
||||||
DATA_KEY_TYPE = Literal["raw", "infer", "learn"]
|
DATA_KEY_TYPE = Literal["raw", "infer", "learn"]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ The calculation of both <period_time, feature> and <observe_time, feature> data
|
|||||||
2) concatenate all th collasped data, we will get data with format <observe_time, feature>.
|
2) concatenate all th collasped data, we will get data with format <observe_time, feature>.
|
||||||
Qlib will use the operator `P` to perform the collapse.
|
Qlib will use the operator `P` to perform the collapse.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from qlib.data.ops import ElemOperator
|
from qlib.data.ops import ElemOperator
|
||||||
|
|||||||
@@ -3,5 +3,4 @@
|
|||||||
|
|
||||||
from .storage import CalendarStorage, InstrumentStorage, FeatureStorage, CalVT, InstVT, InstKT
|
from .storage import CalendarStorage, InstrumentStorage, FeatureStorage, CalVT, InstVT, InstKT
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["CalendarStorage", "InstrumentStorage", "FeatureStorage", "CalVT", "InstVT", "InstKT"]
|
__all__ = ["CalendarStorage", "InstrumentStorage", "FeatureStorage", "CalVT", "InstVT", "InstKT"]
|
||||||
|
|||||||
@@ -5,5 +5,4 @@ import warnings
|
|||||||
|
|
||||||
from .base import Model
|
from .base import Model
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["Model", "warnings"]
|
__all__ = ["Model", "warnings"]
|
||||||
|
|||||||
@@ -4,5 +4,4 @@
|
|||||||
from .task import MetaTask
|
from .task import MetaTask
|
||||||
from .dataset import MetaTaskDataset
|
from .dataset import MetaTaskDataset
|
||||||
|
|
||||||
|
|
||||||
__all__ = ["MetaTask", "MetaTaskDataset"]
|
__all__ = ["MetaTask", "MetaTaskDataset"]
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ from .poet import POETCovEstimator
|
|||||||
from .shrink import ShrinkCovEstimator
|
from .shrink import ShrinkCovEstimator
|
||||||
from .structured import StructuredCovEstimator
|
from .structured import StructuredCovEstimator
|
||||||
|
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"RiskModel",
|
"RiskModel",
|
||||||
"POETCovEstimator",
|
"POETCovEstimator",
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import tempfile
|
|||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from ruamel.yaml import YAML
|
from ruamel.yaml import YAML
|
||||||
|
|
||||||
|
|
||||||
DELETE_KEY = "_delete_"
|
DELETE_KEY = "_delete_"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
"""
|
"""
|
||||||
This module covers some utility functions that operate on data or basic object
|
This module covers some utility functions that operate on data or basic object
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
"""
|
"""
|
||||||
Time related utils are compiled in this script
|
Time related utils are compiled in this script
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import bisect
|
import bisect
|
||||||
from datetime import datetime, time, date, timedelta
|
from datetime import datetime, time, date, timedelta
|
||||||
from typing import List, Optional, Tuple, Union
|
from typing import List, Optional, Tuple, Union
|
||||||
@@ -14,7 +15,6 @@ import pandas as pd
|
|||||||
from qlib.config import C
|
from qlib.config import C
|
||||||
from qlib.constant import REG_CN, REG_TW, REG_US
|
from qlib.constant import REG_CN, REG_TW, REG_US
|
||||||
|
|
||||||
|
|
||||||
CN_TIME = [
|
CN_TIME = [
|
||||||
datetime.strptime("9:30", "%H:%M"),
|
datetime.strptime("9:30", "%H:%M"),
|
||||||
datetime.strptime("11:30", "%H:%M"),
|
datetime.strptime("11:30", "%H:%M"),
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ from .recorder import Recorder
|
|||||||
from ..log import get_module_logger
|
from ..log import get_module_logger
|
||||||
from ..utils.exceptions import ExpAlreadyExistError
|
from ..utils.exceptions import ExpAlreadyExistError
|
||||||
|
|
||||||
|
|
||||||
logger = get_module_logger("workflow")
|
logger = get_module_logger("workflow")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ from ..utils.data import deepcopy_basic_type
|
|||||||
from ..utils.exceptions import QlibException
|
from ..utils.exceptions import QlibException
|
||||||
from ..contrib.eva.alpha import calc_ic, calc_long_short_return, calc_long_short_prec
|
from ..contrib.eva.alpha import calc_ic, calc_long_short_return, calc_long_short_prec
|
||||||
|
|
||||||
|
|
||||||
logger = get_module_logger("workflow", logging.INFO)
|
logger = get_module_logger("workflow", logging.INFO)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
"""
|
"""
|
||||||
TaskGenerator module can generate many tasks based on TaskGen and some task templates.
|
TaskGenerator module can generate many tasks based on TaskGen and some task templates.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import abc
|
import abc
|
||||||
import copy
|
import copy
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ A task in TaskManager consists of 3 parts
|
|||||||
- tasks status: the status of the task
|
- tasks status: the status of the task
|
||||||
- tasks result: A user can get the task with the task description and task result.
|
- tasks result: A user can get the task with the task description and task result.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import concurrent
|
import concurrent
|
||||||
import pickle
|
import pickle
|
||||||
import time
|
import time
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ from data_collector.index import IndexBase
|
|||||||
from data_collector.utils import get_calendar_list, get_trading_date_by_shift, deco_retry
|
from data_collector.utils import get_calendar_list, get_trading_date_by_shift, deco_retry
|
||||||
from data_collector.utils import get_instruments
|
from data_collector.utils import get_instruments
|
||||||
|
|
||||||
|
|
||||||
NEW_COMPANIES_URL = (
|
NEW_COMPANIES_URL = (
|
||||||
"https://oss-ch.csindex.com.cn/static/html/csindex/public/uploads/file/autofile/cons/{index_code}cons.xls"
|
"https://oss-ch.csindex.com.cn/static/html/csindex/public/uploads/file/autofile/cons/{index_code}cons.xls"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ from time import mktime
|
|||||||
from datetime import datetime as dt
|
from datetime import datetime as dt
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
_CG_CRYPTO_SYMBOLS = None
|
_CG_CRYPTO_SYMBOLS = None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ from tqdm import tqdm
|
|||||||
from loguru import logger
|
from loguru import logger
|
||||||
from fake_useragent import UserAgent
|
from fake_useragent import UserAgent
|
||||||
|
|
||||||
|
|
||||||
CUR_DIR = Path(__file__).resolve().parent
|
CUR_DIR = Path(__file__).resolve().parent
|
||||||
sys.path.append(str(CUR_DIR.parent.parent))
|
sys.path.append(str(CUR_DIR.parent.parent))
|
||||||
|
|
||||||
@@ -24,7 +23,6 @@ from data_collector.index import IndexBase
|
|||||||
from data_collector.utils import deco_retry, get_calendar_list, get_trading_date_by_shift
|
from data_collector.utils import deco_retry, get_calendar_list, get_trading_date_by_shift
|
||||||
from data_collector.utils import get_instruments
|
from data_collector.utils import get_instruments
|
||||||
|
|
||||||
|
|
||||||
WIKI_URL = "https://en.wikipedia.org/wiki"
|
WIKI_URL = "https://en.wikipedia.org/wiki"
|
||||||
|
|
||||||
WIKI_INDEX_NAME_MAP = {
|
WIKI_INDEX_NAME_MAP = {
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ from functools import partial
|
|||||||
from concurrent.futures import ProcessPoolExecutor
|
from concurrent.futures import ProcessPoolExecutor
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
|
from qlib.utils.pickle_utils import restricted_pickle_load
|
||||||
|
|
||||||
HS_SYMBOLS_URL = "http://app.finance.ifeng.com/hq/list.php?type=stock_a&class={s_type}"
|
HS_SYMBOLS_URL = "http://app.finance.ifeng.com/hq/list.php?type=stock_a&class={s_type}"
|
||||||
|
|
||||||
CALENDAR_URL_BASE = "http://push2his.eastmoney.com/api/qt/stock/kline/get?secid={market}.{bench_code}&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58&klt=101&fqt=0&beg=19900101&end=20991231"
|
CALENDAR_URL_BASE = "http://push2his.eastmoney.com/api/qt/stock/kline/get?secid={market}.{bench_code}&fields1=f1%2Cf2%2Cf3%2Cf4%2Cf5&fields2=f51%2Cf52%2Cf53%2Cf54%2Cf55%2Cf56%2Cf57%2Cf58&klt=101&fqt=0&beg=19900101&end=20991231"
|
||||||
@@ -265,7 +267,7 @@ def get_hs_stock_symbols() -> list:
|
|||||||
symbol_cache_path.parent.mkdir(parents=True, exist_ok=True)
|
symbol_cache_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
if symbol_cache_path.exists():
|
if symbol_cache_path.exists():
|
||||||
with symbol_cache_path.open("rb") as fp:
|
with symbol_cache_path.open("rb") as fp:
|
||||||
cache_symbols = pickle.load(fp)
|
cache_symbols = restricted_pickle_load(fp)
|
||||||
symbols |= cache_symbols
|
symbols |= cache_symbols
|
||||||
with symbol_cache_path.open("wb") as fp:
|
with symbol_cache_path.open("wb") as fp:
|
||||||
pickle.dump(symbols, fp)
|
pickle.dump(symbols, fp)
|
||||||
|
|||||||
@@ -4,6 +4,5 @@
|
|||||||
import fire
|
import fire
|
||||||
from qlib.tests.data import GetData
|
from qlib.tests.data import GetData
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
fire.Fire(GetData)
|
fire.Fire(GetData)
|
||||||
|
|||||||
1
setup.py
1
setup.py
@@ -3,7 +3,6 @@ import os
|
|||||||
import numpy
|
import numpy
|
||||||
from setuptools import Extension, setup
|
from setuptools import Extension, setup
|
||||||
|
|
||||||
|
|
||||||
NUMPY_INCLUDE = numpy.get_include()
|
NUMPY_INCLUDE = numpy.get_include()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ from qlib.rl.utils.finite_env import (
|
|||||||
generate_nan_observation,
|
generate_nan_observation,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
_test_space = gym.spaces.Dict(
|
_test_space = gym.spaces.Dict(
|
||||||
{
|
{
|
||||||
"sensors": gym.spaces.Dict(
|
"sensors": gym.spaces.Dict(
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ from qlib.workflow import R
|
|||||||
from qlib.tests import TestAutoData
|
from qlib.tests import TestAutoData
|
||||||
from qlib.tests.config import GBDT_MODEL, get_dataset_config, CSI300_MARKET
|
from qlib.tests.config import GBDT_MODEL, get_dataset_config, CSI300_MARKET
|
||||||
|
|
||||||
|
|
||||||
CSI300_GBDT_TASK = {
|
CSI300_GBDT_TASK = {
|
||||||
"model": GBDT_MODEL,
|
"model": GBDT_MODEL,
|
||||||
"dataset": get_dataset_config(
|
"dataset": get_dataset_config(
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ sys.path.append(str(Path(__file__).resolve().parent.parent.joinpath("scripts")))
|
|||||||
from get_data import GetData
|
from get_data import GetData
|
||||||
from dump_bin import DumpDataAll, DumpDataFix
|
from dump_bin import DumpDataAll, DumpDataFix
|
||||||
|
|
||||||
|
|
||||||
DATA_DIR = Path(__file__).parent.joinpath("test_dump_data")
|
DATA_DIR = Path(__file__).parent.joinpath("test_dump_data")
|
||||||
SOURCE_DIR = DATA_DIR.joinpath("source")
|
SOURCE_DIR = DATA_DIR.joinpath("source")
|
||||||
SOURCE_DIR.mkdir(exist_ok=True, parents=True)
|
SOURCE_DIR.mkdir(exist_ok=True, parents=True)
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ from dump_pit import DumpPitData
|
|||||||
sys.path.append(str(Path(__file__).resolve().parent.parent.joinpath("scripts/data_collector/pit")))
|
sys.path.append(str(Path(__file__).resolve().parent.parent.joinpath("scripts/data_collector/pit")))
|
||||||
from collector import Run
|
from collector import Run
|
||||||
|
|
||||||
|
|
||||||
pd.set_option("display.width", 1000)
|
pd.set_option("display.width", 1000)
|
||||||
pd.set_option("display.max_columns", None)
|
pd.set_option("display.max_columns", None)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user