Skip to content
QuantReadySign In
#435easyRisk

Look-Ahead Bias Detection

Time Limit: 2sMemory: 256MB

Problem

Look-ahead bias occurs when a backtest uses information that would not have been available at the time of the trading decision. A common example: computing a moving average signal using future prices.

Given a price series and window size kk, compare:

  • Biased signal (forward-looking MA at time tt): average of Pt,Pt+1,,Pt+k1P_t, P_{t+1}, \ldots, P_{t+k-1}
  • Correct signal (backward-looking MA at time tt): average of Ptk+1,Ptk+2,,PtP_{t-k+1}, P_{t-k+2}, \ldots, P_t

Evaluate both at point t=nkt = n - k (the last position where the forward window fits).

Input Format

Two lines:

  • Line 1: integer k (window size)
  • Line 2: comma-separated floats — price series

Output Format

Two space-separated values: biased_signal correct_signal, each to 4 decimal places.

Examples

Example 1
Input(Two lines:)
3
100,102,98,105,101,99,103,97,106,100
Output
101.0000 99.6667

At t=7: biased = (97+106+100)/3 = 101.0. Correct = (99+103+97)/3 = 99.6667.

Example 2
Input(Two lines:)
4
50,52,48,55,53,47,51,49
Output
50.0000 52.0000

At t=4: biased = (53+47+51+49)/4 = 50.0. Correct = (48+55+53+47)/4 = 50.75. Wait...

Constraints

  • First line has the window size k (2 to 10)
  • Second line has comma-separated price series (length n, where n >= 2k)
  • Evaluation point is t = n - k (the last position where the forward window fits)
  • Output the biased signal (forward MA) and correct signal (backward MA) to 4 decimal places
Loading interactive editor…