Skip to main content

Time Series Decomposition Demo

Explore trend and seasonality in a simple time series decomposition demo. Paste your data, choose a seasonal period and model, and see separate trend, seasonal, and residual components with interactive charts.

Last updated:
Formulas verified by Waqar Kaleem Khan, Lead AI Engineer
For educational purposes only - not for trading, forecasting, or financial advice

Configure Decomposition

Quick Start with Demo Data:

Examples: 7 (weekly in daily), 12 (yearly in monthly), 4 (yearly in quarterly)

Decompose a Time Series into Trend and Seasonality

Paste a simple time series, choose a seasonal period and model, and we'll show you separate trend, seasonal, and residual components with interactive charts. Great for learning time series concepts.

Getting Started:

  1. 1Enter your time series values (one per line or comma-separated)
  2. 2Choose the seasonal length (e.g., 12 for monthly data with yearly seasonality)
  3. 3Select additive or multiplicative model
  4. 4Click "Decompose Time Series" to see the breakdown

Pro tip: Try the demo presets to see how decomposition works with different patterns. This is a simple educational tool — not for forecasting or trading decisions.

Separating Trend From Seasonal Swing in Your Data

Revenue was up 12% in December, and the VP asks whether the business is actually growing or just riding the holiday bump. A raw chart cannot answer that — both the upward trend and the December spike live in the same line. Time series decomposition pulls the line apart into three layers: the trend (is the baseline rising, falling, or flat over months?), the seasonal component (how much does December reliably add every year?), and the residual (the noise left after removing both). Once those layers are separated, you can answer the VP’s question with a number instead of a shrug.

The mistake that derails most first attempts: eyeballing a peak and calling it “growth.” If December always adds 15% and this December added 12%, the trend actually slowed — the seasonal component just masked it. Decomposition strips the mask away so you see the underlying trajectory.

Picking the Right Period for Your Decomposition

The period tells the algorithm how many data points make up one full seasonal cycle. Monthly data with yearly seasonality uses period = 12. Daily data with weekly patterns uses period = 7. Hourly server logs with daily cycles use period = 24. Get the number wrong and the seasonal component absorbs part of the trend or vice versa — every downstream conclusion is then off.

If you are unsure of the period, plot the raw data and count the distance (in data points) between repeating peaks. An autocorrelation plot makes this mechanical: the first strong positive spike after the origin marks the period. For monthly sales data, the spike should appear at lag 12. If it appears at lag 6 instead, you may have a semi-annual pattern, or your data might have two overlapping cycles (quarterly promotions inside a yearly trend).

One trap: choosing a period longer than half your data length. Classical decomposition needs at least two full cycles to estimate seasonal indices reliably. Twelve months of monthly data (period = 12) gives exactly one cycle — not enough. You need at least 24 months, and 36 or more is much better. If your series is too short, the seasonal estimates will be noisy and the residuals will look patterned.

What the Residual Component Is Telling You

The residual is everything the model could not explain with trend and seasonality. If the decomposition did its job, the residual should look like random noise — no visible pattern, no autocorrelation, roughly centred at zero (additive) or at one (multiplicative). That is the sign that you extracted all the structure the data has to offer at this level of complexity.

Patterned residuals are the most useful diagnostic. If you see a clear wave in the residuals, you probably picked the wrong period or missed a second seasonal cycle (daily inside weekly, for example). If the residuals trend upward, the moving-average window was too short to capture a slowly bending trend. If specific months consistently show large residual spikes, there may be a holiday or event effect that the fixed seasonal index cannot represent.

Residuals also flag outliers. A single point with a residual three times the standard deviation of the rest is worth investigating — it could be a data error, a one-time promotion, or a system outage. Classical decomposition does not handle outliers; it simply dumps them into the residual. More advanced methods like STL apply robustness weights to downplay these spikes.

Additive or Multiplicative: Picking the Wrong Model

The seasonal swings in my data are getting bigger over time. Which model?
Multiplicative. In an additive model, the seasonal component adds a fixed amount each December — say, +$50k. In a multiplicative model, December multiplies the trend by a factor — say, 1.20. As the trend rises, 1.20× produces larger absolute swings. If your December spike was $10k in year one and $30k in year three (while the trend tripled), the pattern is multiplicative. A quick check: plot the data. If the seasonal envelope fans out like a trumpet, use multiplicative.

I used additive but the residuals show a pattern that follows the trend. What went wrong?
The additive model subtracted a constant seasonal value from a series whose seasonal swings grew with the level. The leftover growth shows up as patterned residuals — positive residuals in peak months, negative in troughs, scaling with the trend. Switch to multiplicative and the residuals should flatten.

Can I take the log and use additive instead of multiplicative?
Yes. log(Trend × Seasonal × Residual) = log(Trend) + log(Seasonal) + log(Residual), so a multiplicative model on the original scale becomes additive on the log scale. This is a common trick when your tooling supports only additive decomposition. Just remember to exponentiate the components when you present results.

Decomposition Interpretation Pitfalls

The trend line looks flat but the series is clearly rising. Why?
The moving-average window may be too wide, over-smoothing the trend and pushing the real movement into the residual. Try a narrower window. Alternatively, if the rise is entirely seasonal (every Q4 spikes, then drops back), the trend correctly shows no lasting change — the series bounces but never ratchets higher.

Trend strength is 85% and seasonality strength is 90%. Do they add up?
No. Strength measures are not additive shares of variance. Trend strength compares the variance of the detrended series to the original; seasonality strength compares the residual variance to the original. Both can be high simultaneously if the series is dominated by trend and a strong repeating cycle on top of it.

Can I use the decomposition output for forecasting?
Not directly. Classical decomposition describes the past — it does not extrapolate. The trend stops at the last data point, and the seasonal indices assume the pattern repeats unchanged. For forecasting you need a method that projects the trend forward (ARIMA, exponential smoothing, Prophet). But decomposition is a useful first step: it tells you what components to model.

The first and last few trend values are missing. Is that a bug?
No. The centred moving average needs data on both sides of each point. With period = 12, the first 6 and last 6 trend values cannot be computed because there are not enough neighbours. This is an inherent limitation of classical decomposition, not a software error.

Trend, Seasonal, and Residual Decomposition Equations

Two model forms and one trend estimator cover classical decomposition:

Additive model
Yt = Tt + St + Rt
Seasonal indices sum to ≈ 0 across one period
Multiplicative model
Yt = Tt × St × Rt
Seasonal indices average to ≈ 1 across one period
Trend via centred moving average
Tt = (1/m) × Σ Yt−k … Yt+k
where m = period (or period+1 if even, for odd window)
Null at first k and last k points (edge effect)

Units note: in the additive model, T, S, and R share the same units as Y. In the multiplicative model, T is in original units, S and R are dimensionless ratios (1.20 means 20% above trend).

Monthly SaaS Revenue Decomposition Walkthrough

Scenario: You have 36 months of MRR (monthly recurring revenue) for a B2B SaaS product. Revenue grows from $120k to $340k with visible Q4 spikes each year. The seasonal swings appear to grow with the level, so you choose multiplicative decomposition with period = 12.

Step 1 — Estimate trend.
A 13-point centred moving average (period = 12, made odd) smooths away the monthly noise. The trend line rises from about $135k in month 7 to $310k in month 30. The first 6 and last 6 trend values are null.

Step 2 — Detrend and compute seasonal indices.
Divide each observation by its trend value. Group the ratios by month position (January values together, February values together, and so on). Average each group and normalise so the 12 indices average to 1.0. Result: January index = 0.93 (7% below trend), November index = 1.08 (8% above), December index = 1.14 (14% above).

Step 3 — Compute residuals.
Residual = Original / (Trend × Seasonal). Most residual values cluster between 0.95 and 1.05 with no visible pattern — the decomposition captured the main structure. One month shows a residual of 1.18 — a pricing change that boosted revenue beyond the seasonal norm.

Step 4 — Narrate the result.
“Underlying MRR grew roughly 2.5× over three years. Q4 reliably adds 8–14% on top of trend, with December as the strongest month. After removing trend and seasonality, residuals are random except for one anomaly in month 22 — the mid-contract price increase. The business is genuinely growing, not just cycling.”

Sources

Hyndman & Athanasopoulos — Forecasting: Principles and Practice: Classical and STL decomposition methods with additive/multiplicative model selection.

NIST/SEMATECH — Seasonal Decomposition: Moving-average trend estimation and seasonal index computation.

statsmodels — seasonal_decompose: Python implementation of classical decomposition with additive and multiplicative options.

NCBI — Time Series Decomposition in Epidemiology: Practical decomposition application with residual diagnostics and model selection.

Frequently Asked Questions

What is the difference between additive and multiplicative decomposition?

In an additive model, the components add up: Original = Trend + Seasonal + Residual. This fits data where seasonal swings stay roughly the same size as the series rises or falls. In a multiplicative model, the components multiply: Original = Trend x Seasonal x Residual. That is a better fit when seasonal variation grows or shrinks with the overall level of the series.

How do I choose the right seasonal length?

The seasonal length should match your data's periodicity: use 7 for weekly patterns in daily data, 12 for yearly patterns in monthly data, 4 for yearly patterns in quarterly data, or 52 for yearly patterns in weekly data. If you are unsure, plot the data and count the number of periods between repeating peaks or troughs.

Why do the trend and seasonal components look strange near the edges?

This is called edge effect. The moving average used to estimate the trend needs values before and after each point. At the beginning and end of the series, there are not enough neighbors, so the trend cannot be computed there. That limitation is normal for simple decomposition methods.

Can I use this tool to forecast or trade stocks?

No, this is not a forecasting or trading tool. It breaks past data into trend, seasonality, and residual pieces so you can inspect structure in old values. Forecasting or trading requires a different workflow, better models, and real evaluation against future data.

What if my data has multiple seasonalities (e.g., daily + weekly)?

Then this demo is too simple for the job. It only separates one repeating pattern, so data with daily and weekly cycles, or weekly and yearly cycles, needs something like STL or another multi-seasonal method.

What do the trend and seasonality strength percentages mean?

Trend strength and seasonality strength (both 0-100%) show how much of the variance in the original series is explained by each component. High trend strength suggests a clear upward or downward direction. High seasonality strength suggests a clear repeating pattern. These values are approximations based on variance ratios rather than formal tests.

Why are my residuals not random / showing patterns?

If residuals still show patterns, the decomposition did not fully capture the structure of the series. Common reasons are the wrong seasonal length, the wrong model choice (additive vs multiplicative), multiple seasonalities, structural breaks, or outliers.

How many data points do I need?

Ideally, you should have at least two full seasonal cycles. For example, monthly data with yearly seasonality usually needs at least 24 months. With fewer points, the decomposition becomes unstable and the component estimates are much less trustworthy.

What algorithm does this tool use?

This tool uses classical decomposition with a centered moving average for trend estimation and averaging of detrended values for seasonal indices. It is intentionally simple and easy to inspect, but it is less flexible than modern methods such as STL or X-13 style workflows.

Is this tool suitable for business decisions?

Treat it as a teaching aid. If money, staffing, inventory, or operations decisions depend on the result, run the analysis in validated software and review the assumptions with someone who owns the data.

Explore More Data Science Tools

Build essential skills in data analysis, statistics, and operations research

Explore All Data Science & Operations Tools

How helpful was this calculator?