microsoft/qlib · error · ValueError
calendar does not exist: {self.calendar_path}
Error message
calendar does not exist: {self.calendar_path} What it means
Raised by CollectorFutureCalendar.calendar_list (scripts/data_collector/future_calendar_collector.py:45) when <qlib_dir>/calendars/day.txt does not exist. The future-calendar collector works by merging new exchange trading dates into the existing day calendar, so a pre-existing qlib data directory with a valid calendars/day.txt is a hard prerequisite. Its absence means the qlib_dir argument does not point at an initialized qlib data directory.
Source
Thrown at scripts/data_collector/future_calendar_collector.py:45
qlib data directory
start_date
start date
end_date
end date
"""
self.qlib_dir = Path(qlib_dir).expanduser().absolute()
self.calendar_path = self.qlib_dir.joinpath("calendars/day.txt")
self.future_path = self.qlib_dir.joinpath("calendars/day_future.txt")
self._calendar_list = self.calendar_list
_latest_date = self._calendar_list[-1]
self.start_date = _latest_date if start_date is None else pd.Timestamp(start_date)
self.end_date = _latest_date + pd.Timedelta(days=365 * 2) if end_date is None else pd.Timestamp(end_date)
@property
def calendar_list(self) -> List[pd.Timestamp]:
# load old calendar
if not self.calendar_path.exists():
raise ValueError(f"calendar does not exist: {self.calendar_path}")
calendar_df = pd.read_csv(self.calendar_path, header=None)
calendar_df.columns = ["date"]
calendar_df["date"] = pd.to_datetime(calendar_df["date"])
return calendar_df["date"].to_list()
def _format_datetime(self, datetime_d: [str, pd.Timestamp]):
datetime_d = pd.Timestamp(datetime_d)
return datetime_d.strftime(self.calendar_format)
def write_calendar(self, calendar: Iterable):
calendars_list = [self._format_datetime(x) for x in sorted(set(self.calendar_list + calendar))]
np.savetxt(self.future_path, calendars_list, fmt="%s", encoding="utf-8")
@abc.abstractmethod
def collector(self) -> Iterable[pd.Timestamp]:
"""
ReturnsView on GitHub (pinned to 79633dd950)
Solutions
- Point --qlib_dir at an existing qlib data directory containing calendars/day.txt (default ~/.qlib/qlib_data/cn_data).
- If no data dir exists yet, first download or bootstrap one (get_data.py or scripts/dump_bin.py) so calendars/day.txt is created.
- Verify with: ls <qlib_dir>/calendars/day.txt before running the collector.
Example fix
# before
run(qlib_dir='./cn_data', region='cn') # empty dir, no calendars/day.txt
# after
import os
assert os.path.exists(os.path.expanduser('~/.qlib/qlib_data/cn_data/calendars/day.txt')), 'run dump_bin first'
run(qlib_dir='~/.qlib/qlib_data/cn_data', region='cn') Defensive patterns
Strategy: validation
Validate before calling
from pathlib import Path
qlib_dir = Path(qlib_dir).expanduser()
if not (qlib_dir / 'calendars' / 'day.txt').exists():
raise SystemExit(f'{qlib_dir} is not an initialized qlib data dir (calendars/day.txt missing); run dump_bin or download data first') Prevention
- Standardize on one absolute qlib data path (e.g. ~/.qlib/qlib_data/cn_data) in all collector invocations.
- BootStrap the data directory (get_data/dump_bin) before any calendar-extension tooling.
When it happens
Trigger: Running `python future_calendar_collector.py collect --qlib_dir <dir> --region cn` where <dir> lacks calendars/day.txt — e.g. a fresh/empty directory, a typo in the path, or pointing at the qlib source tree instead of the data directory (~/.qlib/qlib_data/cn_data).
Common situations: First-time users who have not yet run `dump_bin.py`/downloaded cn_data before trying to extend the calendar; passing a relative path that resolves differently from the script's cwd (the code does Path(...).expanduser().absolute(), not resolve()); moving/renaming a data directory.
Related errors
- This type of input {rtype} is not supported
- User data for {} already exists
- No file is found.
- can't find a freq from {self.support_freq} that can resample
- This recorder is not saved in the local file system.
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/428f2704098dde16.
Report an issue: GitHub.