MCPcopy
hub / github.com/microsoft/qlib / backtest

Function backtest

qlib/rl/trainer/api.py:66–118  ·  view source on GitHub ↗

Backtest with the parallelism provided by RL framework. Experimental API. Parameters might change shortly. Parameters ---------- simulator_fn Callable receiving initial seed, returning a simulator. state_interpreter Interprets the state of simulators. action

(
    simulator_fn: Callable[[InitialStateType], Simulator],
    state_interpreter: StateInterpreter,
    action_interpreter: ActionInterpreter,
    initial_states: Sequence[InitialStateType],
    policy: BasePolicy,
    logger: LogWriter | List[LogWriter],
    reward: Reward | None = None,
    finite_env_type: FiniteEnvType = "subproc",
    concurrency: int = 2,
)

Source from the content-addressed store, hash-verified

64
65
66def backtest(
67 simulator_fn: Callable[[InitialStateType], Simulator],
68 state_interpreter: StateInterpreter,
69 action_interpreter: ActionInterpreter,
70 initial_states: Sequence[InitialStateType],
71 policy: BasePolicy,
72 logger: LogWriter | List[LogWriter],
73 reward: Reward | None = None,
74 finite_env_type: FiniteEnvType = "subproc",
75 concurrency: int = 2,
76) -> None:
77 """Backtest with the parallelism provided by RL framework.
78
79 Experimental API. Parameters might change shortly.
80
81 Parameters
82 ----------
83 simulator_fn
84 Callable receiving initial seed, returning a simulator.
85 state_interpreter
86 Interprets the state of simulators.
87 action_interpreter
88 Interprets the policy actions.
89 initial_states
90 Initial states to iterate over. Every state will be run exactly once.
91 policy
92 Policy to test against.
93 logger
94 Logger to record the backtest results. Logger must be present because
95 without logger, all information will be lost.
96 reward
97 Optional reward function. For backtest, this is for testing the rewards
98 and logging them only.
99 finite_env_type
100 Type of finite env implementation.
101 concurrency
102 Parallel workers.
103 """
104
105 vessel = TrainingVessel(
106 simulator_fn=simulator_fn,
107 state_interpreter=state_interpreter,
108 action_interpreter=action_interpreter,
109 policy=policy,
110 test_initial_states=initial_states,
111 reward=cast(Reward, reward), # ignore none
112 )
113 trainer = Trainer(
114 finite_env_type=finite_env_type,
115 concurrency=concurrency,
116 loggers=logger,
117 )
118 trainer.test(vessel)

Callers 3

test_twap_strategyFunction · 0.90
test_cn_ppo_strategyFunction · 0.90
train_and_testFunction · 0.90

Calls 3

testMethod · 0.95
TrainingVesselClass · 0.85
TrainerClass · 0.70

Tested by 2

test_twap_strategyFunction · 0.72
test_cn_ppo_strategyFunction · 0.72