Multiple Seasonal-Trend Decomposition Based on Loess

The Multiple Seasonal-Trend Decomposition Based on Loess (MSTL) of Bandara, Hyndman and Bergmeir (2021) extends STL to a series with several seasonal patterns at once, such as daily data with a weekly and a yearly season.

The formula for the Multiple Seasonal-Trend Decomposition Based on Loess splits the series \(x_{t}\) into the trend \(T_{t}\), k seasonal parts \(S_{i , t}\) of \(m_{1} < \ldots < m_{k}\) periods and the remainder \(R_{t}\):

\[x_{t} = T_{t} + \sum_{i=1}^{k} S_{i,t} + R_{t}\]

It runs STL for each season in turn, from the shortest, on the series without the other seasonal parts, and repeats the round twice so that the seasons settle. The seasonally adjusted series is \(x_{t}\) minus every seasonal part.

Each season has its own part, which shows how much of the variation each pattern explains. Seasons whose lengths are multiples of each other, or a long season with few repetitions in the sample, are hard to separate.

Decompose every series into its trend, its seasonal pattern and the remainder, and give the seasonally adjusted series: how much of a move is the usual pattern of the time of year (or week) and how much is news.

A seasonal decomposition splits a series into a trend, the slow movement of its level; a seasonal part, the pattern that repeats every year, quarter or week; and a remainder, what neither explains. The series without its seasonal part is the seasonally adjusted series, the form in which statistical offices publish most macroeconomic data, as it shows whether a change is more than the usual pattern of the time of year. Seasonal patterns are strong in series published without seasonal adjustment, such as retail sales, employment, energy demand and consumer prices, and weak in the prices of liquid assets. The decompositions here are additive, the parts add up to the series, so a pattern that grows with the level of the series fits better on its logarithm. The trend and the season near the ends of the sample are the least certain and move as new data arrives.

Also known as: MSTL, multiple seasonal decomposition.

In the Finance Toolkit this is get_seasonal_decomposition with method="mstl", the same function as Seasonal Decomposition.

Example · Germany · 2015 to 2025

Install the Finance Toolkit with pip install financetoolkit -U, then call get_seasonal_decomposition:

from financetoolkit import Economics, Econometrics

economics = Economics(start_date="2015-01-01", end_date="2025-12-31")

consumer_prices = economics.get_consumer_price_index(
    countries=["Germany"], period="monthly"
)

econometrics = Econometrics(data=consumer_prices)

econometrics.get_seasonal_decomposition(method="mstl")["Germany"]

Which returns:

Using Your Own Data

get_seasonal_decomposition runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:

from financetoolkit import Economics, Econometrics

economics = Economics(start_date="2000-01-01")

unemployment = economics.get_unemployment_rate(
    countries=["United States", "Germany"], period="monthly"
)

econometrics = Econometrics(data=unemployment, changes="difference")

econometrics.get_seasonal_decomposition()

References

  • Paper Bandara, K., Hyndman, R.J. and Bergmeir, C. (2021). “MSTL: A Seasonal-Trend Decomposition Algorithm for Time Series with Multiple Seasonal Patterns.” arXiv:2107.13462.
  • Library Shares similar logic as statsmodels’ MSTL (Multiple Seasonal-Trend Decomposition Based on Loess)
Share