#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 , compare:
- Biased signal (forward-looking MA at time ): average of
- Correct signal (backward-looking MA at time ): average of
Evaluate both at point (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…