Skip to content
Tutorials Center
My learning

Topics

Lesson 10 of 40 ยท Components and Decomposition

Calendar Effects and Cycles

Handle working-day, holiday, leap-year and moving-holiday effects in time series, plus multiple seasonalities, cycles and how to tell a cycle from a season using the periodogram.

The calendar is not as regular as the tidy "12 months, 7 days" picture suggests. February is shorter than March, Easter moves every year, and a month can contain four or five weekends. These irregularities create calendar effects that a plain seasonal pattern cannot capture. This lesson shows how to measure and remove them, how to handle series with more than one season, and how to separate seasons from cycles.

Why calendar effects matter

Imagine monthly sales of a shop that is closed on Sundays. A month with five Sundays has fewer sales than one with four, whatever the demand. Seasonal figures cannot know this because the "extra Sunday" moves around. Such effects are:

  • Month length: total counts depend on the number of days (28 to 31).
  • Trading or working days: the number of Mondays, weekdays, weekends in the month.
  • Leap years: one more day in February every fourth year.
  • Holidays: fixed-date (New Year) or moving (Easter, Ramadan, Lunar New Year).

Month length and daily averages

The cheapest fix for count and sum data is to convert to a daily average by dividing by the number of days. After that, the length effect disappears.

Python Normalise monthly totals by month length

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The raw totals wobble between 2800 and 3100 even though nothing changed, while the per-day series is flat. A model fed the totals would waste its seasonal terms on February.

Trading-day regressors

For flows driven by weekdays, count how many of each weekday a month contains and use those counts as regressors.

Python Count weekdays per month and regress

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Regression on the weekday counts recovers the per-day sales of each weekday (the closed Sunday comes out near zero), so the model can adjust any month for its mix of days before looking at demand.

Holidays and moving events

Fixed-date holidays can be handled with dummy variables on the day. Moving holidays need a window around the event. A common design is a dummy for "the 7 days before Easter" because shopping rises ahead of the holiday. The effect often straddles two months, so the dummy should hold the number of affected days in each month.

In practice:

  1. Build a holiday calendar (the holidays package or a hand-made table).
  2. Create columns for the day of the event and for leading and trailing days.
  3. Add them to a regression, ARIMAX or tree model as exogenous inputs.
Python Holiday dummies with an event window

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

More than one seasonal period

Hourly electricity load has a daily wave (24) and a weekly wave (168). Daily web traffic has weekly (7) and yearly (365.25). Many classic methods only handle one period. Options include:

Approach Idea
Fourier terms for each period add sine/cosine columns per period to a regression or ARIMAX model
Seasonal dummies for the short period, Fourier for the long one mix as needed
MSTL (multiple STL) repeated STL passes, one per period; available in statsmodels
Tree/neural models with calendar features hour, weekday, month and day-of-year as inputs

Seasons versus cycles

A season has a fixed length, a cycle does not. The periodogram (the squared size of each frequency in a Fourier transform) shows which periods carry energy. A true season appears as a sharp peak at one frequency; a cycle appears as a broad hump.

Python Find the dominant period with a periodogram

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The two strongest peaks sit at periods 12 and 6, exactly the cycles we built in. If you do not know the period of a series, the periodogram is the quickest way to find it, and it also reveals harmonics such as the half-year wave above.

Practical advice

  • Prefer per-day or per-unit rates for sum data over raw totals.
  • Test whether a calendar effect is real before adding it: compare models with and without the regressor on held-out data.
  • Keep holiday definitions in one table shared by training and forecasting, including future holiday dates.
  • When cycles are irregular, do not force a seasonal period; use ARMA-type or machine learning models instead.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. A shop's monthly totals dip every February. What is the simplest first fix for the shorter month?

    Dividing by the number of days removes the month-length effect.
  2. 2. Why is Easter hard for ordinary seasonal models?

    A moving holiday does not repeat at a fixed position of the seasonal cycle, so it needs explicit regressors.
  3. 3. A periodogram of a monthly series has a sharp peak at period 12 and a smaller one at period 6. What does that tell you?

    Sharp peaks at fixed periods mean seasonality; the half-period peak is a harmonic that shapes the yearly curve.
  4. 4. How should holiday dummies be prepared for forecasting?

    Exogenous regressors must be known for the forecast horizon, and holiday calendars are.

Summary

  • Calendar effects are the irregular parts of the calendar: month length, weekday mix, leap years and holidays.
  • Use daily averages for month length and weekday counts or dummies for trading days.
  • Moving holidays need event windows that may cross month boundaries.
  • Multiple seasonalities call for Fourier terms, MSTL or calendar features in ML models.
  • The periodogram separates sharp seasonal peaks from broad cycles.

Next: Stationarity and Random Walks