Fix/rl alignment assertion error 1972#2306
Open
Vedantvijayhumbe wants to merge 3 commits into
Open
Conversation
…osoft#2278) When end_time falls on the final calendar entry and no future calendar is available, calendar_index + 1 is out of bounds, crashing the backtest with an opaque IndexError. Guard the peek: if calendar_index + 1 < len(self._calendar) use the next bar as before; otherwise compute the right endpoint as left + one freq-period, mirroring the day_start + Timedelta(days=1) idiom already used in get_data_cal_range. epsilon_change is applied to whichever right is chosen, so the closed-interval convention is preserved on both paths. Added tests/backtest/test_calendar_boundary.py covering: - last-bar step does not raise - day and minute fallback values - pre-boundary steps are unchanged - full loop terminates with the correct step count
…x alignment Fixes microsoft#1972 ## Problem In , two bare statements guarded the requirement that and must each be divisible by : assert data_config["source"]["default_start_time_index"] % data_granularity == 0 assert data_config["source"]["default_end_time_index"] % data_granularity == 0 When a user supplied a misaligned value (e.g. with ), they received a bare with no message, making it impossible to understand what went wrong or how to fix it. ## Changes ### qlib/rl/contrib/_utils.py (new) Extracts the validation logic into a standalone function that lives in a module with **zero** heavy dependencies (no tianshou, torch, gym). This allows the function to be unit-tested in any CI environment regardless of which optional packages are installed. ### qlib/rl/contrib/train_onpolicy.py - Imports from and calls it instead of the bare asserts. - Adds a comprehensive NumPy-style docstring to that explicitly documents the alignment constraint with examples, a block, and a section. ### docs/component/rl/quickstart.rst - Fixes two wrong config key names in the example YAML ( → , → , → ). - Adds a admonition explaining the alignment rule and providing concrete examples for different granularities. - Fixes the invocation commands (removed spurious suffix). ### tests/rl/test_train_onpolicy_alignment.py (new) 14 unit tests covering valid and invalid configurations. Tests verify that: - Valid index/granularity pairs do not raise. - Misaligned indices raise (not ). - Error messages contain the actual values, the modulo remainder, and a suggested correction. - errors are reported before errors when both are wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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