mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-05 20:11:08 +08:00
fix trade time bug
This commit is contained in:
@@ -10,7 +10,7 @@ from qlib.config import REG_CN
|
||||
|
||||
from qlib.utils import exists_qlib_data, init_instance_by_config, flatten_dict
|
||||
from qlib.workflow import R
|
||||
from qlib.workflow.record_temp import PortAnaRecord
|
||||
from qlib.workflow.record_temp import SignalRecord, PortAnaRecord
|
||||
from qlib.tests.data import GetData
|
||||
|
||||
if __name__ == "__main__":
|
||||
@@ -64,9 +64,9 @@ if __name__ == "__main__":
|
||||
"kwargs": data_handler_config,
|
||||
},
|
||||
"segments": {
|
||||
"train": ("2012-01-01", "2014-12-31"),
|
||||
"train": ("2008-01-01", "2014-12-31"),
|
||||
"valid": ("2015-01-01", "2016-12-31"),
|
||||
"test": ("2017-01-01", "2018-01-31"),
|
||||
"test": ("2017-01-01", "2020-08-01"),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -74,17 +74,16 @@ if __name__ == "__main__":
|
||||
# model initialization
|
||||
model = init_instance_by_config(task["model"])
|
||||
dataset = init_instance_by_config(task["dataset"])
|
||||
model.fit(dataset)
|
||||
|
||||
trade_start_time = "2017-01-31"
|
||||
trade_end_time = "2018-01-31"
|
||||
trade_start_time = "2017-01-01"
|
||||
trade_end_time = "2020-08-01"
|
||||
|
||||
port_analysis_config = {
|
||||
"strategy": {
|
||||
"class": "TopkDropoutStrategy",
|
||||
"module_path": "qlib.contrib.strategy.model_strategy",
|
||||
"kwargs": {
|
||||
"step_bar": "week",
|
||||
"step_bar": "day",
|
||||
"model": model,
|
||||
"dataset": dataset,
|
||||
"topk": 50,
|
||||
@@ -92,28 +91,12 @@ if __name__ == "__main__":
|
||||
},
|
||||
},
|
||||
"env": {
|
||||
"class": "SplitEnv",
|
||||
"class": "SimulatorEnv",
|
||||
"module_path": "qlib.contrib.backtest.env",
|
||||
"kwargs": {
|
||||
"step_bar": "week",
|
||||
"sub_env": {
|
||||
"class": "SimulatorEnv",
|
||||
"module_path": "qlib.contrib.backtest.env",
|
||||
"kwargs": {
|
||||
"step_bar": "day",
|
||||
"verbose": True,
|
||||
"generate_report": True,
|
||||
},
|
||||
},
|
||||
"sub_strategy": {
|
||||
"class": "SBBStrategyEMA",
|
||||
"module_path": "qlib.contrib.strategy.rule_strategy",
|
||||
"kwargs": {
|
||||
"step_bar": "day",
|
||||
"freq": "day",
|
||||
"instruments": "csi300",
|
||||
},
|
||||
},
|
||||
"step_bar": "day",
|
||||
"verbose": True,
|
||||
"generate_report": True,
|
||||
},
|
||||
},
|
||||
"backtest": {
|
||||
@@ -129,9 +112,18 @@ if __name__ == "__main__":
|
||||
"min_cost": 5,
|
||||
},
|
||||
}
|
||||
|
||||
with R.start(experiment_name="highfreq_backtest"):
|
||||
R.log_params(**flatten_dict(task))
|
||||
model.fit(dataset)
|
||||
R.save_objects(**{"params.pkl": model})
|
||||
|
||||
# prediction
|
||||
recorder = R.get_recorder()
|
||||
sr = SignalRecord(model, dataset, recorder)
|
||||
sr.generate()
|
||||
|
||||
# backtest. If users want to use backtest based on their own prediction,
|
||||
# please refer to https://qlib.readthedocs.io/en/latest/component/recorder.html#record-template.
|
||||
recorder = R.get_recorder()
|
||||
par = PortAnaRecord(recorder, port_analysis_config, "day")
|
||||
par.generate()
|
||||
par.generate()
|
||||
Reference in New Issue
Block a user