From 2fb9380b342556ddb50a4b24e4fe8655d548b2b8 Mon Sep 17 00:00:00 2001 From: Linlang <30293408+SunsetWolf@users.noreply.github.com> Date: Thu, 12 Feb 2026 21:07:15 +0800 Subject: [PATCH] fix(backtest): avoid calendar overflow when end_time is missing (#2127) * fix(backtest): avoid calendar overflow when end_time is missing * fix: pkg_source not found error when build docs --- docs/conf.py | 6 +++--- qlib/workflow/record_temp.py | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index f1377c140..7c638e736 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -21,7 +21,7 @@ import os import sys -import pkg_resources +from importlib.metadata import version as ver # -- General configuration ------------------------------------------------ @@ -63,9 +63,9 @@ author = "Microsoft" # built documents. # # The short X.Y version. -version = pkg_resources.get_distribution("pyqlib").version +version = ver("pyqlib") # The full version, including alpha/beta/rc tags. -release = pkg_resources.get_distribution("pyqlib").version +release = version # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/qlib/workflow/record_temp.py b/qlib/workflow/record_temp.py index 844914d46..79c4a78f8 100644 --- a/qlib/workflow/record_temp.py +++ b/qlib/workflow/record_temp.py @@ -476,7 +476,13 @@ class PortAnaRecord(ACRecordTemp): 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) + self.backtest_config["end_time"] = get_date_by_shift(dt_values.max(), -1) + warnings.warn( + "No explicit backtest end_time provided. " + "Qlib requires one extra calendar step to determine the right boundary of a bar. " + "Therefore the end_time is shifted backward by one trading day from " + f"{dt_values.max()} -> {self.backtest_config['end_time']}." + ) artifact_objects = {} # custom strategy and get backtest