Overview
A statistical forecasting pipeline for TSX stock prices that applies Seasonal-Trend decomposition (STL) and then fits an ARIMA model. It trains on monthly closes from 2006 to 2015 and forecasts into October 2016, the month I did the work, so the forecast can be checked against prices that had already happened.
Background
Time series was the core technical skill of my economics master’s, applied to Canadian real GDP and interest rates. What those courses skipped was a plain model-building procedure, and in particular the habit of holding out a test period. A model can follow every textbook step and still forecast badly. This project was my way of practising that habit on 141 months of S&P/TSX closes from Yahoo Finance Canada.
Methodology
1. STL decomposition. Splits the price series into trend, seasonal, and remainder components with Loess smoothing.
2. Stationarity check. Box plots of the remainder by month confirm the series is stationary, which ARIMA requires.
3. Train and test split. The remainder from January 2006 to December 2015 is the training set. Everything after is held out.
4. ARIMA fitting. An exhaustive search with auto.arima() selects ARIMA(5,0,0) for the remainder component.
5. Diagnostics. A Box-Ljung test on the residuals confirms the model has captured the autocorrelation structure.
6. Forecasting. Produces 9-month forecasts with 95% confidence intervals, plotted against the actual values in ggplot2.
What the forecast showed
The ARIMA fit tracked the training period closely. Into 2016 it came near the observed prices but over-predicted for the first months, then drifted under the actual values about six months out. That is the expected behaviour of a short-memory model, and it is why these forecasts are only trusted a few months ahead.

As a second opinion I fitted simple exponential smoothing with HoltWinters() on the raw prices over the same split. It fitted the training period well, forecast much like the ARIMA model, and its confidence band contained the observed 2016 prices. The two models agreeing was reassuring, though the honest next step would have been to compare them on prediction error rather than by eye.

Methodology
1. STL decomposition. Splits the price series into trend, seasonal, and remainder components with Loess smoothing.
2. Stationarity check. Box plots of the remainder by month confirm the series is stationary, which ARIMA requires.
3. ARIMA fitting. An exhaustive search with auto.arima() selects ARIMA(5,0,0) for the remainder component.
4. Diagnostics. A Box-Ljung test on the residuals confirms the model has captured the autocorrelation structure.
5. Forecasting. Produces 9-month forecasts with 95% confidence intervals, plotted against the actual values in ggplot2.
Tech Stack
- Language: R
- Modeling:
forecast(ARIMA), STL decomposition,HoltWinters(simple exponential smoothing) - Visualization:
ggplot2,Cairo - Data Processing:
dplyr,reshape