05 — Foundations

Resampling & Frequency#

FoundationsStatistical
◆ 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
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.
Worked example

A day of +10% and a day of −10%: summing the returns says 0%, compounding says −1%. Summing log returns gives the right −1%. And a week of prices ending at 95 has a closing price of 95 but an average of 101.2: whether you take the last value, the mean, the sum or the maximum is a modelling decision.

Where it misleads
  • Downsampling with the wrong aggregate (mean of prices, sum of rates) silently changes what the series means.
  • Upsampling invents data points; forward-filling makes series look smoother and more autocorrelated than they are.
  • Calendar periods differ in length (months, trading days), which matters for sums and rates.
In code
daily = np.array([0.10, -0.10])                  # +10% then -10%
summed = daily.sum()
compounded = np.prod(1 + daily) - 1
log_sum = np.expm1(np.log1p(daily).sum())        # log returns add up correctly
prices = pd.Series([100, 102, 101, 108, 95], index=pd.date_range('2026-03-02', periods=5))
week = dict(last=prices.iloc[-1], mean=prices.mean())   # a weekly 'close' vs a weekly average
Python, in your browser — edit the code and run it again

Assumes import numpy as np and import pandas as pd. Each snippet simulates or makes up its own series, as the comments say.

The same idea with a library
# 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()
Sources
  • R. S. Tsay, Analysis of Financial Time Series (3rd ed.), Wiley, 2010 — simple versus log returns
  • pandas documentation, “Time series / date functionality: resampling”, pandas.pydata.org
  • Forecasting: Principles and Practice (3rd ed.), R. J. Hyndman & G. Athanasopoulos, OTexts, 2021

Last reviewed October 2026 · How this site checks its content · Report a mistake

Linked from 3
← Previous
Differencing
Open in the full reader, with the topic sidebar