Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Forecasting with Moving Averages | Section
Forecasting With Classical Models

bookForecasting with Moving Averages

Svep för att visa menyn

To forecast future values in a time series, moving averages offer a simple yet effective approach. You can use a simple moving average (SMA) to predict the next value by averaging the most recent NN observations. The process for one-step-ahead forecasting with SMA involves the following steps:

  1. Choose the window size NN, which determines how many past values you will average;
  2. For each time point tt, calculate the average of the previous NN values: (xtN+1,xtN+2,...,xtx_{t-N+1}, x_{t-N+2}, ..., x_t);
  3. Use this average as the forecast for the next time point (t+1t+1);
  4. Slide the window forward by one period and repeat the process for each subsequent forecast.

While this method is easy to implement and understand, it has several limitations. Moving averages assume that recent values are the best predictors of the next value, which may not hold if there are trends or seasonality in the data. Furthermore, SMAs give equal weight to all NN values, potentially ignoring the relevance of more recent data. As a result, forecasts may lag behind actual changes, especially in volatile or non-stationary time series.

123456789101112131415161718
import pandas as pd # Example time series data data = [12, 14, 15, 16, 15, 17, 18, 20, 19, 21] N = 3 # Window size for SMA # Create a pandas Series ts = pd.Series(data) # Calculate the Simple Moving Average (SMA) sma = ts.rolling(window=N).mean() # Forecast the next value using the last N values last_n_values = ts[-N:] forecast = last_n_values.mean() print(f"Last {N} values: {list(last_n_values)}") print(f"Forecast for next value using SMA: {forecast:.2f}")
copy
question mark

Which of the following is a limitation of using simple moving averages for forecasting?

Select the correct answer

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 1. Kapitel 4

Fråga AI

expand

Fråga AI

ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

Avsnitt 1. Kapitel 4
some-alt