mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-17 09:24:34 +08:00
Black
This commit is contained in:
@@ -278,7 +278,7 @@ def single_with_collect_data_loop(
|
|||||||
**{
|
**{
|
||||||
"codes": stocks,
|
"codes": stocks,
|
||||||
"freq": backtest_config["data_granularity"],
|
"freq": backtest_config["data_granularity"],
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
strategy, executor = get_strategy_executor(
|
strategy, executor = get_strategy_executor(
|
||||||
|
|||||||
@@ -192,13 +192,15 @@ class TrainingConfigParser:
|
|||||||
"qlib": {
|
"qlib": {
|
||||||
"provider_uri_1min": config["qlib"]["provider_uri_1min"],
|
"provider_uri_1min": config["qlib"]["provider_uri_1min"],
|
||||||
},
|
},
|
||||||
"exchange": exchange_config
|
"exchange": exchange_config,
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret_config
|
return ret_config
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = TrainingConfigParser("/home/huoran/exp_configs/amc4th_training_refined.yml")
|
parser = TrainingConfigParser("/home/huoran/exp_configs/amc4th_training_refined.yml")
|
||||||
|
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
|
|
||||||
pprint(parser.parse())
|
pprint(parser.parse())
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ def get_executor_config(freq: int) -> dict:
|
|||||||
"track_data": True,
|
"track_data": True,
|
||||||
"trade_type": "serial",
|
"trade_type": "serial",
|
||||||
"verbose": False,
|
"verbose": False,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
"inner_strategy": {
|
"inner_strategy": {
|
||||||
"class": "TWAPStrategy",
|
"class": "TWAPStrategy",
|
||||||
@@ -58,7 +58,7 @@ def get_executor_config(freq: int) -> dict:
|
|||||||
},
|
},
|
||||||
"time_per_step": "30min",
|
"time_per_step": "30min",
|
||||||
"track_data": True,
|
"track_data": True,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
"inner_strategy": {
|
"inner_strategy": {
|
||||||
"class": "ProxySAOEStrategy",
|
"class": "ProxySAOEStrategy",
|
||||||
@@ -67,7 +67,7 @@ def get_executor_config(freq: int) -> dict:
|
|||||||
},
|
},
|
||||||
"time_per_step": "1day",
|
"time_per_step": "1day",
|
||||||
"track_data": True,
|
"track_data": True,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -168,6 +168,7 @@ def train_and_test(
|
|||||||
|
|
||||||
sim_type = simulator_config["type"]
|
sim_type = simulator_config["type"]
|
||||||
if sim_type == "simple":
|
if sim_type == "simple":
|
||||||
|
|
||||||
def _simulator_factory(order: Order) -> SingleAssetOrderExecutionSimple:
|
def _simulator_factory(order: Order) -> SingleAssetOrderExecutionSimple:
|
||||||
simulator = SingleAssetOrderExecutionSimple(
|
simulator = SingleAssetOrderExecutionSimple(
|
||||||
order=order,
|
order=order,
|
||||||
@@ -178,6 +179,7 @@ def train_and_test(
|
|||||||
vol_threshold=simulator_config["vol_limit"],
|
vol_threshold=simulator_config["vol_limit"],
|
||||||
)
|
)
|
||||||
return simulator
|
return simulator
|
||||||
|
|
||||||
elif sim_type == "full":
|
elif sim_type == "full":
|
||||||
init_qlib(simulator_config["qlib"])
|
init_qlib(simulator_config["qlib"])
|
||||||
executor_config = get_executor_config(freq)
|
executor_config = get_executor_config(freq)
|
||||||
@@ -287,16 +289,13 @@ def main(config: dict, run_training: bool, run_backtest: bool) -> None:
|
|||||||
network_config = config["policy"]["network"]
|
network_config = config["policy"]["network"]
|
||||||
network_config["kwargs"] = {
|
network_config["kwargs"] = {
|
||||||
**network_config.get("kwargs", {}),
|
**network_config.get("kwargs", {}),
|
||||||
**{"obs_space": state_interpreter.observation_space}
|
**{"obs_space": state_interpreter.observation_space},
|
||||||
}
|
}
|
||||||
additional_policy_kwargs["network"] = init_instance_by_config(network_config)
|
additional_policy_kwargs["network"] = init_instance_by_config(network_config)
|
||||||
|
|
||||||
# Create policy
|
# Create policy
|
||||||
policy_config = config["policy"]["policy"]
|
policy_config = config["policy"]["policy"]
|
||||||
policy_config["kwargs"] = {
|
policy_config["kwargs"] = {**policy_config.get("kwargs", {}), **additional_policy_kwargs}
|
||||||
**policy_config.get("kwargs", {}),
|
|
||||||
**additional_policy_kwargs
|
|
||||||
}
|
|
||||||
policy: BasePolicy = init_instance_by_config(policy_config)
|
policy: BasePolicy = init_instance_by_config(policy_config)
|
||||||
|
|
||||||
use_cuda = config["runtime"]["use_cuda"]
|
use_cuda = config["runtime"]["use_cuda"]
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ def get_executor_config(data_granularity: int = 1) -> dict:
|
|||||||
"track_data": True,
|
"track_data": True,
|
||||||
"trade_type": "serial",
|
"trade_type": "serial",
|
||||||
"verbose": False,
|
"verbose": False,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
"inner_strategy": {
|
"inner_strategy": {
|
||||||
"class": "TWAPStrategy",
|
"class": "TWAPStrategy",
|
||||||
@@ -59,7 +59,7 @@ def get_executor_config(data_granularity: int = 1) -> dict:
|
|||||||
},
|
},
|
||||||
"time_per_step": "30min",
|
"time_per_step": "30min",
|
||||||
"track_data": True,
|
"track_data": True,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
"inner_strategy": {
|
"inner_strategy": {
|
||||||
"class": "ProxySAOEStrategy",
|
"class": "ProxySAOEStrategy",
|
||||||
@@ -68,7 +68,7 @@ def get_executor_config(data_granularity: int = 1) -> dict:
|
|||||||
},
|
},
|
||||||
"time_per_step": "1day",
|
"time_per_step": "1day",
|
||||||
"track_data": True,
|
"track_data": True,
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -149,6 +149,7 @@ def _load_handler_pickle(path: str) -> object:
|
|||||||
obj = pickle.load(fstream)
|
obj = pickle.load(fstream)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
|
||||||
class HandlerIntradayProcessedData(BaseIntradayProcessedData):
|
class HandlerIntradayProcessedData(BaseIntradayProcessedData):
|
||||||
"""Subclass of IntradayProcessedData. Used to handle handler (bin format) style data."""
|
"""Subclass of IntradayProcessedData. Used to handle handler (bin format) style data."""
|
||||||
|
|
||||||
@@ -189,7 +190,12 @@ def load_handler_intraday_processed_data(
|
|||||||
backtest: bool = False,
|
backtest: bool = False,
|
||||||
) -> HandlerIntradayProcessedData:
|
) -> HandlerIntradayProcessedData:
|
||||||
return HandlerIntradayProcessedData(
|
return HandlerIntradayProcessedData(
|
||||||
data_dir, stock_id, date, feature_columns_today, feature_columns_yesterday, backtest,
|
data_dir,
|
||||||
|
stock_id,
|
||||||
|
date,
|
||||||
|
feature_columns_today,
|
||||||
|
feature_columns_yesterday,
|
||||||
|
backtest,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import time
|
|||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from line_profiler import LineProfiler
|
from line_profiler import LineProfiler
|
||||||
|
|
||||||
|
|
||||||
@contextmanager
|
@contextmanager
|
||||||
def simple_perf(desc: str = ""):
|
def simple_perf(desc: str = ""):
|
||||||
s = time.perf_counter()
|
s = time.perf_counter()
|
||||||
@@ -17,4 +18,5 @@ def lprofile(func):
|
|||||||
res = lpw(*args, **kwargs)
|
res = lpw(*args, **kwargs)
|
||||||
lp.print_stats()
|
lp.print_stats()
|
||||||
return res
|
return res
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|||||||
Reference in New Issue
Block a user