Window features include future returns
Review this Python sliding-window feature builder for next-day return prediction.
Backtests look unusually profitable. Find the bug.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1import numpy as np
2import pandas as pd
3
4def make_window_features(prices: pd.Series, window: int = 5):
5 feats, targets = [], []
6 p = prices.values
7 # predict next-day return from the trailing `window` returns
8 rets = np.diff(p) / p[:-1]
9 for i in range(window, len(rets)):
10 x = rets[i - window : i + 1] # trailing window of returns
11 y = rets[i + 1] if i + 1 < len(rets) else 0.0
12 feats.append(x)
13 targets.append(y)
14 return np.array(feats), np.array(targets)
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.