mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-16 01:06:56 +08:00
update workflow_by_code & update executor
This commit is contained in:
@@ -66,32 +66,45 @@ if __name__ == "__main__":
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# model initialization
|
||||||
|
model = init_instance_by_config(task["model"])
|
||||||
|
dataset = init_instance_by_config(task["dataset"])
|
||||||
|
|
||||||
port_analysis_config = {
|
port_analysis_config = {
|
||||||
|
"executor": {
|
||||||
|
"class": "SimulatorExecutor",
|
||||||
|
"module_path": "qlib.backtest.executor",
|
||||||
|
"kwargs": {
|
||||||
|
"time_per_step": "day",
|
||||||
|
"generate_report": True,
|
||||||
|
},
|
||||||
|
},
|
||||||
"strategy": {
|
"strategy": {
|
||||||
"class": "TopkDropoutStrategy",
|
"class": "TopkDropoutStrategy",
|
||||||
"module_path": "qlib.contrib.strategy.strategy",
|
"module_path": "qlib.contrib.strategy.model_strategy",
|
||||||
"kwargs": {
|
"kwargs": {
|
||||||
|
"model": model,
|
||||||
|
"dataset": dataset,
|
||||||
"topk": 50,
|
"topk": 50,
|
||||||
"n_drop": 5,
|
"n_drop": 5,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"backtest": {
|
"backtest": {
|
||||||
"verbose": False,
|
"start_time": "2017-01-01",
|
||||||
"limit_threshold": 0.095,
|
"end_time": "2020-08-01",
|
||||||
"account": 100000000,
|
"account": 100000000,
|
||||||
"benchmark": benchmark,
|
"benchmark": benchmark,
|
||||||
"deal_price": "close",
|
"exchange_kwargs": {
|
||||||
"open_cost": 0.0005,
|
"freq": "day",
|
||||||
"close_cost": 0.0015,
|
"limit_threshold": 0.095,
|
||||||
"min_cost": 5,
|
"deal_price": "close",
|
||||||
"return_order": True,
|
"open_cost": 0.0005,
|
||||||
|
"close_cost": 0.0015,
|
||||||
|
"min_cost": 5,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
# model initialization
|
|
||||||
model = init_instance_by_config(task["model"])
|
|
||||||
dataset = init_instance_by_config(task["dataset"])
|
|
||||||
|
|
||||||
# NOTE: This line is optional
|
# NOTE: This line is optional
|
||||||
# It demonstrates that the dataset can be used standalone.
|
# It demonstrates that the dataset can be used standalone.
|
||||||
example_df = dataset.prepare("train")
|
example_df = dataset.prepare("train")
|
||||||
@@ -110,5 +123,5 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
# backtest. If users want to use backtest based on their own prediction,
|
# 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.
|
# please refer to https://qlib.readthedocs.io/en/latest/component/recorder.html#record-template.
|
||||||
par = PortAnaRecord(recorder, port_analysis_config)
|
par = PortAnaRecord(recorder, port_analysis_config, "day")
|
||||||
par.generate()
|
par.generate()
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from .backtest import backtest as backtest_func
|
|||||||
from .backtest import collect_data as data_generator
|
from .backtest import collect_data as data_generator
|
||||||
|
|
||||||
from .utils import CommonInfrastructure
|
from .utils import CommonInfrastructure
|
||||||
|
from .order import Order
|
||||||
from ..strategy.base import BaseStrategy
|
from ..strategy.base import BaseStrategy
|
||||||
from ..utils import init_instance_by_config
|
from ..utils import init_instance_by_config
|
||||||
from ..log import get_module_logger
|
from ..log import get_module_logger
|
||||||
|
|||||||
@@ -118,6 +118,9 @@ class BaseExecutor:
|
|||||||
def get_report(self):
|
def get_report(self):
|
||||||
raise NotImplementedError("get_report is not implemented!")
|
raise NotImplementedError("get_report is not implemented!")
|
||||||
|
|
||||||
|
def get_all_executor(self):
|
||||||
|
return [self]
|
||||||
|
|
||||||
|
|
||||||
class NestedExecutor(BaseExecutor):
|
class NestedExecutor(BaseExecutor):
|
||||||
"""
|
"""
|
||||||
@@ -244,6 +247,9 @@ class NestedExecutor(BaseExecutor):
|
|||||||
sub_env_report_dict.update({f"{_count}{_freq}": (_report, _positions)})
|
sub_env_report_dict.update({f"{_count}{_freq}": (_report, _positions)})
|
||||||
return sub_env_report_dict
|
return sub_env_report_dict
|
||||||
|
|
||||||
|
def get_all_executor(self):
|
||||||
|
return [self, *self.inner_executor.get_all_executor()]
|
||||||
|
|
||||||
|
|
||||||
class SimulatorExecutor(BaseExecutor):
|
class SimulatorExecutor(BaseExecutor):
|
||||||
"""Executor that simulate the true market"""
|
"""Executor that simulate the true market"""
|
||||||
|
|||||||
@@ -11,10 +11,11 @@ class Order:
|
|||||||
stock_id : str
|
stock_id : str
|
||||||
amount : float
|
amount : float
|
||||||
start_time : pd.Timestamp
|
start_time : pd.Timestamp
|
||||||
closed start time for order generation
|
closed start time for order trading
|
||||||
end_time : pd.Timestamp
|
end_time : pd.Timestamp
|
||||||
closed end time for order generation
|
closed end time for order trading
|
||||||
direction : Order.SELL for sell; Order.BUY for buy
|
direction : int
|
||||||
|
Order.SELL for sell; Order.BUY for buy
|
||||||
factor : float
|
factor : float
|
||||||
presents the weight factor assigned in Exchange()
|
presents the weight factor assigned in Exchange()
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user