microsoft/qlib · error · ValueError
add date is not tradable date
Error message
add date is not tradable date
What it means
Raised by OnlineOperator.add_user when the computed add_date (last calendar date <= the given date) is not a tradable date. The user's strategy initialization is anchored to a real trading day, so the account start date must be in the calendar. Like error 311, the .format() call has no placeholder so the date is omitted from the message.
Source
Thrown at qlib/contrib/online/operator.py:86
"""Add a new user into the a folder to run 'online' module.
Parameters
----------
id : str
User id, should be unique.
config : str
The file path (yaml) of user config
path : str
Path to save user account.
date : str (YYYY-MM-DD)
The date that user account was added.
"""
create_user_folder(path)
qlib.init_from_yaml_conf(self.client)
um = UserManager(user_data_path=path)
add_date = D.calendar(end_time=date)[-1]
if not is_tradable_date(add_date):
raise ValueError("add date is not tradable date".format(add_date.date()))
um.add_user(user_id=id, config_file=config, add_date=add_date)
def remove_user(self, id, path):
"""Remove user from folder used in 'online' module.
Parameters
----------
id : str
User id, should be unique.
path : str
Path to save user account.
"""
um = UserManager(user_data_path=path)
um.remove_user(user_id=id)
def generate(self, date, path):
"""Generate order list that will be traded at 'date'.
View on GitHub (pinned to 79633dd950)
Solutions
- Pass a date that is a known trading day (check D.calendar() for the market).
- Roll back explicitly: add_date = D.calendar(end_time=date)[-1] in your own code and validate is_tradable_date(add_date) before calling add_user.
- Update/point at a qlib data dump whose calendar covers the requested date.
Example fix
# before op.add_user(id="u1", config=cfg, path=p, date="2021-10-02") # ValueError: add date is not tradable date # after from qlib.data import D d = D.calendar(end_time="2021-10-02")[-1] # last trading day <= date op.add_user(id="u1", config=cfg, path=p, date=str(d.date()))
Defensive patterns
Strategy: validation
Validate before calling
from qlib.data import D
from qlib.contrib.online.operator import is_tradable_date
d = D.calendar(end_time=date)[-1]
if not is_tradable_date(d):
raise RuntimeError(f"add date {d} not tradable; supply a trading day")
op.add_user(id=id, config=cfg, path=p, date=str(d.date())) Prevention
- Pre-compute the last trading day and validate tradability yourself before add_user.
- Keep a helper get_last_trading_day(date) used by all online entry points.
- Refresh the qlib data dump so the calendar covers current dates.
When it happens
Trigger: Calling op.add_user(id, config, path, date) where D.calendar(end_time=date)[-1] resolves to a non-trading day, or where the date is outside/edge-of the calendar such that the last element is not tradable per is_tradable_date.
Common situations: Adding users on weekends/holidays; calendar/data dump that ends before the requested date; suspended trading periods in the local calendar data.
Related errors
- trade date is not tradable date
- The account data is not newest! last trading date {}, today
- Cannot find user
- User {} has been loaded
- Cannot find user {}
AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15).
Data as JSON: /api/errors/155dfc70b3c1a18f.
Report an issue: GitHub.