Conversation
| split: str = "stock", | ||
| cash_limit: float = None, | ||
| generate_report: bool = False, | ||
| ) -> Union[Tuple[pd.DataFrame, dict], pd.DataFrame]: |
There was a problem hiding this comment.
There should be some docstring for this function.
qlib/rl/contrib/backtest.py
Outdated
|
|
||
|
|
||
| def _generate_report(decisions: list, report_dict: dict) -> dict: | ||
| def _generate_report(decisions: list, report_dicts: List[dict]) -> dict: |
There was a problem hiding this comment.
I think there should be richer annotation for the input (e.g. report) and the returned report
For example, @ dataclass with typed fields and detailed docstrings
There was a problem hiding this comment.
I did some research on this issue and I found that this is related to the entire collect_data_loop() / backtest() lifecycle, so we need a lot of efforts to optimize it. Since it is not about the core function of RL backtest, I suggest we leave this in future PRs.
There was a problem hiding this comment.
Maybe we can leave a TODO here...
| } | ||
| ) | ||
|
|
||
| simulator = SingleAssetOrderExecution( |
There was a problem hiding this comment.
How does this simulator generate reports?
I didn't find how the step is called.
There was a problem hiding this comment.
The simulator will execute one hidden step when it is created. When it is used in training, it will pause at the first yield of the internal strategies. However, in backtest, there will (should) not be any pauses, so the simulator will run until it stops.
qlib/rl/contrib/backtest.py
Outdated
| stock_pool = stock_pool | ||
|
|
||
| single = single_with_simulator if with_simulator else single_with_collect_data_loop | ||
| if parallel_mode: |
There was a problem hiding this comment.
I don't think parallel_mode is a required parameter.
Joblib will fall to single process when n_jobs == 1
| Configuration used to initialize Qlib. If it is None, Qlib will not be initialized. | ||
| cash_limit: | ||
| Cash limit. | ||
| backtest_mode |
There was a problem hiding this comment.
backtest_mode is not a necessary parameter if we carefully design it.
It should disappear with CollectDataEnvWrapper in the future.
Please add doc for it.
There was a problem hiding this comment.
Agree. backtest_mode looks ugly in the init signature.
| executor.inner_strategy.set_env(CollectDataEnvWrapper()) | ||
| executor = executor.inner_executor | ||
|
|
||
| self.step(action=None) |
There was a problem hiding this comment.
Why should it call step in the reset phase?
There was a problem hiding this comment.
Call step() with None is to "activate" the internal generator.
There was a problem hiding this comment.
Please Add comments about it.
|
|
||
| self._last_yielded_saoe_strategy = self._iter_strategy(action=None) | ||
| if backtest_mode: | ||
| executor: BaseExecutor = self._executor |
There was a problem hiding this comment.
Add comments that it should be removed in the future
| return np.array([tmp.get(t, fill_val) for t in total_time_list]) | ||
|
|
||
|
|
||
| class SAOEStateAdapter: |
There was a problem hiding this comment.
I suggest moving this adapter to state_adapter.py or simulator_qlib.py. If I'm using the simple simluator, there is no reason I will be interested in all these adapter-related logics.
Can be left as TODO. :)
| for key in ["1minute", "5minute", "30minute", "1day"]: | ||
| if key not in report_dict["indicator"]: | ||
| decision_details = pd.concat([getattr(d, "details") for d in decisions if hasattr(d, "details")]) | ||
| for key in ["1min", "5min", "30min", "1day"]: |
There was a problem hiding this comment.
I think I hard-coded this to quickly run through the experiments.
For open source version, it's worth making it more general.
There was a problem hiding this comment.
This is part of the following issue mentioned by you-n-g before. I will redesign the entire logic in later PRs.
I think there should be richer annotation for the input (e.g. report) and the returned report
For example, @ dataclass with typed fields and detailed docstrings
| ) | ||
|
|
||
|
|
||
| class TradeDecisionWithDetails(TradeDecisionWO): |
There was a problem hiding this comment.
Add some explanations on why (in what scenarios) we need this.
| Configuration used to initialize Qlib. If it is None, Qlib will not be initialized. | ||
| cash_limit: | ||
| Cash limit. | ||
| backtest_mode |
There was a problem hiding this comment.
Agree. backtest_mode looks ugly in the init signature.
|
The CI will be fixed in this PR soon #1314 |
* RL backtest with simulator * Minor modification in init_qlib * Cherry pick PR 1302 * Resolve PR comments * Fix missing data processing * Minor bugfix * Add TODOs and docs * Add a comment

Now support running RL backtest with SAOE simulator.
Description
Motivation and Context
How Has This Been Tested?
pytest qlib/tests/test_all_pipeline.pyunder upper directory ofqlib.Screenshots of Test Results (if appropriate):
Types of changes