Introduction to Time Series Forecasting
Time series data is everywhere—from the daily temperature readings that help meteorologists predict tomorrow's weather, to the stock prices that financial analysts monitor for investment decisions, to the sales figures that retailers use to manage inventory. At its core, a time series is simply a sequence of observations recorded over time, typically at regular intervals. However, this simplicity belies a rich structure and a set of unique challenges that make forecasting both a fascinating and a practical discipline. Unlike cross-sectional data, where each observation is independent, time series data points are intrinsically ordered and often exhibit temporal dependencies: what happened yesterday influences what happens today. This temporal dimension introduces autocorrelation, trends, seasonality, and other patterns that must be understood and modeled to produce accurate forecasts.
Consider a concrete example: a national electricity grid operator must forecast electricity demand for the next 24 hours to ensure sufficient generation capacity. The demand exhibits a clear daily pattern—peaks in the morning and evening, troughs at night—and a weekly pattern, with higher consumption on weekdays than weekends. Superimposed on these regular cycles is an underlying trend as population and electrification grow, plus irregular fluctuations due to weather events. To build a reliable forecasting system, one must decompose the series into these constituent components, account for their interactions, and quantify the uncertainty inherent in any projection into the future. This chapter will establish the foundational concepts necessary to approach such problems systematically.
What Exactly Constitutes a Time Series?
A time series is defined as a sequence of data points collected or recorded at successive points in time, spaced at uniform intervals. The key characteristics are:
1. Temporal ordering: The index of each observation is a timestamp (e.g., `2023-01-01 14:00:00`) or an ordinal time index (e.g., day 1, day 2, ...). This ordering is not merely a label; it carries causal information about potential dependencies. 2. Equispaced intervals: While some series may have irregular gaps (e.g., medical records), most forecasting methods assume regular sampling—hourly, daily, weekly, monthly, quarterly, etc. Irregular series often require preprocessing (e.g., aggregation or interpolation) to fit standard models. 3. Continuity: The series represents a continuous process, even if observations are discrete. There is an underlying stochastic process that generates the data.
Formally, let $X_t$ denote the value of the series at time $t$, where $t \in \mathbb{Z}$ (discrete time) or $t \in \mathbb{R}$ (continuous, but discretely observed). The entire series up to time $T$ is $\{X_1, X_2, \dots, X_T\}$. Forecasting aims to predict future values $X_{T+1}, X_{T+2}, \dots, X_{T+h}$ given historical data.
It is crucial to distinguish time series from simple sequences of numbers. A sequence of lottery numbers, though ordered, is typically independent and identically distributed (i.i.d.); there is no temporal dependency. In contrast, a time series like the daily closing price of a stock often exhibits autocorrelation: yesterday's price influences today's price through market momentum, information diffusion, and trader behavior. This dependency structure is what we model.
Types of Time Series Data
Time series can be categorized by the nature of the variable being measured:
- **Univariate**: A single variable recorded over time (e.g., daily temperature). Most introductory forecasting focuses on univariate series.
- **Multivariate**: Multiple variables recorded simultaneously over time, each with its own temporal pattern, but potentially cross-correlated (e.g., temperature, humidity, and wind speed measured hourly). This is also called **multivariate time series** or **panel data** when multiple similar series are observed (e.g., sales for many products). Note: In statistics, "multivariate" sometimes refers to multiple *response* variables at each time point; in forecasting, it often means multiple *related* series. We will clarify this in Chapter 3.
- **Longitudinal data**: Repeated observations on the same subject (e.g., a patient's blood pressure over months). Often irregularly spaced and with missing data. Closer to panel data.
Additionally, series can be:
- **Continuous**: The underlying process is continuous (e.g., temperature), but we sample discretely.
- **Discrete**: The variable itself takes discrete values (e.g., number of customers, count of events). Often modeled with Poisson or negative binomial distributions.
Why Forecasting Matters: Industry Applications
Time series forecasting is not just an academic exercise; it drives critical decisions across sectors. Let's examine three detailed cases that illustrate the diversity of problems and the stakes involved.
Retail and Supply Chain Management
A global e-commerce company like Amazon forecasts demand for millions of products across hundreds of fulfillment centers. The goal is to optimize inventory: minimize stockouts (lost sales) while avoiding overstock (holding costs, obsolescence). Consider a specific product: a bestselling novel.
- **Data**: Daily sales quantities for the past three years.
- **Patterns**:
- *Trend*: Sales may rise gradually as the book gains popularity, then decline.
- *Seasonality*: Strong weekly pattern (higher on weekends), annual pattern (holiday shopping spikes, e.g., Christmas, Black Friday).
- *Events*: Promotions, price discounts, or media appearances (e.g., movie adaptation) cause sudden, non-repeating spikes.
- *External factors*: Competitor releases, economic indicators, social media buzz.
- **Forecasting horizon**: Short-term (next 7 days for warehouse replenishment) and long-term (next quarter for procurement).
- **Challenges**: New products have no history (cold-start). Promotional effects are hard to quantify. The product lifecycle introduces structural breaks.
- **Impact**: A 10% improvement in forecast accuracy can save millions in logistics costs and boost revenue through better product availability.
Energy and Utilities
Electricity grid operators engage in load forecasting—predicting electricity demand. This is critical for balancing supply and demand in real time, as electricity cannot be easily stored at scale.
- **Data**: Hourly electricity consumption (in MWh) for a region, spanning several years.
- **Patterns**:
- *Intraday seasonality*: Two peaks daily—morning (7–10 AM) and evening (6–9 PM)—with a midday dip.
- *Weekly seasonality*: Lower demand on weekends.
- *Annual seasonality*: Higher in summer (air conditioning) and winter (heating), depending on climate.
- *Trend*: Gradual increase due to electrification of transport and heating.
- *Weather sensitivity*: Temperature, humidity, cloud cover, and wind speed are strong predictors. A heatwave can cause a dramatic spike.
- **Forecasting horizon**: From minutes (for real-time balancing) to weeks (for maintenance scheduling) to years (for infrastructure investment).
- **Challenges**: Extreme weather events cause outliers. Renewable integration adds volatility (solar and wind generation are intermittent and weather-dependent). The COVID-19 pandemic altered daily patterns (more residential load, less commercial).
- **Impact**: Accurate forecasts reduce the need for expensive peaking plants (e.g., gas turbines) and lower operational costs. Errors can lead to blackouts or wasted generation.
Finance and Algorithmic Trading
Predicting asset prices (stocks, forex, cryptocurrencies) is notoriously difficult due to market efficiency and high noise. Yet, short-term forecasting is attempted for high-frequency trading, risk management, and portfolio allocation.
- **Data**: Minute-by-minute or daily prices (open, high, low, close, volume) for a stock.
-