Code Room
Code reviewHard
Question
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.
Learn the concepts
import numpy as npimport pandas as pd def make_window_features(prices: pd.Series, window: int = 5): feats, targets = [], [] p = prices.values # predict next-day return from the trailing `window` returns rets = np.diff(p) / p[:-1] for i in range(window, len(rets)): x = rets[i - window : i + 1] # trailing window of returns y = rets[i + 1] if i + 1 < len(rets) else 0.0 feats.append(x) targets.append(y) return np.array(feats), np.array(targets)Run or narrate your approach, then ask the coach.