Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 5 — Smoothing and Trend Estimation

Real-world time series are often noisy.

Daily stock prices fluctuate constantly.

Macroeconomic indicators rise and fall irregularly.

Even when underlying trends exist, short-run variation can obscure them.

One of the central goals of time series analysis is therefore:

This chapter introduces several important smoothing and trend estimation methods.

We study:

The emphasis throughout is intuition-first and applications-oriented.

All these methods answer the same question: how do we separate signal from noise?


Learning Objectives

By the end of this chapter, you should be able to:


5.1 Why Smooth Data?

Many time series contain substantial short-run noise.

Examples include:

Random fluctuations can make it difficult to see broader patterns.


5.2 Signal and Noise

A useful conceptual framework is:

Observed Series=Signal+Noise\text{Observed Series} = \text{Signal} + \text{Noise}

where:

Example

Suppose stock prices fluctuate daily because of:

Despite this noise, the market may still exhibit:

Smoothing attempts to recover these underlying components.


5.3 Moving Averages

One of the simplest smoothing methods is the moving average.

A moving average replaces each observation with an average of nearby observations.

Simple Moving Average

A kk-period moving average is:

MAt=1ki=0k1xtiMA_t = \frac{1}{k} \sum_{i=0}^{k-1}x_{t-i}

where:


5.4 Example: 5-Day Moving Average

Suppose stock prices are:

DayPrice
1100
2102
3101
4104
5103

The 5-day moving average is:

100+102+101+104+1035=102\frac{100+102+101+104+103}{5} = 102

5.5 Moving Averages in Python

We now compute a moving average using Python.

import yfinance as yf
import matplotlib.pyplot as plt

aapl = yf.download("AAPL", start="2020-01-01", auto_adjust=False)

prices = aapl["Adj Close"]

ma50 = prices.rolling(50).mean()

plt.figure(figsize=(10,4))

plt.plot(prices, label="Price")

plt.plot(ma50, label="50-Day MA")

plt.legend()

plt.title("Apple Stock Price and 50-Day Moving Average")

plt.savefig("figs/ch5/MA.png", dpi=300, bbox_inches="tight")
plt.close()   # replace with plt.show()
Moving Average

5.6 Choosing the Window Length

The smoothing effect depends heavily on the window length.

Small Window

Large Window


5.7 Moving Averages as Filters

Moving averages act as filters.

They suppress:

At the same time, they preserve:

This becomes especially important in:


5.8 Exponential Smoothing

Moving averages assign equal weight to all observations inside the window.

Exponential smoothing instead assigns:

Simple Exponential Smoothing

The updating equation is:

x^t+1=αxt+(1α)x^t\hat x_{t+1} = \alpha x_t + (1-\alpha)\hat x_t

where:

Alternative Form (Error-Correction View)

The updating equation can also be written as:

x^t+1=x^t+α(xtx^t)\hat x_{t+1} = \hat x_t + \alpha(x_t - \hat x_t)

5.9 Interpreting the Smoothing Parameter

The parameter:

α\alpha

controls how quickly the model reacts to new information.

Large α\alpha

Small α\alpha


5.10 Exponential Smoothing in Python

import yfinance as yf
import matplotlib.pyplot as plt

aapl = yf.download("AAPL", start="2020-01-01", auto_adjust=False)

prices = aapl["Adj Close"]

ewma = prices.ewm(span=50).mean()

plt.figure(figsize=(10,4))

plt.plot(prices, label="Price")

plt.plot(ewma, label="EWMA")

plt.legend()

plt.title("Exponential Smoothing")

plt.savefig("figs/ch5/ema.png", dpi=300, bbox_inches="tight")
plt.close()   # replace with plt.show()
EMA

5.11 Forecasting Interpretation

Exponential smoothing is not only a smoothing method.

It is also a forecasting method.

The smoothed series itself becomes a forecast of future values.


5.12 Holt’s Method

Simple exponential smoothing works best when no trend exists.

But many economic time series trend through time.

Holt’s method extends exponential smoothing by modeling:

Holt Updating Equations

Level

t=αxt+(1α)(t1+bt1)\ell_t = \alpha x_t + (1-\alpha)(\ell_{t-1}+b_{t-1})

Trend

bt=β(tt1)+(1β)bt1b_t = \beta(\ell_t-\ell_{t-1}) + (1-\beta)b_{t-1}

5.13 Holt–Winters Method

Some time series contain:

Holt–Winters methods extend Holt’s method further to model seasonal structure.

Examples include:


5.14 Example: Seasonal Data

import pandas as pd
import matplotlib.pyplot as plt

url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/airline-passengers.csv"

df = pd.read_csv(url)

df["Passengers"].plot(figsize=(10,4))

plt.title("Monthly Airline Passengers")

plt.savefig("figs/ch5/airline.png", dpi=300, bbox_inches="tight")
plt.close()   # replace with plt.show()
Airline

5.15 Local Smoothing: LOESS

LOESS (Locally Weighted Scatterplot Smoothing) is a flexible smoothing method.

Instead of fitting one global trend, LOESS fits:


This makes LOESS useful when trends change gradually over time.


5.16 LOESS Example in Python

import numpy as np
import matplotlib.pyplot as plt
from statsmodels.nonparametric.smoothers_lowess import lowess

np.random.seed(123)

x = np.arange(200)

y = (
    0.05*x
    + np.sin(x/10)
    + np.random.normal(scale=1,size=200)
)

smooth = lowess(y, x, frac=0.1)

plt.figure(figsize=(10,4))

plt.plot(x, y, alpha=0.5)

plt.plot(smooth[:,0], smooth[:,1])

plt.title("LOESS Smoothing")

plt.savefig("figs/ch5/loess.png", dpi=300, bbox_inches="tight")
plt.close()   # replace with plt.show()
LOESS

5.17 Splines

Splines provide a flexible way to model smooth trends in a time series.

Instead of fitting a single curve to the entire dataset, splines divide the data into segments and fit simple curves to each part.


Intuition

A spline works like a flexible ruler:


Why Not Use One Polynomial?

Fitting a single high-degree polynomial can lead to:

Splines solve this by:


Role of Knots

Knots determine where the curve can change shape.


Comparison with Other Methods

MethodIdeaStrengthWeakness
Moving AverageSimple averagingEasy, intuitiveCan lag
Exponential SmoothingWeighted averageResponsiveStill global
LOESSLocal regressionVery flexibleComputationally heavier
SplinesPiecewise smooth polynomialsControlled flexibilityRequires choosing knots

When Are Splines Useful?

Splines are useful when:



5.18 The Hodrick–Prescott (HP) Filter

The HP filter is widely used in macroeconomics.

It decomposes a series into:

Decomposition

xt=τt+ctx_t = \tau_t + c_t

where:


5.19 HP Filter Example

import pandas_datareader.data as web
import matplotlib.pyplot as plt
from statsmodels.tsa.filters.hp_filter import hpfilter

gdp = web.DataReader(
    "MKTGDPTHA646NWDB",
    "fred",
    start="2000-01-01"
)

cycle, trend = hpfilter(gdp.squeeze(), lamb=400)

plt.figure(figsize=(10,4))

plt.plot(gdp, label="GDP")

plt.plot(trend, label="Trend")

plt.legend()

plt.title("HP Filter Trend")

plt.savefig("figs/ch5/hp.png", dpi=300, bbox_inches="tight")
plt.close()   # replace with plt.show()
HP Filter

5.20 The Smoothing Parameter in the HP Filter

The HP filter uses a parameter:

λ\lambda

which controls smoothness.

Large λ\lambda

Small λ\lambda


5.21 The Bias–Variance Trade-Off

Smoothing always involves compromise.

Too Little Smoothing

Too Much Smoothing


5.22 Smoothing and Forecasting

Smoothing methods are often used as forecasting tools.

Examples include:


5.23 Adjusted Prices and Trend Analysis

When working with financial prices, smoothing should usually be applied to:

Adjusted Close

rather than raw prices.

This becomes especially important in:


5.24 Smoothing and Trading Indicators

Many popular trading indicators are essentially smoothing methods.

Examples include:


5.25 Gretl Example: Moving Averages

Gretl provides simple tools for smoothing.


Step 1 — Open Data

Load a time series dataset.


Step 2 — Plot Series

Menu:

Variable → Time series plot

Step 3 — Add Moving Average

Menu:

Add → Moving average

Choose the window length.


[GRETL Screenshot Placeholder: Moving average dialog]

5.26 Gretl Example: HP Filter

Menu:

Variable → Filter → Hodrick-Prescott

Choose:


[GRETL Screenshot Placeholder: HP filter output]

5.27 Common Mistakes


5.28 Looking Ahead

This chapter introduced methods for smoothing and trend estimation.

The next chapter studies how many popular trading indicators can be understood as filtering and smoothing techniques.

We will examine:

Key Takeaways

Concept Check

Basic

  1. What is smoothing in time series analysis?

  2. What is the goal of trend estimation?

  3. What is the difference between signal and noise?


Intuition

  1. Why do we smooth time series data before analyzing it?

  2. What is the key idea behind exponential smoothing?

  3. Why might recent observations be more informative than older ones?


Intermediate

  1. What is the difference between:

    • moving average

    • exponential smoothing

    • LOESS

  2. What role do knots play in spline methods?

  3. What is the purpose of the HP filter?


Finance Connection

  1. What are adjusted prices?

  2. Why are adjusted prices important in financial time series?


Challenge

  1. What is the bias–variance trade-off?


Interpretation & Practice

  1. A heavily smoothed series looks very stable.

    • What is the advantage?

    • What information might be lost?


  1. A lightly smoothed series fluctuates a lot.

    • What problem does this create?

    • What type of noise might remain?


  1. A LOESS curve follows the data closely.

    • When is this useful?

    • When might it lead to overfitting?


  1. A spline model uses many knots.

    • What happens to flexibility?

    • What is the risk?


  1. The HP filter separates a series into trend and cycle.

    • What does the “cycle” represent?

    • Why might this be useful in macroeconomics?


Finance Interpretation

  1. A stock price shows a sudden drop due to a dividend payment.

    • What happens to the raw price?

    • Why do adjusted prices correct for this?


  1. A trader uses a very smooth trend estimate.

    • What type of strategy is this suited for?

    • Why might it miss short-term signals?


Challenge

  1. A model fits historical data very closely but performs poorly in forecasting.

    • What problem is this?

    • How is it related to the bias–variance trade-off?


Numerical Practice

Exponential Smoothing (Applied)

Consider the following data:

WeekSalesForecast
13939
24439
34040
44540
53841
64340.4
73940.92

The smoothing parameter is:

α=0.2\alpha = 0.2
  1. Verify the forecast for Week 3 using:

Ft+1=αAt+(1α)FtF_{t+1} = \alpha A_t + (1-\alpha) F_t
  1. Compute the forecast for Week 7.

  2. Why does the forecast change more slowly than the actual data?

  3. What would happen if:


Comparison Thinking

  1. Suppose you apply:

to the same dataset.


Challenge

  1. Suppose a model is extremely smooth and misses turning points.


  1. Suppose a model follows every fluctuation in the data.


Appendix 5A — Centered vs Trailing Moving Averages

A moving average may be:


Trailing Moving Average

Uses only past observations:

MAt=1ki=0k1xtiMA_t = \frac{1}{k} \sum_{i=0}^{k-1}x_{t-i}

This is common in forecasting and trading.


Centered Moving Average

Uses observations on both sides of tt.

Centered averages often produce smoother trend estimates but cannot be used in real-time forecasting.


Appendix 5B — Why “Exponential” Smoothing?

The name “exponential smoothing” comes from the fact that older observations receive exponentially decreasing weights.

Starting from:

x^t+1=αxt+(1α)x^t\hat x_{t+1} = \alpha x_t + (1-\alpha)\hat x_t

we can substitute recursively:

x^t=αxt1+(1α)x^t1\hat x_t = \alpha x_{t-1} + (1-\alpha)\hat x_{t-1}

Continuing this process yields:

x^t+1=αxt+α(1α)xt1+α(1α)2xt2+\hat x_{t+1} = \alpha x_t + \alpha(1-\alpha)x_{t-1} + \alpha(1-\alpha)^2 x_{t-2} + \cdots

Appendix 5C — Why Smoothing Can Distort Turning Points

Heavy smoothing reduces noise but may delay detection of:

This creates an important trade-off in practical forecasting and trading systems.