liveBook · Manning

Look-ahead bias

As explained in Applied Reinforcement Learning

Bias caused by using information that would not have been available at the time of a decision or prediction.

Look-ahead bias occurs when information unavailable at decision time influences a prediction or action. It can make a backtest look excellent while hiding performance that would vanish in live use. section 12.9.3

Prevent it through the design of the decision process:

  • Build the state from information available up to the decision time. section 12.9.3
  • Commit to the action before revealing the next period’s returns. section 12.4
  • Train on earlier data and evaluate on a later chronological holdout. section 12.9.3

A suspiciously strong backtest

An agent that sees tomorrow’s returns could hold assets that rise and avoid those that fall. In the cited test, this leak produced a Sharpe ratio above 20, versus 8.47 for the best honest mode; the apparent advantage would disappear when the future is unknown. section 12.9.3

Listing 12.4 The step function, ordered to prevent look-ahead (summarized)
def step_target_weights(self, target_w, action_name="custom"):
    target_w = np.asarray(target_w,
    ➥ dtype=np.float64).copy()
 
    turnover = 0.5 * np.sum(np.abs(target_w - self.weights))  #A
    transaction_cost = self.cfg.tx_cost_rate * turnover  #B
 
    next_ret = np.zeros(self.n_slots)
    next_ret[: self.n_assets] = self.returns[self.day + 1]  #C
    gross_return = float(np.dot(target_w, next_ret))  #D
 
    net_return = gross_return - transaction_cost
    self.value *= (1.0 + net_return)
    self.peak_value = max(self.peak_value, self.value)
    drawdown = self.value / self.peak_value - 1.0  #E
    
    grown = target_w * (1.0 + next_ret)
    denom = grown.sum()
    self.weights = grown / denom if denom >
    ➥ 1e-12 else target_w
 
    port_vol = float(np.std(self.returns_history)) if  
    ➥ len(self.returns_history) >= 2 else 0.0
    reward = (gross_return
              - transaction_cost
              - self.cfg.turnover_penalty_coef * turnover
              - self.cfg.drawdown_penalty_coef * (-drawdown)
              - self.cfg.vol_penalty_coef * port_vol) * 
              ➥ self.cfg.reward_scale  #F
 
    self.day += 1  #G
    self.step_count += 1
    done = self.step_count >= self.cfg.horizon
    return self._get_state(), float(reward), done, info

See how the step function calculates the next return only after the target allocation is set. section 12.4

How Applied Reinforcement Learning covers it

How deep it goes
Explains decision-time constraints, step ordering, and chronological splits without deriving a formal model.
Examples
Compares a leaked strategy using tomorrow’s returns with an honest backtest and reports their Sharpe ratios.
What you can do after
Diagnose and prevent leakage by restricting states to available data and enforcing action-before-outcome ordering.
How it connects
Connects look-ahead bias to data leakage, time-series modeling, reinforcement learning, and backtesting.

Also explained in

Compare how 2 books explain look-ahead bias →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Applied Reinforcement Learning. The section links point to the parts of the book it draws on.