microsoft / microsoft/qlib

backtest occur errror while executor's time_per_step=1day

Open
#1,925 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

To Reproduce



__benchmark = "SH000300"

portfolio_analysis_config = {
    "strategy": {
        "class": "TopkDropoutStrategy",
        "module_path": "qlib.contrib.strategy",
        "kwargs": {
            "signal": '<PRED>',
            "topk": 50,
            "n_drop": 5,
        },
    },
    "executor": {
        "class": "SimulatorExecutor",
        "module_path": "qlib.backtest.executor",
        "kwargs": {
            "time_per_step": "1day",
            "generate_portfolio_metrics": True,
        },
    },
    "backtest": {
        "start_time": "2017-01-01",
        "end_time": "2020-08-01",
        "account": 100000000,
        "benchmark": __benchmark,
        "exchange_kwargs": {
            "limit_threshold": 0.095,
            "deal_price": "close",
            "open_cost": 0.0005,
            "close_cost": 0.0015,
            "min_cost": 5,
        },
    },
}

class WorkflowTest(TestCase):

    def setUp(self):
        super().setUp()

        provider_uri = "~/.qlib/qlib_data/cn_data"
        qlib.init(provider_uri=provider_uri, region=REG_CN)

        self.__my_prefix = 'my_'
        self.__rec_start_param = {'resume': True,
                                  'experiment_name': f"{self.__my_prefix}experiment",
                                  'recorder_name': f"{self.__my_prefix}recorder"}

        self._pkl_model = f"{self.__my_prefix}model.pkl"
        self._pkl_dataset = f"{self.__my_prefix}dataset.pkl"

    def test_backtest(self):
        with R.start(**self.__rec_start_param):
            recorder = R.get_recorder()

            pred = R.load_object('pred.pkl')
            placehorder_value = {"<PRED>": pred}
            pa_config = fill_placeholder(portfolio_analysis_config, placehorder_value)

            par = PortAnaRecord(recorder=recorder, config=pa_config)
            par.generate()


errors:

  File "/python3.12/site-packages/qlib/backtest/report.py", line 116, in _cal_benchmark
    raise ValueError(f"The benchmark {_codes} does not exist. Please provide the right benchmark")
ValueError: The benchmark ['SH000300'] does not exist. Please provide the right benchmark

DeBUG this method qlib.utils.resam.get_higher_eq_freq_feature(),Found that the method was called twice, the first time freq=day and the second time freq=1day`

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 qlib.utils.resam.get_higher_eq_freq_feature(), which the report says receives both day and 1day, and inspect qlib/backtest/report.py at _cal_benchmark(). Run the supplied backtest using SimulatorExecutor with time_per_step set to 1day and benchmark SH000300. Done means the benchmark is found and the run no longer raises the reported ValueError.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.