microsoft / microsoft/qlib

datetime occurs multiple times

Open
#1,909 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
48.7k
Forks
7.7k
PR merge metrics
No merged PRs in 30d

Description

🐛 Bug Description

when change example config to alpha360, datetime occurs multiple times error occurs. i debug to recognize may be record_temp.py can fix to solve

To Reproduce

Steps to reproduce the behavior:

1.change the data handler to use alpha360

    dataset:
        class: DatasetH
        module_path: qlib.data.dataset
        kwargs:
            handler:
                class: Alpha360
                module_path: qlib.contrib.data.handler
                kwargs: *data_handler_config
            segments:
                train: [2022-04-12, 2024-08-12]
                valid: [2024-08-13, 2024-12-31]
                test: [2025-01-05, 2025-04-01]
  1. qrun config

Expected Behavior

no error

Screenshot

Image

Environment

Note: User could run cd scripts && python collect_info.py all under project directory to get system information
and paste them here directly.

  • Qlib version: 0.9.6
  • Python version:3.10
  • OS (Windows):

Additional Notes

after i change the code from workflow/record_temp.py function _generate

    def _generate(self, **kwargs):
        pred = self.load("pred.pkl")

        # replace the "<PRED>" with prediction saved before
        placeholder_value = {"<PRED>": pred}
        for k in "executor_config", "strategy_config":
            setattr(self, k, fill_placeholder(getattr(self, k), placeholder_value))
        # if the backtesting time range is not set, it will automatically extract time range from the prediction file
        dt_values = pred.index.get_level_values("datetime")
        if self.backtest_config["start_time"] is None:
            self.backtest_config["start_time"] = dt_values.min()
        if self.backtest_config["end_time"] is None:
            self.backtest_config["end_time"] = get_date_by_shift(dt_values.max(), 1)
......

to

    def _generate(self, **kwargs):
        pred = self.load("pred.pkl")

        # replace the "<PRED>" with prediction saved before
        placeholder_value = {"<PRED>": pred}
        for k in "executor_config", "strategy_config":
            setattr(self, k, fill_placeholder(getattr(self, k), placeholder_value))
        # if the backtesting time range is not set, it will automatically extract time range from the prediction file
        datetime_level = pred.index.names.index("datetime")
        dt_values = pred.index.get_level_values(datetime_level)
        if self.backtest_config["start_time"] is None:
            self.backtest_config["start_time"] = dt_values.min()
        if self.backtest_config["end_time"] is None:
            self.backtest_config["end_time"] = get_date_by_shift(dt_values.max(), 1)
....

the error disapper

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with workflow/record_temp.py and the _generate function, then reproduce the qrun configuration using the Alpha360 handler. Check how the prediction index exposes its datetime level and verify the backtest range is derived without the reported error. Done means the configuration runs successfully and the regression is covered by the project’s existing test approach, if applicable.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.