Foundations✓ Mathematical
◆ The PatternConverting between time granularities
Downsampling aggregates high-frequency data (e.g., ticks → daily). Upsampling fills gaps in lower-frequency data (e.g., monthly → daily with interpolation). Proper frequency alignment prevents lookahead bias and ensures your features match your target.
// Interactive — resampling effects
Target Frequency1x
# Python — resampling with pandas # Downsample: daily → weekly (OHLCV) weekly = df.resample('W').agg({ 'open': 'first', 'high': 'max', 'low': 'min', 'close': 'last', 'volume': 'sum' }) # Upsample: monthly → daily (forward fill) daily = monthly.resample('D').ffill()
Pattern bridge: Choosing the right frequency is the time-series equivalent of context window sizing in LLMs — too little history and you miss patterns, too much and you drown in noise. In markets, timeframe selection is this exact tradeoff.