{"record":{"id":"6d9bfba154fddc07","repo":"microsoft/qlib","slug":"the-benchmark-codes-does-not-exist-please-prov","errorCode":null,"errorMessage":"The benchmark {_codes} does not exist. Please provide the right benchmark","messagePattern":"The benchmark (.+?) does not exist\\. Please provide the right benchmark","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"qlib/backtest/report.py","lineNumber":116,"sourceCode":"        if benchmark_config is None:\n            return None\n        benchmark = benchmark_config.get(\"benchmark\", CSI300_BENCH)\n        if benchmark is None:\n            return None\n\n        if isinstance(benchmark, pd.Series):\n            return benchmark\n        else:\n            start_time = benchmark_config.get(\"start_time\", None)\n            end_time = benchmark_config.get(\"end_time\", None)\n\n            if freq is None:\n                raise ValueError(\"benchmark freq can't be None!\")\n            _codes = benchmark if isinstance(benchmark, (list, dict)) else [benchmark]\n            fields = [\"$close/Ref($close,1)-1\"]\n            _temp_result, _ = get_higher_eq_freq_feature(_codes, fields, start_time, end_time, freq=freq)\n            if len(_temp_result) == 0:\n                raise ValueError(f\"The benchmark {_codes} does not exist. Please provide the right benchmark\")\n            return (\n                _temp_result.groupby(level=\"datetime\", group_keys=False)[_temp_result.columns.tolist()[0]]\n                .mean()\n                .fillna(0)\n            )\n\n    def _sample_benchmark(\n        self,\n        bench: pd.Series,\n        trade_start_time: Union[str, pd.Timestamp],\n        trade_end_time: Union[str, pd.Timestamp],\n    ) -> Optional[float]:\n        if self.bench is None:\n            return None\n\n        def cal_change(x):\n            return (x + 1).prod()\n","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/microsoft/qlib/blob/79633dd9506ea689e5400dea0197717b5b3d74b7/qlib/backtest/report.py#L98-L134","documentation":"After resolving benchmark codes and querying $close/Ref($close,1)-1 via get_higher_eq_freq_feature, _cal_benchmark receives an empty result and raises ValueError('The benchmark {codes} does not exist...'). The local qlib data contains no bars for the requested benchmark instrument(s) in the given time range, so no return series can be built.","triggerScenarios":"benchmark like 'SH000300' (or a custom list) missing from the installed data dump; start_time/end_time in benchmark_config entirely outside data coverage; wrong instrument naming convention for the dump; freq mismatch with available data.","commonSituations":"Using the small qlib demo data (which may lack index data) with the default CSI300 benchmark; custom datasets without benchmark indices; date ranges before the index existed; instrument name typos ('000300' vs 'SH000300').","solutions":["Check the code exists in your data: D.features(['SH000300'], ['$close'], start, end, freq=freq)","Extend benchmark_config start_time/end_time to match data coverage or drop them","Download/provide index data with dump_bin.py, or pass benchmark as an inline pd.Series you computed yourself"],"exampleFix":"# before\nbenchmark_config = {\"benchmark\": \"SH000300\"}  # not in local data\n\n# after\nimport pandas as pd\nbench_ret = pd.Series(..., index=pd.DatetimeIndex(...))  # precomputed\nbenchmark_config = {\"benchmark\": bench_ret}","handlingStrategy":"validation","validationCode":"from qlib.data import D\ncodes = benchmark if isinstance(benchmark, (list, dict)) else [benchmark]\ndf = D.features(codes, [\"$close\"], cfg.get(\"start_time\"), cfg.get(\"end_time\"), freq=freq)\nassert len(df.dropna()) > 0, f\"benchmark data missing for {codes}\"","typeGuard":null,"tryCatchPattern":"try:\n    pm.init_bench(freq=freq, benchmark_config=cfg)\nexcept ValueError as e:\n    if \"does not exist\" in str(e):\n        pm.init_bench(freq=freq, benchmark_config={\"benchmark\": precomputed_series})","preventionTips":["Verify benchmark instruments exist in the local dump before backtests","Use the same instrument naming convention as your data","Fall back to an inline pd.Series benchmark when index data is unavailable"],"tags":["qlib","backtest","benchmark","missing-data","report"],"backgroundTag":null,"analyzedSha":"79633dd9506ea689e5400dea0197717b5b3d74b7","analyzedAt":"2026-08-15T07:01:27.511Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}