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