microsoft/qlib · critical · ValueError

The account data is not newest! last trading date {}, today

Error message

The account data is not newest! last trading date {}, today {}

What it means

Raised in OnlineOperator.execute (the order-execution path) when the user account's last trading date (dates[0] from prepare()) does not equal the expected prediction date pred_date. Online execution assumes the account is fully synced up to the previous trading day; otherwise orders computed for stale scores could be executed against the wrong portfolio state.

Source

Thrown at qlib/contrib/online/operator.py:155

    def execute(self, date, exchange_config, path):
        """Execute the orderlist at 'date'.

        Parameters
        ----------
           date : str (YYYY-MM-DD)
               Trade date, that the generated order list will be traded.
           exchange_config: str
               The file path (yaml) of exchange config
           path : str
               Path to save user account.
        """
        um, pred_date, trade_date = self.init(self.client, path, date)
        for user_id, user in um.users.items():
            dates, trade_exchange = prepare(um, trade_date, user_id, exchange_config)
            executor = SimulatorExecutor(trade_exchange=trade_exchange)
            if str(dates[0].date()) != str(pred_date.date()):
                raise ValueError(
                    "The account data is not newest! last trading date {}, today {}".format(
                        dates[0].date(), trade_date.date()
                    )
                )

            # load and execute the order list
            # will not modify the trade_account after executing
            order_list = load_order_list(user_path=(pathlib.Path(path) / user_id), trade_date=trade_date)
            trade_info = executor.execute(order_list=order_list, trade_account=user.account, trade_date=trade_date)
            executor.save_executed_file_from_trade_info(
                trade_info=trade_info,
                user_path=(pathlib.Path(path) / user_id),
                trade_date=trade_date,
            )
            self.logger.info("execute order list at {} for {}".format(trade_date.date(), user_id))

    def update(self, date, path, type="SIM"):
        """Update account at 'date'.

View on GitHub (pinned to 79633dd950)

Solutions

  1. Catch up the account first: run the missed dates' execute/order cycle in chronological order until the account reaches pred_date, then run today's.
  2. If the state is acceptable to reset, remove and re-add the user (or restore from a fresh account) to realign dates.
  3. Schedule the online job reliably for every trading day so the account never falls behind.

Example fix

# before
op.execute(date="2021-10-11", ...)
# ValueError: The account data is not newest! last trading date 2021-09-30, today 2021-10-11

# after
# replay missed trading days in order, then run today
for d in ["2021-10-08", "2021-10-09", "2021-10-11"]:
    op.execute(date=d, ...)
Defensive patterns

Strategy: validation

Validate before calling

# before executing, verify the account is current
um, pred_date, trade_date = op.init(client, path, date)
for uid, user in um.users.items():
    dates, _ = prepare(um, trade_date, uid, exchange_config)
    if str(dates[0].date()) != str(pred_date.date()):
        raise RuntimeError(
            f"account {uid} stale (last={dates[0].date()}, need={pred_date.date()}); "
            "replay missed trading days first"
        )
op.execute(date=date, ...)

Try / catch

try:
    op.execute(date=date, ...)
except ValueError as e:
    if "not newest" in str(e):
        # determine missed dates from the message and replay them in order
        log.error("stale account; replay missed days: %s", e)
    raise

Prevention

When it happens

Trigger: Running execute() for trade_date when the user's saved account last_updated date is behind pred_date — e.g. the daily job was skipped for one or more days, or execute is called twice in a day after the account was already advanced.

Common situations: Missed scheduled runs (server down over a trading day); manually re-running or catching up execute() out of order; clock/timezone skew making 'today' resolve to a different trading date than the account state.

Related errors


AI-assisted analysis of microsoft/qlib@79633dd950 (2026-08-15). Data as JSON: /api/errors/a2652bb11741388d. Report an issue: GitHub.