Time Series
On this page

Book

20 Time Series

94 min read

20.1 Introduction

A time series is a set of observations ordered in time. Some examples of time series are:

  • daily pollution values in a city;
  • monthly temperature values ​​recorded in a city;
  • daily indices from the São Paulo Stock Exchange;
  • accidents that occurred on the highways of the city of São Paulo during a month.

itub3

The models used to describe time series are stochastic processes, that is, processes controlled by probabilistic laws.

We have in the literature a very large number of different models to describe the behavior of a particular series. The construction of these models depends on several factors, such as the behavior of the phenomenon or the a priori knowledge we have of its nature and the objective of the analysis.

20.1.1 Stationarity

A time series is said to be stationary when it develops in time randomly around a constant mean, reflecting some form of stable equilibrium. In practice, most of the series we find present some type of non-stationarity, for example, trend.

serieestacionaria

A series can be stationary for short or long periods, which implies a change in level and/or slope. The ARIMA class of models will be able to satisfactorily describe stationary series and non-stationary series that do not exhibit explosive behavior. This type of non-stationarity is called homogeneous, when the series can be stationary, fluctuating around a level for a certain time, then changing levels and fluctuating around a new level and so on, or changing slope.

Most statistical analysis procedures for time series assume that they are stationary, therefore, it will be necessary to transform the original data if they do not form a stationary series. The most common transformation consists of taking successive differences from the original series, until a stationary series is obtained. The first difference Z(t) is defined by

$$\Delta Z(t) = Z(t) - Z(t - 1)$$

So, the second difference is

$$\Delta^2 Z(t) = \Delta[\Delta Z(t)] = \Delta[Z(t) - Z(t - 1)]$$

$$\Delta^2 Z(t) = Z(t) - 2Z(t - 1) + Z(t - 2)$$

In general, the nth difference of Z(t) is

$$\Delta^n Z(t) = \Delta[\Delta^{n-1} Z(t)]$$

Normally, it will be enough to take one or two differences for the series to become stationary.

serienaoestacionaria

20.1.2 Stochastic Processes

Definition 1.2.1

Be $ T $ an arbitrary set. A stochastic process is a family $ Z = (Z(t), t \in T) $, such that, for each $ t \in T $, Z(t) is a random variable.

Under these conditions, a stochastic process is a family of random variables, which we assume to be defined in the same probability space (Ω, A, P). The set $ T $ is normally taken as the set of integers $ Z $ = {±1, ±2, ±3,…}.

To say that a stochastic process is specified, we need certain conditions. Be $ t_1 $, $ t_2 $,…, $ t_n $ any elements of $ T $ and let’s consider

$$F(z_1, \dots,z_n;t_1, \dots ,t_n) = P[Z(t_1) \le z_1, \dots ,Z(t_n) \le z_n]$$

So, the stochastic process $ Z = (Z(t), t \in T) $ will be specified if we know the finite-dimensional distributions, for all n ≥ 1. The distribution functions must satisfy the following two conditions:

  • (Symmetry Condition) for any $ j_1 $,…,$ j_n $, from indices 1,2,…,n we have:

$$F(z_{j_n}, \dots ,z_{j_1};t_1, \dots ,t_n) = F(z_1, \dots ,z_n;t_1, \dots ,t_n)$$

  • (Compatibility Condition) for m < n,

$$F(z_1, \dots ,z_m,+ \infty , \dots ,- \infty ;t_1, \dots ,t_m,t_{m+1}, \dots ,t_n) = F(z_1, \dots ,z_m;t_1, \dots ,t_m)$$

Exemplo 1.2.1

Consideramos {$ X_n $, n = 1,2,…} uma sequência de v.a. definidas no mesmo espaço amostral Ω. Aqui, $ T $ = {1,2,…} e temos um processo com parâmetro discreto, ou uma sequência aleatória. Para todo n ≥ 1, podemos escrever

$$P[X_1 = a_1, \dots , X_n = a_n] = P[X_1 = a_1]P[X_2 = a_2|X_1 = a_1] \times \dots \times$$

$$P[X_n = a_n|X_1 = a_1, \dots, X_{n-1} = a_{n-1}].$$

Aqui, os $ a_j $’s representam os estados do processo e o espaço dos estados pode ser tomado como o conjunto dos reais. O caso mais simples é aquele em que temos uma sequência {$ X_n $, n ≥ 1} de v.a. mutuamente independentes e neste caso temos

$$P[X_1 = a_1, \dots , X_n = a_n] = P[X_1 = a_1] \dots P[X_n = a_n].$$

Este exemplo é conhecido como Sequência Aleatória.

Exemplo 1.2.2

Considere uma sequência aleatória $ {\varepsilon_t \ge 1} $ com v.a. i.i.d. $ (\mu_{\varepsilon} , \sigma^2_{\varepsilon}) $. Defina a sequência

$$X_t = \varepsilon_1 + \dots + \varepsilon_t.$$

Segue-se que $ E(X_t) = t\mu_{\varepsilon} $ e $ Var(X_t) = t\sigma_{\varepsilon} $, ou seja, ambas dependem de t.

Esse exemplo é conhecido como Passeio Aleatório, e têm grande importância em econometria e finanças.

20.1.3 Processos Estácionarios

Dizemos que um processo é estacionário se todas as características do comportamento do processo não são alterados no tempo, ou seja, o processo se desenvolve no tempo em torno da média, de modo que a escolha de uma origem dos tempos não é importante.

Definição 1.3.1

Um processo estocástico $ Z = (Z(t), t \in T) $ diz-se estritamente estacionário se todas as distribuições finito-dimensionais permanecem as mesmas sob translações no tempo, ou seja,

$ F(z_1, \dots , z_n;t_1 + \tau , \dots , t_n + \tau) = F(z_1, \dots , z_n;t_1, \dots , t_n), $ para quaisquer $ t_1, \dots , t_{n +\tau} $ de $ T $.

Em particular, se um processo é estritamente estacionário significa que todas as distribuições unidimensionais são invariantes sob translações do tempo, logo a média $ \mu (t) $ e variância $ V(t) $ são constantes, isto é,

$ \mu (t) = \mu, \hspace{0.3cm} V(t) = \sigma^2, $ para todo $ t \in T $.

Definição 1.3.2

Dizemos que um processo estocástico $ Z(t) = (Z(t), t \in T) $ é fracamente estacionário ou estacionário de segunda ordem se e somente se

(i) $ E[Z(t)] = \mu (t) = \mu $, constante, para todo $ t \in T $;

(ii) $ E[Z^2(t)] < \infty $, para todo $ t \in T $;

(iii) $ \gamma (t_1,t_2) = Cov[Z(t_1), Z(t_2)] $ é uma função de $ |t_1 - t_2| $.

Denominaremos simplesmente por processo estacionário quando o processo for fracamente estacionário. Iremos tratar de modelos que são apropriados para os processos estacionários homogêneos, isto é, processos cujo nível e/ou inclinação mudam com o decorrer do tempo. Tais processos podem tornar-se estacionários por meio de diferenças sucessivas.

Definição 1.3.3

Um processo estocástico $ Z = (Z(t), t \in T) $ diz-se Gaussiano (ou normal) se para qualquer conjunto $ t_1 $,$ t_2 $,…,$ t_n $ de $ T $, as v.a. Z($ t_1 $),…,Z($ t_n $) tem distribuição normal n-variada.

Se um processo for Gaussiano (ou normal) ele será determinado pelas médias e covariâncias; em particular, se ele for estacionário de segunda ordem, ele será estritamente estacionário.

Função de Autocovariância

Seja $ (X_t, t \in Z) $ um processo estacionário real discreto de média zero, sua função de autocovariância (f.a.c.v.) é definida por $ \gamma_{\tau} = E[X_tX_{t + \tau}] $.

Proposição 1.3.1

A facv $ \gamma_{\tau} $ deve satisfazer as seguintes propriedades:

(i) $ \gamma_0 > 0 $;

(ii) $ \gamma_{-\tau} = \gamma_{\tau} $;

(iii) $ |\gamma_{\tau}| \le \gamma_o $;

(iv) $ \gamma_{\tau} $ is non-negative definite, such that $ \sum^{n}_{j = 1} \sum^{n}_{k = 1}a_ja_k\gamma_{\tau_j - \tau_k} \ge 0, $

for any real numbers $ a_1, \dots , a_n, $ and $ \tau_1, \dots , \tau_n $ of $ Z $.

Proof

(i) and (ii) follow immediately from the definition of $ \gamma_{\tau} $.

(iii) It is enough to note that

$$E[X_{t + \tau} \pm X_t]^2 = E[X^2_{t + \tau} \pm 2X_{t + \tau}X_t + X^2_t] \ge 0$$

but we know that

$$X^2_{t + \tau} \pm 2X_{t + \tau}X_t + X^2_t = \gamma^2 \pm 2\gamma_{\tau} + \sigma^2 \ge 0$$

i.e.

$$2\gamma_0 \pm 2\gamma_{\tau} \ge 0 \Longrightarrow |\gamma_{\tau}| \le \gamma_0$$

.

(iv) We have to

$$\sum_{j = 1}^{n} \sum_{k = 1}^{n} a_ja_k\gamma_{\tau_j - \tau_k} = \sum_{j = 1}^{n} \sum_{k = 1}^{n} a_ja_kE[X_{\tau_j}X_{\tau_k}] = E[\sum_{j = 1}^{n} a_jX_{\tau_j}]^2 \ge 0$$

Note that the facv of a stationary process tends to zero when $ |\tau| \rightarrow 0. $

Autocorrelation Function

The process autocorrelation function is defined by

$$\rho_{\tau} = \dfrac{\gamma_{\tau}}{\gamma_0}, \tau \in Z$$

and has the same properties as the autocovariance function $ \gamma_{\tau} $, except now we have $ \rho_0 = 1 $.

The autocorrelation function is used to identify a suitable model for the time series.

Example 1.3.1

Returning to Example 1.2.1, we have a random sequence. If v.a.$ X_1 $,$ X_2 $, … all have the same distribution, we will then have a sequence of independent and identically distributed v.a. In this case, the process $ X_n $ is stationary. Se $ E[X_n] = \mu $ and $ Var[X_n] = \sigma^2 $, for all $ n \ge 1 $, then we have

Screenshot_1

Therefore, it follows that $ \rho_{\tau} = 1 $, for $ \tau = 0 $ and $ \rho_{\tau} = 0 $, otherwise.

Example 1.3.2

Continuing Example 1.2.2 we have a Random Walk. So, we have to $ E[X_t] = t\mu_{\varepsilon} $ and $ Var[X_t] = t\sigma^2_{\varepsilon} $. We can note that this is a non-stationary process, as the mean and variance depend on t. Calculating the autocovariance function we have

$$Cov[X_t, X_{t - k}] = Cov[\varepsilon_1 + \dots + \varepsilon_{t-k} + \dots + \varepsilon_t , \varepsilon_1 + \dots + \varepsilon_{k-t}] = (t - k)\sigma_{\varepsilon}^2$$

Thus, the autocorrelation function becomes

$$\rho_t = \dfrac{t - k}{t}.$$

Delay Operator

Consider a process MA(q), we can express it using a delay operator, denoted by B, defined by

$$B^jX_t = X_{t-j}$$

So we can rewrite

Screenshot_4

$$X_t = (1 + \theta_1B + \theta_2B^2 + \cdots + \theta_qB^q)a_t = \theta(B)a_t$$

where $ \theta(B) $ is a polynomial of order q in B. We say that a process MA(q) is invertible if the roots of the equation

$$\theta (B) = 1 + \theta_1B + \theta_2B^2 + \cdots + \theta_qB^q = 0$$

are outside the unit circle, that is, given $ b_1, \dots, b_q $ solutions for $ \theta(B) = 0 $ then the process will be invertible if $ |b_j| > 1, j = 1,\dots,q $, we then say that the process is stationary.

In the case of an AR(p) process

$$X_t = \phi_0 + \phi_1X_{t-1} + \phi_pX_{t-p} + a_t$$

Using the result that an AR(p) process can be written as an infinite MA process with coefficients $ \omega_0 , \omega_1, \dots $, that is

$$X_t = \omega_0a_t + \omega_1a_{t-1} + \cdots = (\omega_0 + \omega_1B + \omega_2B^2 + \cdots)a_t = \omega(B)a_t$$

It follows that a process AR(p) will be stationary if $ \sum_j \omega_j^2 < \infty $. The $ \omega_j $ can be determined by

$$\omega_0 = 1$$

$$\omega_1 = \omega_0\phi_1$$

$$\omega_2 = \omega_1\phi_1 + \omega_0\phi_2$$

$$ \quad \vdots $$

$$\omega_i = \sum_{j=1}^i \omega_{i-j}\phi_j$$

In a mixed model ARMA(p,q), using the delay operator, we can write

$$X_t = \phi_1X_{t-1} + \cdots \phi_pX_{t-p} + a_t + \theta_1a_{t-1} + \cdots + \theta_qa_{t-q}$$

Screenshot_5

i.e.

$$\phi(B)X_t = \theta(B)a_t$$

The values of $ \phi_1, \dots, \phi_p $ that make the process stationary are such that the roots of $ \phi(B) = 0 $ are outside the unit circle. Similarly, the values of $ \theta_1, \dots, \theta_q $ that make the process invertible are such that the roots of $ \theta(B) = 0 $ are outside the unit circle.

Example 1.3.3

Consider an ARMA(1,1) process given by $ X_t = 0,7X_{t-1} + a_t + 0,6a_{t-1} $. Let’s analyze whether this process is stationary and invertible.

Writing in the form of delay operators we have

$$(1 - 0,7B)X_t = (1 + 0,6B^*)a_t$$

Screenshot_3

$$(1 - 0,7B) = 0 \quad \Longleftrightarrow \quad B = \dfrac{1}{0,7} = 1,43$$

Screenshot_2

We conclude that the process is stationary and inversible.

20.1.4 Stationarity Tests

Most of the resources for time series were created using the concept of stationarity in the series. A general way to analyze this fact is to study the existence of some root of the delay operators within the unit circle, simply called the unit root.

Therefore, we use hypothesis tests that, in general, have the following hypotheses:

$$H_0=\text{Existe pelo menos uma raiz dentro do círculo unitário}$$

$$H_1=\text{Não existem raízes dentro do círculo unitário}$$

We present below three unit root tests, each with its own particularities. In a general context, the ideal is to apply the tests together to be sure of the stationarity of the series.

20.1.4.1 Augmented Dickey-Fuller Test

The Augmented Dickey-Fuller test is known in the literature as the ADF test (Augmented Dickey-Fuller) and requires the study of the following regression:

$$\Delta y_t = \beta_1 + \beta_2t + \delta y_{t-1} + \sum^m_{i=1}\alpha_i \Delta y_{t-i} + \varepsilon_t$$

where $ \beta_1 $ is the intercept, also called drift of the series; $ \beta_2 $ is the trend coefficient; $ \delta $ is the unit root presence coefficient and m is the number of lags taken in the series.

In this case the null hypothesis is given by $H_0: \delta = 0$

We perform a regression of $ \Delta y_t $ in $ y_{t-1}, \Delta y_{t-1}, \dots, \Delta y_{t+p-1} $ and we calculate the T statistic given by

$$T = \dfrac{\hat{\delta}}{se(\hat{\delta})}$$

where $ \hat{\delta} $ is an estimator for $ \delta $ and, $ se(\hat{\delta}) $ is an estimator for the standard deviation of the error of $ \delta $.

The critical values of statistics $ T $ they were tabulated by Dickey and Fuller through Monte Carlo simulation and vary in the cases of presence of only the intercept, presence of only the trend and presence of both.

20.1.4.2 Phillips - Perron test

The Phillips - Perron test, known in the literature as the PP test, is a generalization of the Dickley - Fuller test for cases in which errors $ (\varepsilon_t)_{t \in \mathbb{Z}} $ are correlated and possibly heteroscedastic. So, let’s study the following regression

$$\Delta y_t = \beta_1 + \beta_2t + \delta y_{t-1} + \sum^m_{i=1}\alpha_i \Delta y_{t-i} + \varepsilon_t$$

In this case, the statistics $ Z $ is calculated by

$$Z = n \hat{\delta_n} - \dfrac{n^2\hat{\sigma}^2}{2s^2_n}\Bigg( \hat{\lambda_n}^2 - \hat{\gamma_{0,n}} \Bigg)$$

where

$$\hat{\gamma_{j,n}} = \dfrac{1}{n} \sum^n_{i=1+j} r_ir_{i-j}$$

$$\hat{\lambda_n}^2 = \hat{\gamma_{0,n}} + 2\sum^q_{j = 1}\Bigg(1 - \dfrac{j}{q+1}\Bigg) \hat{\gamma}_{j,n}$$

$$s^2_n = \dfrac{1}{n-k} \sum^n_{i = 1} r_i^2$$

in which $ r_i $ represents the residue in $ y_i $ using least squares estimators, k is the number of covariates in the regression and, q is the number of lags used to calculate $ \hat{\lambda}^2_n $.

Note that $ Z $ this is an adjustment to the Dickley - Fuller statistic. If the process is uncorrelated we have zero covariances and in this case, $ \hat{\lambda}^2_n = \hat{\gamma}_{0,n} $. If the process is not heteroscedastic we have $ se(\delta) = 1/n $ and then $ Z $ is given by

$$Z = n\hat{\delta}= \dfrac{\hat{\delta}}{se(\hat{\delta})}$$

that is, $ Z $ is the Dickley - Fuller statistic and therefore has the same distribution as the ADF test statistic, calculated by Dickley - Fuller through Monte Carlo simulation.

20.1.4.3 KPSS Test

Test created by Denis Kwiatkowski, Peter C. B. Phillips, Peter Schmidt and Yongcheol Shin, called KPSS test after their names, aims to determine stationarity in a time series.

The test hypotheses are

$ H_0 = $ “The series is stationary”

$ H_1 = $ “The series has a unit root”

Note that the hypotheses of this test are not the same as the Dickley - Fuller and Phillips - Perron tests for stationarity. The null hypothesis of this test is the same as the alternative hypotheses in the previous tests.

Be $ X_t, t = 1,2,\dots,N $ observations of a time series that we want to test for stationarity. Suppose we can decompose the series into trend, random walk and error components

$$X_t = \xi t + r_t + \varepsilon_t$$

where $ r_t $ It’s the random walk

$$r_t = r_{t-1} + \mu_t$$

with $ \mu_t $ i.i.d with zero mean and variance $ \sigma_{\mu}^2 $.

Consider now, $ e_t $, t = 1,2, … , N the residuals of a regression on y explained by the trend, random walk and intercept components. We denominate $ \hat{\sigma_{\varepsilon}}^2 $ an estimator for the error variance in this regression, that is, $ \hat{\sigma_{\varepsilon}}^2 = \dfrac{SQE}{N} $. We define the partial sum of the residuals by

$$S_t = \sum^t_{i = 1} e_t, \quad t = 1, 2, \dots, T$$

Then the test statistic is given by

$$LM = \sum^N_{t = 1} \dfrac{S_t^2}{N^2 \hat{\sigma}_{\varepsilon}^2}$$

It is possible to show that the statistics $ LM $ has a distribution that asymptotically converges to a Brownian Movement in which its critical values are tabulated.

For more details, access the article by Kwiatkowski, Phillips, Schmidt and Shin in the Journal of Econometrics in 1992.

20.1.5 Models for Time Series

We will study parametric models for time series, that is, models in which the number of parameters is finite.

In these models, the analysis is done in the time domain. The most frequently used are error (or regression) models, autoregressive and moving average models (ARMA) and integrated autoregressive and moving average models (ARIMA).

Error or regression models

We can write an observed time series in the following form

$ Z_t = f(t) + a_t, \quad t = 1, 2, \dots , N, $ where $ f(t) $ is called signal and $ a_t $ noise.

In this model the signal $ f(t) $ is a completely determined function of time and $ a_t $ is a random sequence, independent of $ f(t) $. It is assumed that the v.a. $ a_t $ are uncorrelated, have zero mean and constant variance, that is,

$$E[a_t] = 0, \forall t, \quad E[a^2_t] = \sigma^2_a, \forall t, \quad E[a_ta_s] = 0, s\neq t.$$

The series $ a_t $ with the above characteristics is known as white noise.

ARMA models

To describe the behavior of economic and social series, where the observed errors are autocorrelated, we use ARMA models. These models are useful in these cases, since the fact that they are autocorrelated influences the evolution of the process.

There are three particular cases of ARIMA models that we will study:

  1. autoregressive process of order p: AR(p);
  2. process of moving averages of order q: MA(q)
  3. autoregressive process and moving averages of orders p and q: ARMA(p,q).

We can generalize these processes appropriately by the so-called integrated autoregressive and moving average models of order p, d and q: ARIMA(p,d,q), where d represents the inclusion of a seasonal operator.

Note that we can describe the three processes through ARIMA. For example, an autoregressive process of order p, AR(p), can be written as ARIMA(p,0,0).

20.2 Trend and Seasonality

In an attempt to describe the behavior of a time series, we use the decomposition of the original series into three time series, trend, seasonality and a random component, also known as level.

Let {$ Z_t $, t = 1, … ,N} the observations of a time series. We can decompose $ Z_t $ in two forms.

Additive model

$$Z_t = T_t + S_t + a_t.$$

Multiplicative model

$$Z_t = T_t \ast S_t \ast a_t,$$

where $ T_t $ and $ S_t $represent the trend and seasonality, respectively, while $ a_t $ is a random component, with zero mean and variance $ \sigma_a^2 $.

The main objective will be to estimate $ S_t $ and $ T_t $ and construct a seasonally free or seasonally adjusted and detrended series. Estimating yourself $ S_t $ and $ T_t $ and subtracting from $ Z_t $ we will obtain an estimate of the random component $ a_t $.

In general, the components $ T_t $ and $ S_t $ they are closely related and the influence of the trend on the seasonal component can be very strong.

Suppose initially that the seasonal component is not present, then we will consider the following model

$$Z_t = T_t + a_t$$

where $ a_t $ is a random variable with zero mean and variance $ \sigma^2_a $. Some of the most used methods to estimate $ T_t $ consist of:

(i) fit a function of time, such as a polynomial or an exponential;

(ii) smooth the series values ​​around a point, to estimate the trend at that point;

(iii) smooth the series values ​​through successive adjustments of weighted least squares straight lines;

After estimating the trend in $ \hat T_t $ we can have the series trend-adjusted or trend-free,

$$Y_t = Z_t - \hat T_t.$$

A procedure that is commonly used to remove trends is to take successive differences from the original series until a stationary series is found.

$$\Delta Z_t = Z_t - Z_{t-1}$$

For more details on how to calculate a trend estimate $ \hat T_t $ see the book: Time series analysis (2006) / Pedro A. Morettin, Célia M. C. Toloi.

20.2.2 Tests for trend

There are some useful non-parametric tests to detect whether there is a trend in a set of observations. However, these tests are generally based on hypotheses that may not be verified in the case of a time series, for example, assuming that the observations are independent.

It is necessary to be aware if there is another component (such as $ S_t $) in the series, in addition to $ T_t $. We need to eliminate this component before testing $ T_t $, as there is a great influence of other components on the trend.

Therefore, caution is required when using these tests.

20.2.2.1 Wald Test - Wolfowitz

To be able to apply this test, we initially need the time series to be independent and identically distributed.

Let {Zt, t = 1, … , N} be a time series with N observations. Consider M being the median of the N observations of Zt. We assign each value of Zt the symbol “a” if it is greater than or equal to M, and “b” if it is less than M. So, we have that N = (“Na” points “a”) + (“Nb” points “b”). This way, we will have groups of observations marked with “a” and groups of observations marked with “b” throughout the time series. The total number of groups will be the test statistic, that is,

T = “total number of groups with equal symbols”.

We consider the following hypotheses:

$ H_0 = $ “There is no trend”

$ H_1 = $ “There is a trend”

We reject the null hypothesis H0 if we have a small number of groups with equal symbols, that is, if T is relatively small.

For values of Na and Nb greater than 20, we can use the Central Limit Theorem and approximate the distribution of T by a normal one, that is, $ T \sim N(\mu , \sigma^2) $, where

$$\mu = \dfrac{2N_aN_b}{N} + 1, $$

$$\sigma = \sqrt\dfrac{2N_aN_b(2N_aN_b - N)}{N^2(N-1)}.$$

Example 2.2.1.1

Consider the observations below regarding the IBOVESPA indexes in the period from September 1, 2009 to November 1, 2009.

t Index t Index
1 56176 12 60570
2 55706 13 60432
3 55582 14 60575
4 56258 15 61467
5 57504 16 61157
6 57898 17 60020
7 58153 18 60207
8 58460 19 61089
9 58448 20 61152
10 59082 21 61523
11 60088 22 60772

Series chart:

(image missing)

Results using Action:

(image missing)

Note that for this example the median is 60054 and therefore, we have T = 4 distinct groups with the same symbols. Applying the Wald-Wolfowitz test, we reject the null hypothesis with a confidence level above 99%.

.

Example 2.2.1.2

Observe below the graph of the time series of daily closing values of Petrobras shares in the period from July 10, 2007 to January 9, 2008, with a total of 123 observations.

(image missing)

Action Results:

(image missing)

We can do a graphical analysis and notice that this series has a trend. To confirm this analysis, the Wald-Wolfowitz test was applied and, therefore, we rejected the null hypothesis of no trend.

20.2.2.2 Cox-Stuart test

Consider a set of observations X1,x2,…,xN. We group observations into pairs (X1,X1+c), (X2,X2+c),…, (XN-c,XN), where c = N/2 if N is even and c = (N+1)/2 if N is odd. To each pair of observations we associate the sign “-” if Xi$ < $ Xi+c and the “+” sign if Xi$ > $ Xi+c, if Xi = Xi+c we eliminate this observation. Consider Nt the number of pairs where Xi$ \neq $ Xi+c. So, we want to test:

$$ H_0 = P(X_i < X_{i+c}) = P(X_i > X_{i+c}), \quad \forall i: \text{Não existe tendência}; $$

$$ H_1 = P(X_i < X_{i+c}) \neq P(X_i > X_{i+c}), \quad \forall i: \text{Existe tendência}. $$

Note that this is a two-sided test, where the test statistic is given by

T = Number of pairs with a “+” sign.

We used the binomial distribution to evaluate the test, with the parameters p = 0.5 and n = Nt with two-sided test hypotheses.

Example 2.2.2.1

Consider Example 2.2.1.1, where the observations below refer to the IBOVESPA indices in the period from September 1, 2009 to November 1, 2009.

t Index t Index
1 56176 12 60570
2 55706 13 60432
3 55582 14 60575
4 56258 15 61467
5 57504 16 61157
6 57898 17 60020
7 58153 18 60207
8 58460 19 61089
9 58448 20 61152
10 59082 21 61523
11 60088 22 60772

Series chart:

(image missing)

Results using Action:

(image missing)

Therefore, we reject the null hypothesis and conclude that there is a trend in the series.

.

Example 2.2.2.2

Using Example 2.2.1.2, observe below the graph of the time series of the daily closing values of Petrobras shares in the period from July 10, 2007 to January 9, 2008, with a total of 123 observations.

(image missing)

Results using Action:

(image missing)

In this example we have a total of pairs Nt = 62, that is, in all pairs (Xi, Xi+c), we have Xi$ < $ Xi+c for all i. Therefore, we reject the null hypothesis that the series has no trend.

20.2.2.3 Mann-Kendall Test

Let the observations be X1, X2,…,Xn of a time series. We can apply the Mann-Kendall test for trend only if the series is serially independent. Then, we want to test whether the observations in the series are independent and identically distributed, that is, we want to test the hypotheses

Screenshot_6

Therefore, under $H_0$ The test statistic is given by:

$$ S = \sum_{k=1}^{n-1} \sum_{j = k+1}^{n} sign(x_j - x_k)$$

where

Screenshot_7

It is possible to show that S is normally distributed, that is, $ S \sim N(\mu, \sigma^2) $ with

$$\mu = 0$$

$$\sigma^2 = \dfrac{n(n-1)(2n+5) - \sum^{P}_{j = 1} t_j(t_j -1)(2t_j + 5)}{18}$$

where n is the number of observations and, considering the case in which the series may have groups with equal observations, P is the number of groups with equal observations and tj is the number of equal observations in group j.

In the case where the number of observations is greater than 30, the test statistic is calculated by

Screenshot_8

Even for a number of observations less than 30, we can use the Z statistic to perform the test.

In a two-sided test, we do not reject the null hypothesis H0 for a given significance level $ \alpha $, if for the quantile $ Z_{\alpha /2} $ From a standard normal distribution we have $ |Z| \leq Z_{\alpha /2} $.

Example 2.2.3.1

Consider Example 2.2.1.1, the observations below refer to the IBOVESPA indices in the period from September 1, 2009 to November 1, 2009.

t Index t Index
1 56176 12 60570
2 55706 13 60432
3 55582 14 60575
4 56258 15 61467
5 57504 16 61157
6 57898 17 60020
7 58153 18 60207
8 58460 19 61089
9 58448 20 61152
10 59082 21 61523
11 60088 22 60772

Series chart:

(image missing)

Results using Action:

(image missing)

Therefore, we reject the null hypothesis of no trend in the series.

.

Example 2.2.3.2

Observe the time series graph below, in Example 2.2.1.2, the daily closing values of Petrobras shares in the period from July 10, 2007 to January 9, 2008, with a total of 123 observations.

(image missing)

Results using Action:

(image missing)

Analyzing the results, we reject the null hypothesis that the information is independent and identically distributed, that is, we reject that the series has no trend.

20.2.3 Seasonality

We say that a time series is seasonal when the phenomena that occur over time are repeated every identical period of time, that is, phenomena that occur daily at a certain time, every day, or in a certain month in every year. An easy example to visualize would be the increase in airline ticket sales every year-end, or even the increase in retail sales during the Christmas period.

Considering the time series composed of the three components $S_t$, $T_t$ and $a_t$, where $S_t$ is the seasonal component, we then want to find an estimator for $S_t$.

(image missing)

20.2.3.1 Deterministic seasonality

Deterministic seasonality is when we assume a regular and stable seasonal pattern over time, in this way we can predict seasonal behavior perfectly based on previous data.

Regression models are great for series that present this type of seasonality. Then, using the additive decomposition of the time series we have

$$ T_t = \sum^m_{j=0} \beta_j t^j$$

$$S_t = \sum_{j=0}^{12}\alpha_j d_{jt}$$

where $ d_{jt} $ are periodic variables. We are assuming constant seasonality, i.e. $ \alpha_j $ does not depend on t, therefore, for a deterministic seasonality with period 12 we have

Screenshot_9

So, we have

$$ \sum_{j = 1}^{12} d_{jt} = 1, \quad t = 1, \dots , N$$

such that the regression matrix is of rank m+12. Therefore, we need to impose the restriction below to obtain the complete model

$$\sum^{11}_{j = 1} \alpha_j = 0$$

Thus, the full rank model is given by

$$Z_t = \sum^m_{j = 0} \beta_j t^j + \sum^{11}_{j = 1} \alpha_j D_{jt} + a_t$$

such that

Screenshot_10

Now, from the model with full rank, we can use the least squares method to obtain the estimators of $ \alpha_j $ and $ \beta_j $.

20.2.3.2 Stochastic Seasonality

We say that a time series has stochastic seasonality when the seasonal component of the series varies over time. This procedure can be used and is normally used when we have a constant seasonal pattern.

Given the time series $ Z_t $, be it $ \hat{T_t} $ a previously calculated estimator for the trend, we consider the following time series

$$ Y_t = Z_t - \hat{T_t}.$$

Thus, considering the case in which we have a constant seasonal pattern, we will use $ Y_t $ to estimate $ S_t $. Initially, considering the data provided annually, we took the average of the months

$$\bar{Y_{.j}} = \frac{1}{n_j} \sum^{n_j}_{i = 1} Y_{ij}, \quad j= 1, \dots , 12;$$

In general, the sum of $ \bar{Y_{.j}} $ is not zero and therefore we take as estimates of the seasonal constants

$$\hat{S_j} = \bar{Y_{.j}} - \bar{Y}, \quad \hbox{onde} \quad \bar{Y} = \frac{1}{12} \sum^{12}_{j = 1} \bar{Y_{.j}}$$

Thus, the original series model $ Z_t $ can be written in additive form by

$$ Z_t = T_t + S_j + a_t$$

with t = 12i + j, i = 0, 1, … ,p-1, j = 1, … ,12, where p is the number of years.

Then the seasonality-free series can be written as

$$Z^{\ast_t} = Z_t - \hat{S_t}.$$

Example 2.3.2

Consider the AirPassengers time series that represents the number of passengers per month on an airline from 1949 to 1960.

It can be seen from the series graph that it has annual seasonality and therefore, we can obtain the seasonality-free series:

(image missing)

20.2.4 Tests for deterministic seasonality

Using the model for deterministic seasonality seen in section 20.2.3.1, we have

$$Z_t = \sum^m_{i=0}\beta_it^i + \sum^{n_j}_{j=1}\alpha_jD_{jt} + a_t$$

then, we say that there is no deterministic seasonality in the time series if the null hypothesis that all $ \alpha_j $ are null is not rejected, that is, if

$$H_0 : \alpha_1 = \dots = \alpha_{n_j} = 0$$

is not rejected.

We can use parametric and non-parametric methods to determine deterministic seasonality and, for any test, it is necessary to eliminate the trend from the series if it exists, that is, we will work with the series $ Y_t = Z_t - \hat{T_t} $.

20.2.4.1 Kruskal-Wallis test

Assuming a sample from a population, subdivided into k sets of samples of size $ n_j $ each, which varies depending on the series we are working on. For example, if the series is annual and we have monthly observations, that is, nj = 12 and k would represent the number of years.

So, we have the following samples

$$Y_{ij}, \quad j=1,\dots,k, \ \ i=1, \dots, n_j, \quad N = \sum^k_{j=1} n_j$$

We replace the observations Yij with their respective ranks among all N observations, we add all the ranks in each subgroup j, that is

$$R_{.j} = \sum^{n_j}_{i=1} R_{ij}, \quad j=1,\dots,k.$$

Thus, the statistic for the test is given by

$$H=\frac{\frac{12}{N(N+1)}\sum_{i=1}^kn_i\left(R_{i\cdot}-\frac{N+1}{2}\right)^2}{1-\frac{ \sum_{j=1}^g t_j^3-t_j}{N^3-N}}=\frac{\left(\frac{12}{N(N+1)}\sum_{i=1}^k \frac{R_i^2}{n_i} \right)-3(N+1)}{1-\frac{\sum_{j=1}^g t_j^3-t_j}{N^3-N}}$$

where t is the number of repeated observations in group j and g is the number of groups with repeated observations.

Under H0, for sufficiently large nj, or k $ \ge $ 4, the distribution of H can be approximated by a variable $ \chi^2 $ with k-1 degrees of freedom. Therefore, we reject the null hypothesis of no existence of deterministic seasonality if $ P_{h_0}(H \ge \chi^2_{(k-1), \alpha}) = \alpha $, such that $ \alpha $ is the significance level of the test.

Example 2.4.1

We consider again the AirPassengers time series from Example 2.3.2 and apply the Kruskal-Wallis test.

Year/Month Jan Feb Sea Apr May June Jul Aug Set out Nov Ten
1949 112 118 132 129 121 135 148 148 136 119 104 118
1950 115 126 141 135 125 149 170 170 158 133 114 140
1951 145 150 178 163 172 178 199 199 184 162 146 166
1952 171 180 193 181 183 218 230 242 209 191 172 194
1953 196 196 236 235 229 243 264 272 237 211 180 201
1954 204 188 235 227 234 264 302 293 259 229 203 229
1955 242 233 267 269 270 315 364 347 312 274 237 278
1956 284 277 317 313 318 374 413 405 355 306 271 306
1957 315 301 356 348 355 422 465 467 404 347 305 336
1958 340 318 362 348 363 435 491 505 404 359 310 337
1959 360 342 406 396 420 472 548 559 463 407 362 405
1960 417 391 419 461 472 535 622 606 508 461 390 432

So, we have

$$n_j = \hbox{número de meses} = 12, \quad j = 1,2,\dots,12$$

$$N = \sum^{12}_{j=1}n_j = 144$$

The positions of each observation are given in the table below

Year/month Jan Feb Sea Apr May June Jul Aug Set Oct Nov Ten
1949 2,0 5,5 12,0 11,0 8,0 14,5 21,5 21,5 16,0 7,0 1,0 5,5
1950 4,0 10,0 18,0 14,5 9,0 23,0 29,5 29,5 25,0 13,0 3,0 17,0
1951 19,0 24,0 34,5 27,0 32,5 34,5 47,5 47,5 40,0 26,0 20,0 28,0
1952 31,0 36,5 43,0 38,0 39,0 54,0 59,0 67,5 52,0 42,0 32,5 44,0
1953 45,5 45,5 64,0 62,5 57,0 69,0 71,5 77,0 65,5 53,0 36,5 49,0
1954 51,0 41,0 62,5 55,0 61,0 71,5 84,0 82,0 70,0 57,0 50,0 57,0
1955 67,5 60,0 73,0 74,0 75,0 91,5 112,0 100,5 89,0 78,0 65,5 80,0
1956 81,0 79,0 93,0 90,0 94,5 113,0 123,0 119,5 104,5 86,5 76,0 86,5
1957 91,5 83,0 106,0 102,5 104,5 127,0 133,0 134,0 117,5 100,5 85,0 96,0
1958 98,0 94,5 109,5 102,5 111,0 129,0 137,0 138,0 117,5 107,0 88,0 97,0
1959 108,0 99,0 121,0 116,0 126,0 135,5 141,0 142,0 132,0 122,0 109,5 119,5
1960 124,0 115,0 125,0 130,5 135,5 140,0 144,0 143,0 139,0 130,5 114,0 128,0

Using Action to perform the calculations we obtain:

(image missing)

Therefore, under $ H_0 $ we have $ P(H \ge \chi^2_{11, \alpha}) \approx 0 $ and we reject the null hypothesis that there is no deterministic seasonality.

20.2.4.2 Friedman test

Consider the time series $ Z_t $ such that we can interpret it in the form of the additive model $ Z_t = T_t + S_t + a_t $.

In order to apply the Friedman test for deterministic seasonality, we need to consider the trend-free series, that is, considering $ \hat{T_t} $ the estimator for the trend of the series, let’s work with the series

$$Y_t = Z_t - \hat{T_t}.$$

We divide the series into blocks of periods and calculate the rank of each observation in each block, for example, if we are analyzing a time series with monthly data for 20 years, we will test the seasonality in each month during the 20 years, so we have a period of 12 months and 20 blocks of periods.

Thus, the test statistic can be calculated by

$$H = \frac{12}{nk(k+1)}\sum_{j=1}^kR_{.j}^2 - 3n(k+1), \quad \hbox{onde} \ \ R_{,j} = \sum_{i=1}^nR_{ij},$$

where $ R_{ij} $ is the observation post $ Y_{ij} $ Within block i, n is the number of blocks and k is the period size. The distribution of H can be approximated by a distribution $ \chi^2 $ with k-1 degrees of freedom.

Example 2.4.1

We consider again the AirPassengers time series from Example 2.3.2 and apply the Friedman test.

Year/Month Jan Feb Sea Apr May June Jul Aug Set out Nov Ten
1949 112 118 132 129 121 135 148 148 136 119 104 118
1950 115 126 141 135 125 149 170 170 158 133 114 140
1951 145 150 178 163 172 178 199 199 184 162 146 166
1952 171 180 193 181 183 218 230 242 209 191 172 194
1953 196 196 236 235 229 243 264 272 237 211 180 201
1954 204 188 235 227 234 264 302 293 259 229 203 229
1955 242 233 267 269 270 315 364 347 312 274 237 278
1956 284 277 317 313 318 374 413 405 355 306 271 306
1957 315 301 356 348 355 422 465 467 404 347 305 336
1958 340 318 362 348 363 435 491 505 404 359 310 337
1959 360 342 406 396 420 472 548 559 463 407 362 405
1960 417 391 419 461 472 535 622 606 508 461 390 432

So, we have

$$n_j = \hbox{número de meses} = 12, \quad j = 1,2,\dots,12$$

$$N = \sum^{12}_{j=1}n_j = 144$$

The positions of each observation are given in the table below

Year/month Jan Feb Sea Apr May June Jul Aug Set Oct Nov Ten
1949 2,0 5,5 12,0 11,0 8,0 14,5 21,5 21,5 16,0 7,0 1,0 5,5
1950 4,0 10,0 18,0 14,5 9,0 23,0 29,5 29,5 25,0 13,0 3,0 17,0
1951 19,0 24,0 34,5 27,0 32,5 34,5 47,5 47,5 40,0 26,0 20,0 28,0
1952 31,0 36,5 43,0 38,0 39,0 54,0 59,0 67,5 52,0 42,0 32,5 44,0
1953 45,5 45,5 64,0 62,5 57,0 69,0 71,5 77,0 65,5 53,0 36,5 49,0
1954 51,0 41,0 62,5 55,0 61,0 71,5 84,0 82,0 70,0 57,0 50,0 57,0
1955 67,5 60,0 73,0 74,0 75,0 91,5 112,0 100,5 89,0 78,0 65,5 80,0
1956 81,0 79,0 93,0 90,0 94,5 113,0 123,0 119,5 104,5 86,5 76,0 86,5
1957 91,5 83,0 106,0 102,5 104,5 127,0 133,0 134,0 117,5 100,5 85,0 96,0
1958 98,0 94,5 109,5 102,5 111,0 129,0 137,0 138,0 117,5 107,0 88,0 97,0
1959 108,0 99,0 121,0 116,0 126,0 135,5 141,0 142,0 132,0 122,0 109,5 119,5
1960 124,0 115,0 125,0 130,5 135,5 140,0 144,0 143,0 139,0 130,5 114,0 128,0

Using Action to perform the calculations we obtain:

(image missing)

Therefore, under $ H_0 $ we have $ P(H \ge \chi^2_{11, \alpha}) \approx 0 $ and we reject the null hypothesis that there is no deterministic seasonality.

20.2.4.3 F Test

The test $ F $ to detect deterministic seasonality it is the same hypothesis test used to compare variances in a statistical model.

Consider the time series $ Z_t $ such that we can interpret it in the form of the additive model, in this case, we write the time series observations without the trend component in the following model

$$Y_{ij} = S_j + e_{ij}, \quad i = 1,\dots,n_j; \quad j=1,\dots, k.$$

where $ n_j $ is the size of the period to be considered and k is the number of blocks of periods, assuming $ e_{ij} \sim N(0, \sigma^2) $. The test statistics $ F $ can be written as

$$H = \frac{N - k}{k - 1}\frac{\sum_{j=1}^kn_j(\bar{Y_{.j}} - \bar{Y})^2}{\sum_{i=1}^k\sum_{j=1}^{n_j}(Y_{ij} - \bar{Y_{.j}})^2}, \quad \hbox{onde} \quad N = \sum_{j=1}^kn_j.$$

We approximate the distribution of H by a Fisher-Snedcor F with (k-1) and (N-k) degrees of freedom, that is, $ H \sim F(k-1,N-k) $.

Example 2.4.3

We again consider the AirPassengers time series from Example 2.3.2 and apply the F test for an analysis of variance.

The positions of each observation are given in the table below

Year/month Jan Feb Sea Apr May June Jul Aug Set Oct Nov Ten
1949 2,0 5,5 12,0 11,0 8,0 14,5 21,5 21,5 16,0 7,0 1,0 5,5
1950 4,0 10,0 18,0 14,5 9,0 23,0 29,5 29,5 25,0 13,0 3,0 17,0
1951 19,0 24,0 34,5 27,0 32,5 34,5 47,5 47,5 40,0 26,0 20,0 28,0
1952 31,0 36,5 43,0 38,0 39,0 54,0 59,0 67,5 52,0 42,0 32,5 44,0
1953 45,5 45,5 64,0 62,5 57,0 69,0 71,5 77,0 65,5 53,0 36,5 49,0
1954 51,0 41,0 62,5 55,0 61,0 71,5 84,0 82,0 70,0 57,0 50,0 57,0
1955 67,5 60,0 73,0 74,0 75,0 91,5 112,0 100,5 89,0 78,0 65,5 80,0
1956 81,0 79,0 93,0 90,0 94,5 113,0 123,0 119,5 104,5 86,5 76,0 86,5
1957 91,5 83,0 106,0 102,5 104,5 127,0 133,0 134,0 117,5 100,5 85,0 96,0
1958 98,0 94,5 109,5 102,5 111,0 129,0 137,0 138,0 117,5 107,0 88,0 97,0
1959 108,0 99,0 121,0 116,0 126,0 135,5 141,0 142,0 132,0 122,0 109,5 119,5
1960 124,0 115,0 125,0 130,5 135,5 140,0 144,0 143,0 139,0 130,5 114,0 128,0

Therefore, we have

$$\sum_{j=1}^{12}12(\bar{Y_{.j}} - \bar{Y})^2 = 211306,90$$

$$\sum_{j=1}^{12}\sum_{i=1}^{12}(Y_{ij} - \bar{Y_{.j}})^2 = 58286,99$$

$$H = \frac{144 - 12}{12 - 1}*\frac{211306,90}{58286,99} = 43,50$$

Using Action we obtain the same result:

(image missing)

Using the F distribution table for a significance level of $ \alpha = 0,05 $, we have $ F_{(11, 132, \alpha=0,05)} = 1,86 $. Therefore, we reject the null hypothesis that the series does not have deterministic seasonality.

20.3 Exponential Smoothing Models

Smoothing models are a large class of forecasting methods that are based on the idea that past observations contain information about the pattern of the time series. The purpose of the methods is to distinguish a pattern of behavior from any other noise that may be contained in the observations of the series and then use this pattern to predict future values ​​of the series.

20.3.1 Simple Moving Averages (SMA)

Consider the time series $ Z_1 $, $ Z_2 $, … , $ Z_n $, stationary and locally constant, composed of its level and another random noise as follows

$$Z_t = \mu_t + a_t, \quad t=1,\dots,N$$

where E(at) = 0, Var(at) = $ \sigma_a^2 $ and $ \mu_t $ is an unknown parameter that varies over time.

The moving average technique consists of calculating the arithmetic mean of the k most recent observations, i.e.

$$M_t = \frac{Z_t + Z_{t-1} + \dots + Z_{t-k+1}}{k} = M_{t-1} + \frac{Z_t - Z_{t-k}}{k}$$

We denote k as the length of the mean.

In this way, $ M_t $ is an estimate of the level $ \mu_t $ which does not take into account older observations. Note that in each period the oldest observation is replaced by the most recent, calculating a new average.

Therefore, the prediction of h future values is given by the last calculated moving average, i.e.

$$\hat{Z_t}(h) = M_t,$$

or even

$$\hat{Z_t}(h)= \hat{Z_{t-1}}(h+1) + \frac{Z_t - Z_{t-k}}{k}, \quad \forall h > 0.$$

We can see that the above equation corrects the prediction of $ Z_{t+h} $ at each instant, that is, at each new observation in the series, $ Z_{t+h} $ is updated.

Assuming that $ a_t \sim N(0,\sigma_a^2) $, we can say that $ \hat{Z_t}(h) \sim N(\mu,\frac{\sigma_a^2}{k}) $ and construct a confidence interval with significance level \alpha, given by

$$\Bigg(\hat{Z_t}(h) - z_{\alpha}\frac{\sigma_a}{\sqrt{k}} ; \hat{Z_t}(h) + z_{\alpha}\frac{\sigma_a}{\sqrt{k}}\Bigg),$$

where $ z_{\alpha} $ is the quantile of a standard normal distribution, with a significance level $ \alpha $.

Example 3.1.1

Be $ Z_t $ a time series referring to the annual average temperatures in New York City during the years 1912 and 1971. Let’s fit an MMS model to this time series and try to predict the temperature for the next 6 years.

Year Temperature Year Temperature Year Temperature
1912 49,9 1932 51,8 1952 53,1
1913 52,3 1933 51,1 1953 54,6
1914 49,4 1934 49,8 1954 52
1915 51,1 1935 50,2 1955 52
1916 49,4 1936 50,4 1956 50,9
1917 47,9 1937 51,6 1957 52,6
1918 49,8 1938 51,8 1958 50,2
1919 50,9 1939 50,9 1959 52,6
1920 49,3 1940 48,8 1960 51,6
1921 51,9 1941 51,7 1961 51,9
1922 50,8 1942 51 1962 50,5
1923 49,6 1943 50,6 1963 50,9
1924 49,3 1944 51,7 1964 51,7
1925 50,6 1945 51,5 1965 51,4
1926 48,4 1946 52,1 1966 51,7
1927 50,7 1947 51,3 1967 50,8
1928 50,9 1948 51 1968 51,9
1929 50,6 1949 54 1969 51,8
1930 51,5 1950 51,4 1970 51,9
1931 52,8 1951 52,7 1971 53

Using , we obtain the following results for an MMS fit with mean length k = 3

(there are missing elements in the equation above)

(image missing)

(image missing)

Thus, predictions with a 95% confidence interval are given by:

(image missing)

20.3.2 Simple Exponential Smoothing (SES)

Be $ Z_1 $,$ Z_2 $, … ,$ Z_n $ a stationary time series. We can describe an SES by

$$\bar{Z_t} = \alpha\sum_{j=0}^{t-1}(1- \alpha)^jZ_{t-j} + (1-\alpha)^t\bar{Z}_0, \quad t=1,\dots,N,$$

where $ \bar{Z_t} $ is called exponentially smoothed value and $ \alpha $ is the smoothing constant, such that $ 0 \le \alpha \le 1 $.

Expanding the above equation we have

$$\bar{Z_t} = \alpha Z_t + \alpha(1-\alpha)Z_{t-1} + \alpha(1-\alpha)^2Z_{t-2} + \dots$$

Therefore, we can conclude that the SES is a weighted average that gives greater weight to the most recent observations, eliminating one of the disadvantages of the MMS method.

The prediction of h future values is given by the last exponentially smoothed value, i.e.

$$\hat{Z}(h) = \bar{Z_t}, \quad \forall h$$

$$\hat{Z}(h) = \alpha Z_t + (1 - \alpha)\hat{Z_{t-1}}(h+1)$$

Assuming $ a_t \sim N(0,\sigma_a^2) $, we can construct an asymptotic confidence interval for $ Z_{t+h} $, given by

$$\Bigg(\hat{Z_t}(h) - z_{\gamma}\sigma_a\sqrt{\frac{\alpha}{2 - \alpha}} \ ; \ \hat{Z_t}(h) + z_{\gamma}\sigma_a\sqrt{\frac{\alpha}{2 - \alpha}}\Bigg)$$

where $ z_{\gamma} $ is the quantile of a standard normal distribution with significance level $ \gamma $.

Example 3.2.1

Consider the AirPassengers time series that represents the number of passengers at an airport over time. Let’s fit an SES model to this data.

Year/Month Jan Feb Sea Apr May June Jul Aug Set out Nov Ten
1949 112 118 132 129 121 135 148 148 136 119 104 118
1950 115 126 141 135 125 149 170 170 158 133 114 140
1951 145 150 178 163 172 178 199 199 184 162 146 166
1952 171 180 193 181 183 218 230 242 209 191 172 194
1953 196 196 236 235 229 243 264 272 237 211 180 201
1954 204 188 235 227 234 264 302 293 259 229 203 229
1955 242 233 267 269 270 315 364 347 312 274 237 278
1956 284 277 317 313 318 374 413 405 355 306 271 306
1957 315 301 356 348 355 422 465 467 404 347 305 336
1958 340 318 362 348 363 435 491 505 404 359 310 337
1959 360 342 406 396 420 472 548 559 463 407 362 405
1960 417 391 419 461 472 535 622 606 508 461 390 432

Thus, using Action to perform the calculations, we obtain the results:

(there are missing elements in the equation above)

(image missing)

(image missing)

(image missing)

The forecast will be 432 people in January 1961. Note that this type of forecast is not effective for more than one step in the future, because due to its forecast formula the value is repeated consecutively, regardless of the value of the smoothing constant $ \alpha $.

20.3.3 Exponential Holt Smoothing (SEH)

This smoothing technique is recommended for series that show a trend. Consider the case of a time series that is locally composed of the sum of level, trend and residual with zero mean and constant variance. $ \sigma_a^2 $, that is

$$Z_t = \mu_t + T_t + a_t, \quad t = 1, \dots , N$$

This technique is similar to Simple Exponential Smoothing (SES) with an extra constant to model the trend component. The level and trend values of the series will be estimated by

$$\bar{Z_t} = AZ_t + (1-A)(\bar{Z_{t-1}} + \hat{T_{t-1}}), \quad 0< A < 1 \quad e \quad t = 2, \dots , N,$$

$$\hat{T_t} = C(\bar{Z_t} - \bar{Z_{t-1}}) + (1-C)\hat{T_{t-1}}, \quad 0 < C < 1 \quad e \quad t = 2, \dots , N$$

where A and C are called smoothing constants, such that $ A \ge C $.

Therefore, the prediction of the value $ Z_{t+h} $ with origin at t is given by

$$\hat{Z_t}(h) = \bar{Z_t} + h\hat{T_t} \quad \forall h > 0$$

Example 3.3.1

Consider the same time series as in example 3.2.1, let’s try to predict the number of passengers on the airline for the next 6 years.

Year/Month Jan Feb Sea Apr May June Jul Aug Set out Nov Ten
1949 112 118 132 129 121 135 148 148 136 119 104 118
1950 115 126 141 135 125 149 170 170 158 133 114 140
1951 145 150 178 163 172 178 199 199 184 162 146 166
1952 171 180 193 181 183 218 230 242 209 191 172 194
1953 196 196 236 235 229 243 264 272 237 211 180 201
1954 204 188 235 227 234 264 302 293 259 229 203 229
1955 242 233 267 269 270 315 364 347 312 274 237 278
1956 284 277 317 313 318 374 413 405 355 306 271 306
1957 315 301 356 348 355 422 465 467 404 347 305 336
1958 340 318 362 348 363 435 491 505 404 359 310 337
1959 360 342 406 396 420 472 548 559 463 407 362 405
1960 417 391 419 461 472 535 622 606 508 461 390 432

Thus, using Action to perform the calculations, we obtain the results:

(there are missing elements in the equation above)

(image missing)

(image missing)

(image missing)

Note that this smoothing model is the most suitable when the predominant factor in the time series is the trend, as it is the model’s differentiator, using the trend to differentiate and bring the forecasts closer together.

20.3.4 Holt Exponential Smoothing - Winters (HW)

In the case of series that present a slightly more complex behavior, such as seasonality, we use other forms of smoothing such as the Holt - Winters method.

This technique involves three equations with three smoothing parameters that are associated with each component of the series: level, trend and seasonality.

Therefore, we have two cases to consider

Multiplicative Seasonal Series

Consider a seasonal series with period p. The most common variant of the HW method considers the seasonal factor $ S_t $ as being multiplicative, while the trend remains additive, i.e.

$$Z_t = \mu_t S_t + T_t + a_t, \quad t = 1, \dots , N.$$

And so, we calculate the three smoothing equations by

$$\hat{S_t} = D\Bigg(\frac{Z_t}{\bar{Z_t}}\Bigg) + (1-D)\hat{S}_{t-p}, \quad 0 < D < 1,$$

$$\bar{Z_t} = A\Bigg(\frac{Z_t}{\hat{S_{t-s}}}\Bigg) + (1-A)(\bar{Z_{t-1}} + \hat{T_{t-1}}), \quad 0 < A < 1,$$

$$\hat{T_t} = C(\bar{Z_t} - \bar{Z_{t-1}}) + (1-C)\hat{T_{t-1}}, \quad, 0 < C < 1,$$

which represent estimates of the seasonal factor, level and trend, respectively; where A, C and D are the smoothing constants.

A prediction of h steps ahead using the Multiplicative model can be found using the following formula

$$\hat{Z}(h) = (\bar{Z_t} + h\hat{T_t})\hat{S_{t+h-p}}, \quad h= 1, 2, \dots , p,$$

$$\hat{Z}(h) = (\bar{Z_t} + h\hat{T_t})\hat{S_{t+h-2p}}, \quad h= p+1, \dots , 2p,$$

$$\vdots \quad \quad \quad \quad \quad \vdots$$

where $ \bar{Z_t} $, $ \hat{S_t} $ and $ \hat{T_t} $ are given by the equations above. To update forecasts when we have a new observation $ Z_{t+1} $ we just need to do the same procedures with the new observation and going back one step in the prediction, that is

$$\hat{Z_{t+1}}(h-1) = (\bar{Z_{t+1}} + (h-1)\hat{T_{t+1}})\hat{S}_{t+1+h-p}, \quad h= 1, 2, \dots , p+1,$$

$$\hat{Z_{t+1}}(h-1) = (\bar{Z_{t+1}} + (h-1)\hat{T_{t+1}})\hat{S}_{t+1+h-2p}, \quad h= p+2, \dots , 2p+1,$$

For an initial value of the recurrence equations, we use the following formulas

$$\hat{S_j} = \frac{Z_j}{(\frac{1}{p})\sum_{k=1}^{p}Z_k}, \quad j = 1,2,\dots , p; \quad \quad \bar{Z}_p = \frac{1}{p}\sum_{k=1}^pZ_k; \quad \quad \hat{T}_p = 0.$$

Additive Seasonal Series

In this case, the series is composed of

$$Z_t = \mu_t + T_t + S_t + a_t $$

And therefore, we can calculate the smoothing equations by

$$\hat{S_t} = D(Z_t - \hat{Z_t}) + (1-D)\hat{S_{t-s}} , \quad 0 < D < 1,$$

$$\bar{Z_t} = A(Z_t - \hat{S_{t-s}}) + (1-A)(\bar{Z_{t-1}} + \hat{T_{t-1}}), \quad 0 < A < 1,$$

$$\hat{T_t} = C(\bar{Z_t} - \bar{Z_{t-1}}) + (1-C)\hat{T_{t-1}}, \quad 0 < C < 1.$$

which represent the estimate of the seasonal factor, the level and the trend, respectively, where A, C and D are the smoothing constants.

A prediction of h steps ahead can be made using the equations

$$\hat{Z_t}(h) = \bar{Z_t} + h\hat{T_t} + \hat{S_{t+h-p}}, \quad h = 1,2,\dots p,$$

$$\hat{Z_t}(h) = \bar{Z_t} + h\hat{T_t} + \hat{S_{t+h-2p}}, \quad h = p+1,\dots 2p,$$

$$\vdots \quad \quad \quad \quad \quad \vdots$$

If we obtain a new observation $ Z_{t+1} $ we can update the forecast $ Z_{t+h} $ recalculating the recurrence equations for the point t+1, that is

$$\hat{S_{t+1}} = D(Z_{t+1} - \hat{Z_{t+1}}) + (1-D)\hat{S_{t+1-s}}$$

$$\bar{Z_{t+1}} = A(Z_{t+1} - \hat{S}_{t+1-s}) + (1-A)(\bar{Z}_{t} + \hat{T}_{t}),$$

$$\hat{T_{t+1}} = C(\bar{Z_{t+1}} - \bar{Z}_{t}) + (1-C)\hat{T}_{t}.$$

and thus, the new forecast for $ Z_{t+h} $ will be

$$\hat{Z_{t+1}}(h-1) = \bar{Z_{t+1}} + (h-1)\hat{T_{t+1}} + \hat{S}_{t+1+h-p}, \quad h = 1,2,\dots p+1,$$

$$\hat{Z_{t+1}}(h-1) = \bar{Z_{t+1}} + (h-1)\hat{T_{t+1}} + \hat{S}_{t+1+h-2p}, \quad h = p+2,\dots 2p+1,$$

$$\vdots \quad \quad \quad \quad \quad \vdots$$

Example 3.4.1

Consider the same time series as in example 3.2.1, let’s try to predict the number of passengers on the airline for the next three years, that’s 36 steps ahead.

Year/Month Jan Feb Sea Apr May June Jul Aug Set out Nov Ten
1949 112 118 132 129 121 135 148 148 136 119 104 118
1950 115 126 141 135 125 149 170 170 158 133 114 140
1951 145 150 178 163 172 178 199 199 184 162 146 166
1952 171 180 193 181 183 218 230 242 209 191 172 194
1953 196 196 236 235 229 243 264 272 237 211 180 201
1954 204 188 235 227 234 264 302 293 259 229 203 229
1955 242 233 267 269 270 315 364 347 312 274 237 278
1956 284 277 317 313 318 374 413 405 355 306 271 306
1957 315 301 356 348 355 422 465 467 404 347 305 336
1958 340 318 362 348 363 435 491 505 404 359 310 337
1959 360 342 406 396 420 472 548 559 463 407 362 405
1960 417 391 419 461 472 535 622 606 508 461 390 432

Thus, using Action to perform the calculations, we obtain the results:

(there are missing elements in the equation above)

(image missing)

(image missing)

(image missing)

In this case, the seasonal length is k = 12. As this series has a seasonal behavior and a very evident trend, it becomes an optimal case for forecasting using HW smoothing.

20.3.5 Accuracy Measurements

MAPE, MAD and MSD statistics are important information for comparing smoothing models and deciding whether they represent a good fit to our data.

Mean Absolute Percentage Error (MAPE)

Expresses the accuracy of the error in percentage. For example, if we have a MAPE of 7%, it means that our adjustment is wrong in 7% of the data.

To calculate MAPE we use the following formula:

$$ \frac{\sum_{t=1}^{n} |(y_t - \hat{y_t})/y_t|}{n}\times 100\quad\text{se } y_t \not= 0 $$

where $ y_t $ is our data, $ \hat{y_t} $ are the adjustments and $ n $ is the number of observations. Note that if $ y_t = \hat{y_t} $ we obtain MAPE = 0, that is, the lower the MAPE, the better our adjustment.

Mean Absolute Standard Deviation (MAD)

Represents the standard deviation of the fit in relation to the mean in the same data units. For example, if we are fitting a time series of visits over time and find a MAD of 72, this means that our fit has one standard deviation from the 72-day average.

To find the MAD, we perform the following calculation:

$$ \frac{\sum_{t=1}^{n} |(y_t - \hat{y_t})|}{n} $$

where $ y_t $ is our data, $ \hat{y_t} $ are the adjustments and $ n $ is the number of observations. Note that if $ y_t = \hat{y_t} $ we obtain MAD = 0, that is, the lower the MAD the better our adjustment.

Mean Squared Standard Deviation (MSD)

This accuracy measure is quite common in time series adjustments. When we have outliers in our dataset, this measure is affected more than MAD. So if we have a low MAD and a high MSD we can imagine that we have outliers in our data set.

To calculate the MSD we use the formula:

$$ \frac{\sum_{t=1}^{n} |(y_t - \hat{y_t})|^2}{n} $$

where $ y_t $ is our data, $ \hat{y_t} $ are the adjustments and $ n $ is the number of observations. Note that if $ y_t = \hat{y_t} $ we obtain MSD = 0, that is, the smaller the MSD the better our adjustment.

20.4 ARIMA models

This methodology consists of fitting integrated autoregressive moving average models, ARIMA(p,d,q), to a set of data. To build the model, we follow an algorithm in which the choice of the model structure is based on the data itself.

We can describe the algorithm through the following steps:

  1. A general class of models for analysis is considered;
  2. a model is identified based on the analysis of autocorrelations, partial autocorrelations and other criteria;
  3. the parameters of the identified model are estimated;
  4. check whether the adjusted model fits the data through a residual analysis.
  5. If the model is not suitable, the algorithm is repeated, returning to the identification phase.

There are several criteria for identifying a model, therefore, it is possible to identify different models depending on the criterion that was chosen for identification.

20.4.1 Autoregressive (AR) Models

We say that $ {X_t, t \in Z} $ is an autoregressive process of order p and we write $ X_t \sim AR(p) $ If we can write the process in the following form

$$X_t = \phi_0 + \phi_1X_{t-1} + \dots + \phi_pX_{t-p} + \varepsilon_t$$

where $ \phi_0, \phi_1, \dots , \phi_p $ are real parameters and $ \varepsilon_t $ is i.i.d. with $ E(\varepsilon_t) = 0 $ and $ Var(\varepsilon_t) = \sigma^2 $.

A simple particular case of great importance is the autoregressive process of order p = 1, AR(1)

$$X_t = \phi X_{t-1} + \varepsilon_t$$

Making successive substitutions, $ X_{t-1}, X_{t-2} $, etc., in the above equation we obtain

$$X_t = \varepsilon_t + \phi\varepsilon_{t-1} + \phi^2\varepsilon_{t-2} + \dots = \sum_{j=0}^{\infty} \phi^j\varepsilon_{t-j} \hspace{6.0cm} (4.11)$$

where convergence is quadratic mean. Therefore, the condition $ |\phi| < 1 $ is enough for $ X_t $ be stationary.

We can calculate the autocovariance function (f.a.c.v.) by multiplying both sides of (4.11) by $ X_{t-\tau} $ and taking hope

$$E(X_tX_{t-\tau}) = \phi E(X_{t-1}E_{t-\tau}) + \phi^2E(X_{t-2}X_{t-\tau}) + \dots + \phi^pE(X_{t-p}X_{t - \tau}) + E(\varepsilon_tX_{t-\tau})$$

$$\gamma_{\tau} = \phi\gamma_{\tau-1} = \dots = \phi^{\tau}\gamma_0$$

but we know that

$$\gamma_0 = \sigma^2_X = \sigma^2\sum^{\infty}_{j=0}\phi^{2j} = \frac{\sigma^2}{1 - \phi^2}$$

therefore, it follows that

$$\gamma_{\tau} = \frac{\sigma^2}{1 - \phi^2}\phi^{|\tau|} , \quad \tau \in Z$$

Thus, from the autocovariance function we can also calculate the autocorrelation function (f.a.c.)

$$\rho_{\tau} = \frac{\gamma_{\tau}}{\gamma_0} = \phi^{|\tau|}, \quad \tau \in Z$$

In the general case, we can calculate the autocovariance and autocorrelation functions by

$$\gamma_j = \phi_1\gamma_{j-1} + \phi_2\gamma_{j-2} + \dots + \phi_p\gamma_{j-p}, \quad j > 0 $$

$$\rho_j = \phi_1\rho_{j-1} + \phi_2\rho_{j-2} + \dots + \phi_p\rho_{j-p}, \quad j > 0, \quad \quad (4.12)$$

respectively.

If we set j = 1, 2, … , p, in (4.12) we obtain

$$\rho_1 = \phi_1 + \phi_2\rho_2 + \dots + \phi_p\rho_{p-1}$$

$$\rho_2 = \phi_1\rho_1 + \rho_2 + \dots + \phi_p\rho_{p-2}$$

$$\vdots \quad = \quad \vdots$$

$$\rho_p = \phi_1\rho_{p-1} + \phi_2\rho_{p-2} + \dots + \phi_p$$

which is a recursive method for calculating autocorrelations, known as Yule-Walker equations.

Example 4.1.1

Consider an AR(1) model, with $ \phi = 0,7 $. How $ -1 < \phi < 1 $ we have that the model satisfies the stationarity conditions. Calculating the autocorrelation function we have

$$\rho_j = \phi\rho_{j-1} = \phi^j, \quad j \ge 0.$$

Then, the autocorrelation function decays exponentially, with values all positive. Se $ \phi = 0,7 $, $ \rho_j = (0,7)^j $, $ j \ge 0 $, the autocorrelation function would decay exponentially to zero.

How we know $ \phi $ we can calculate the $ \rho_j $ exactly, but we usually need to estimate the values of $ \phi $ and get estimates $ r_j $ for the values of f.a.c

j 0 1 2 3 4 5 6 7 8 9 10
$ \rho_j $ 1,00 0,70 0,49 0,34 0,24 0,17 0,12 0,08 0,06 0,04 0,03
$ r_j $ 1,00 0,71 0,41 0,36 0,20 0,10 -0,09 -0,12 -0,04 -0,11 -0,16

(image missing)

20.4.2 Moving Average (MA) Models

Consider a linear process $ (X_t, t \in Z) $, we say that this process is one of moving averages of order q, denoted by MA(q), if it satisfies the difference equation

$$X_t = a_t - \theta_1 a_{t-1} - \dots - \theta_q a_{t-q}$$

where $ \mu, \theta_1, \dots , \theta_q $ are real constants, $ a_t $ is i.i.d. and $ a_t \sim N(0,\sigma^2) $.

It follows that $ X_t $ is stationary, average $ \mu $. Suppose $ \mu = 0 $, calculating the autocovariance function (f.a.c.v.) of the process we obtain

$$\gamma_j = E(X_tX_{t-j}) = E\Bigg(\Bigg[a_t - \sum_{k=1}^q \theta_k a_{t-k} \Bigg] \Bigg[ a_{t-j} - \sum_{l=1}^q \theta_l a_{t-l-j} \Bigg[\Bigg)$$

$$\gamma_j = E(a_ta_{t-j}) - \sum_{k=1}^q E(a_{t-j}a_{t-k}) - \sum_{l=1}^q E(a_t a_{t-j-l}) + \sum_{k=1}^q\sum_{l=1}^q \theta_k \theta_l E(a_{t-l}a_{t-j-l})$$

How do the $ a_t $ are uncorrelated, we have

Screenshot_11

$$\gamma_0 = Var(X_t) = \sigma_X^2 = \sigma^2(1 + \theta_1^2 + \dots + \theta_q^2)$$

So,

$$ \gamma_j = \gamma_a(j) - \sum_{k=1}^q \gamma_a(k-j) - \sum_{l=1}^q \gamma_a(j+l) + \sum_{k=1}^q\sum_{l=1}^q \theta_k \theta_l E(a_{t-l}a_{t-j-l})\gamma_a(j+l+k) $$

Screenshot_12

Example 4.2.1

Consider the simulated series with 50 observations, generated according to an MA(2) process: $ X_t = a_t + 0,63a_{t-1} + 0,2a_{t-2} $ and $ \sigma^2_a = 1 $. The data for this example can be obtained by clicking here.

We can calculate the f.a.c.v. and f.a.c. exact by

$$\gamma_0 = (1 + \theta_1^2 + \theta_2^2)\sigma_a^2 = (1 + (0,63)^2 + (0,2)^2)1 = 1,437$$

$$\rho_1 = \frac{\theta_1(1 +\theta_2)}{1+\theta_1^2 + \theta_2^2} = \frac{0,63(1 - 0,2)}{1+0,63^2 + (0,2)^2} = 0,526;$$

$$\rho_2 = \frac{\theta_2}{1+\theta_1^2 + \theta_2^2} = \frac{0,2}{1+(0,63)^2+(0,2)^2} = 0,139;$$

$$\rho_j = 0, \quad j=3,4,5, \dots$$

j 0 1 2 3 4 5 6 7 8 9 10
$ \rho_j $ 1,00 0,526 0,139 0 0 0 0 0 0 0 0
$ r_j $ 1,00 0,536 0,202 0,073 0,004 -0,138 -0,168 -0,154 -0,061 -0,031 0,028

ma_simulado

20.4.3 Autoregressive and Moving Average Models

Autoregressive and moving average models are the combination of AR and MA models. We denote by ARMA(p,q) an autoregressive and moving average process of order (p,q) and can be represented by

$$X_t = \phi_1X_{t-1} + \cdots \phi_pX_{t-p} + a_t - \theta_1a_{t-1} - \cdots - \theta_qa_{t-q}$$

A frequently used model is ARMA(1,1), that is,

$$X_t = \phi X_{t-1} + a_t - \theta a_{t-1}$$

In the general case, we calculate the f.a.c.v. by

$$\gamma_j = \phi_1 \gamma_{j-1} + \phi_2 \gamma_{j-2} + \cdots + \phi_p \gamma_{j-p} +\gamma_{Xa}(j) - \theta_1\gamma_{Xa}(j-1) - \cdots - \theta_q\gamma_{Xa}(j-q)$$

where $ \gamma_{Xa}(j) $ is the cross-covariance between $ X_t $ and $ a_t $, defined by

Screenshot_13

Thus, the f.a.c.v. stay

$$\gamma_j = \phi_1\gamma_{j-1} + \phi_2\gamma_{j-2} + \cdots + \phi_p\gamma_{j-p}, \quad j \ > \ q$$

and the f.a.c. is obtained by

$$\rho_j = \frac{\gamma_j}{\gamma_0} = \phi_1\rho_{j-1} + \phi_2\rho_{j-2} + \cdots + \phi_p\rho_{j-p}, \quad j \ > \ q.$$

An ARMA(p,q) process has f.a.c. infinite, which decays according to exponentials and/or damped sinusoids after the “lag” p-q. This observation is important in identifying the model to the observed data.

Example 4.3.1

Consider an ARMA(2,1) model simulated with n = 200, given by $ X_t = 0,26X_{t-1} + 0,37X_{t-2} + 0,81a_{t-1} + a_t. $

Calculating the estimated and theoretical autocorrelation function we have:

$ \bold{j} $ 0 1 2 3 4 5 6 7 8 9 10
$ \bold{\rho_j} $ 1,000 0,809 0,580 0,450 0,332 0,253 0,188 0,143 0,107 0,081 0,060
$ \bold{r_j} $ 1,000 0,779 0,519 0,405 0,312 0,195 0,044 -0,028 -0,052 -0,121 -0,187

(image missing)

20.4.4 Autoregressive, Integrated and Moving Average Models

The AR, MA and ARMA models are appropriate for describing stationary time series, that is, series that develop over time around a constant average.

Many series found in practice are not stationary, but, as seen previously, when we take the differentiated series it becomes stationary.

Autoregressive, integrated and moving average models (ARIMA) represent a series differentiated by an ARMA model.

Be $ Z_t $ a non-stationary time series. We take $ W_t = \Delta Z_t = Z_t - Z_{t-1} $ the series being differentiated once from $ Z_t $, we denote by $ W_t^d = \Delta^d Z_t $ the time series differentiated d times of $ Z_t $.

We can represent $ W_t $ by a ARMA model, such as $ W_t $ is a difference of $ Z_t $ then, $ Z_t $ is an integral of $ W_t $, so we say that $ Z_t $ follows an autoregressive, integrated and moving average model, that is, an ARIMA model of order (p,d,q) and we write ARIMA(p,d,q) where p is the order of the autoregressive component, d is the number of differences taken in the series and q is the order of the moving average component.

Therefore, we can describe all previously seen models using the ARIMA nomenclature, that is

i) ARIMA(p,0,0) = AR(p);

ii)ARIMA(0,0,q) = MA(q);

iii)ARIMA(p,0,q) = WEAPON(p,q).

and in the case of a non-stationary series we use the complete model, ARIMA(p,d,q) with d differences in the original series.

20.4.5 Identification of ARIMA Models

The particular identification of an ARIMA model to be fitted to the data can be considered one of the most critical phases when using ARIMA modeling. The choice of the model to be used is made mainly based on the estimated autocorrelations and partial autocorrelations, which we will use to compare with the theoretical quantities and identify a possible model for the data.

We remind you that the f.a.c. $ \rho_j $ is estimated by

$$r_j = \frac{g_j}{g_0}, \quad j = 0, 1, \dots , N-1$$

where $ g_j $ is the estimate of the f.a.c.v. $ \gamma_j $, given by

$$g_j = \frac{1}{N}\sum_{t=1}^{N-j} [(X_t - \bar{X})(X_{t+j} - \bar{X})], \quad j = 0,1,\dots , N-1$$

being $ \bar{X} = \frac{1}{N}\sum_{j=1}^{N}X_t $ the sample mean. Since the autocorrelation functions are even functions, we have $ g_{-j} = g_j $ and $ r_{-j} = r_{j} $.

The AR(p), MA(q) and ARMA(p,q) models present f.a.c. with special features:

i) a process AR(p) has f.a.c. infinite in extension that decays according to exponentials and/or damped sinusoids;

ii) an MA(q) process has f.a.c. finite, in the sense that it presents a cutoff after the lag q;

iii) an ARMA(p,q) process has f.a.c. infinite that decays according to exponentials and/or damped sinusoids after the lag (q-p).

Thus, from the f.a.c. estimated, we try to identify a pattern that behaves theoretically with some model. In particular, the f.a.c. estimated is useful for identifying MA models because of feature (ii) and are not very useful in identifying ARMA models, which have f.a.c. complicated.

Partial Autocorrelation Function (f.a.c.p.)

Another tool used in the model identification process is the partial autocorrelation function (f.a.c.p.). This measure corresponds to the correlation of $ X_t $ and $ X_{t-k} $ removing the effect of observations $ X_{t-1}, X_{t-2}, \dots , X_{t-k+1} $ and is denoted by $ \phi_{kk} $, that is

$$\phi_{kk} = Corr(X_t, X_{t-l}/X_{t-1}, X_{t-2},\dots,X_{t-k+1})$$

A general method for finding the f.a.c.p. for a stationary process with f.a.c. $ \rho_k $ is using the Yule-Walker equations, that is, for a certain k we have

$$\rho_j = \phi_{k1}\rho_{j-1} + \phi{k2}\rho_1 + \cdots + \phi_{kk}\rho{j-1}, \quad j = 1, 2, \dots , k$$

Developing the equation we have

$$\rho_1 = \phi_{k1} + \phi_{k2}\rho_1 + \cdots + \phi_{kk}\rho_{j-1}$$

$$\rho_2 = \phi_{k1}\rho_1 + \phi_{k2} + \cdots + \phi_{kk}\rho_{j-2}$$

$$\quad \vdots \quad = \quad \vdots$$

$$\rho_j = \phi_{k1}\rho_{j-1} + \phi_{k2}\rho_{j-2} + \cdots + \phi_{kk}$$

Solving the above equations successively for k = 1, 2, …, we obtain $ \phi_{kk} $ in the following way

$ \phi_{11} = \rho_1 $

Screenshot_14

Screenshot_15

in general we have

$$\phi_{kk} = \frac{|P^*_k|}{|P_k|}$$

where $ P_k $ is the autocorrelation matrix, and $ P^*_k $ is the matrix $ P_k $ with the last column replaced by the autocorrelation vector.

In the AR, MA and ARMA processes we have the following f.a.c.p. theoretical:

Screenshot_16

ii) in a MA(q) process at f.a.c.p. behaves in a similar way to f.a.c. of an AR(p) process, that is, composed of exponentials and/or damped sinusoids;

iii) an ARMA(p,q) process has f.a.c.p. that behaves like the f.a.c.p. of a pure MA process.

Due to the above factors, it follows that the f.a.c.p. is useful for identifying pure AR models, and is not as useful for identifying MA and ARMA models.

A simple way to estimate f.a.c.p. of a process consist of substituting the f.a.c. by your estimates

$$r_j = \hat{\phi_{k1}}r_{j-1} + \cdots + \hat{\phi_{kk}}r_{j-k}, \quad j=1,\dots,k,$$

and solve these equations for k=1, 2, 3,….

Example 4.5.1

See the table below for an estimate of the f.a.c.p. of the AR(1), MA(1) and ARMA(1,1) processes, of computationally simulated time series with 100 observations each.

j AR(1) MA(1) WEAPON(1,1)
1 -0,4514 0,3828 -0,0187
2 -0,0640 -0,2738 -0,0833
3 -0,0460 -0,0710 -0,1950
4 -0,0305 -0,1540 0,1094
5 0,0144 -0,0599 -0,0949
6 -0,0425 -0,0412 0,0537
7 0,0939 -0,0412 0,0708
8 -0,0470 -0,1616 -0,1851
9 -0,0256 0,0528 0,1552
10 0,0080 -0,0296 0,0474
11 -0,0754 -0,0305 -0,1351
12 0,0846 -0,1096 -0,0056
13 0,0457 -0,0883 0,0532
14 0,0330 0,0115 -0,0495
15 -0,0132 0,0761 0,0547

Graphically represented by:

(image missing)

AIC and BIC information criteria

After selecting possible ARIMA models for the observed data, we identified the best possible model using the AIC and BIC criteria. We want to find the orders k and l that minimize the AIC and BIC criteria for determining the orders p and q of the model, that is, we want to minimize

$$AIC(k,l) = -2ln(\hat{\sigma}^2_{k,l}) + 2(k+l+2)$$

$$BIC(k,l) = -2ln(\hat{\sigma}^2_{k,l}) + (k+l)\frac{lnN}{N}$$

where, N is the number of observations and $ \hat{\sigma}_{k,l}^2 $ is the maximum likelihood estimator of the residual variance of the ARMA(k,l) model.

Example 4.5.2

Consider the returns on Petrobras shares during the period from 01/10/2008 to 02/10/2008. We constructed a time series using the average of returns at each hour per day, with a total of 110 observations. Let’s identify an ARIMA model for this series.

j $ X_j $ j $ X_j $ j $ X_j $ j $ X_j $ j $ X_j $
1 -0,0012 23 0,0004 45 -0,0011 67 0,0106 89 -0,0036
2 0,0006 24 -0,0035 46 -0,0149 68 -0,0025 90 0,0001
3 -0,0059 25 0,0019 47 0,0003 69 0,0058 91 -0,0030
4 -0,0054 26 -0,0107 48 0,0012 70 -0,0088 92 -0,0020
5 -0,0039 27 0,0042 49 -0,0148 71 -0,0053 93 -0,0154
6 -0,0222 28 0,0030 50 0,0006 72 -0,0242 94 0,0090
7 -0,0017 29 -0,0150 51 0,0136 73 -0,0089 95 0,0083
8 0,0096 30 -0,0215 52 -0,0152 74 -0,0133 96 0,0035
9 0,0102 31 -0,0029 53 -0,0113 75 -0,0075 97 -0,0038
10 -0,0068 32 -0,0575 54 0,0037 76 -0,0037 98 -0,0025
11 0,0105 33 0,0045 55 0,0282 77 0,0065 99 0,0342
12 0,0100 34 -0,0043 56 -0,0008 78 -0,0107 100 -0,0043
13 0,0079 35 -0,0077 57 -0,0192 79 -0,0017 101 0,0567
14 0,0069 36 0,0186 58 0,0060 80 -0,0064 102 0,0033
15 0,0097 37 0,0039 59 0,0077 81 0,0120 103 0,0012
16 -0,0009 38 0,0269 60 -0,0092 82 0,0021 104 0,0053
17 -0,0056 39 -0,0101 61 -0,0010 83 -0,0031 105 0,0066
18 -0,0011 40 -0,0010 62 -0,0003 84 -0,0047 106 -0,0082
19 -0,0035 41 0,0043 63 0,0048 85 0,0014 107 0,0192
20 -0,0313 42 0,0099 64 -0,0017 86 -0,0022 108 0,0020
21 0,0094 43 0,0003 65 0,0008 87 -0,0008 109 0,0122
22 -0,0045 44 0,0022 66 -0,0023 88 0,0090 110 0,0032

(image missing)

Viewing the series graph, we can identify some small repetitive cycles which make the series non-stationary and analyzing the f.a.c. estimated from the series we were unable to identify an appropriate model for the adjustment, so we took a difference in the series and analyzed the f.a.c. and estimated f.a.c.p.

(image missing)

The analysis of the f.a.c. and f.a.c.p. estimates suggest a model of moving averages MA(p) in the differentiated series. We then calculate the AIC and BIC information criteria to confirm an ARIMA(0,1,p) type model.

p AIC BIC
1 -637,4155 -632,0145
2 -635,4466 -627,3451
3 -633,7607 -622,9587
4 -632,4030 -618,9006
5 -630,6355 -614,4326
6 -628,6938 -609,7904
7 -627,4892 -605,8854
8 -627,2289 -602,9245
9 -627,2354 -600,2306
10 -626,7906 -597,0853

Note that among the first 10 orders the smallest value among the criteria is for order p = 1, therefore, we conclude that an ideal model for the data set is ARIMA(0,1,1).

20.4.6 ARIMA Model Estimation

Having identified the order of an ARIMA model for a time series, we now need to estimate the parameters of this model. To do this, we can use the method of moments, least squares estimators and maximum likelihood estimators.

Consider an ARIMA(p,d,q) model and place its p+q+1 parameters in the vector $ \xi = (\phi, \theta, \sigma^2_a) $, where $ \phi = (\phi_1, \phi_2, \dots, \phi_p) $, $ \theta = (\theta_1, \theta_2, \dots, \theta_q) $. When d $ > $ 0 we assume $ \mu = 0 $, otherwise we need to consider $ \mu $ as a parameter and estimate it, then we would have p+q+2 parameters to be estimated.

Given the N observations, $ X_1, \dots, X_n $, we consider the likelihood function $ L(\xi | X_1, \dots, X_n) $ as a function of $ \xi $, then we want to find the values of $ \xi $ that minimize $ L $ or $ l = log(L) $.

To determine the EMV we will work with the assumption that the process $ a_t $ is normal, that is, for each t, we have $ a_t \sim N(0, \sigma_a^2) $, in these considerations the EMV will be approximately least squares estimators (EMQ).

Initially, we take d differences in the series to achieve stationarity, we are left with n = N - d observations denoted by $ W_1, \dots, W_n $, where $ W_t = \Delta^dZ_t $, resulting in a stationary and invertible ARMA(p,q) model, so we write

Screenshot_19

where $ ~{W_t} = W_t - \mu $.

To calculate the $ a_t $ it is necessary to obtain initial values for the $ ~{W} $’s and a’s. We can resolve this issue through two methods: Conditional, in which the unknown initial values ​​are replaced by values ​​that we assume to be reasonable; unconditional, in which the initial values ​​are estimated using a procedure called “backforecasting”.

Conditional Procedure

Assuming normality of $ a_t $, the joint density function of $ a_1, \dots, a_n $ is given by

$$f(a_1, \dots, a_n) = (2\pi)^{-n/2}(\sigma_a)^n exp\Bigg(-\sum_{t=1}^n \frac{a_t^2}{2\sigma_a^2}\Bigg).$$

Suppose we are given p values $ W_t $ and what values $ a_t $, denoted by $ W_t^* $ and $ a_t^* $. The likelihood function is given by

Screenshot_18

Taking the logarithm of L, consider $ \eta = (\phi, \theta) $, we have

Screenshot_17

Non-Conditional Procedure

It can be shown that the logarithm of the unconditional likelihood function is given by

$$l(\xi) \simeq -nlog(\sigma_a) - \frac{S(\eta)}{2\sigma_a^2}$$

in which

$$S(\eta) = S(\phi,\theta) = \sum_{t=-\infty}^n [a_t(\eta,W)]^2$$

is the unconditional sum of squares, with $ [a_t(\eta,W)] = E(a_t|\eta,W). $

Therefore, least squares estimators obtained by minimizing $ S(\eta) $ will be good approximations for maximum likelihood estimators.

To calculate the sum of squares for a given $ \eta $, we need to use the procedure called “backforecasting” to calculate $ [W_{-j}] $ and $ [a_{-j}] $, that is, generating (predicting) values before the start of the series. It can be demonstrated that the so-called “backward” form of the process provides a stationary and invertible representation in which $ W_t $ is expressed only in terms of future values of $ W_t $ and $ e_t $, where $ e_t $ has a normal distribution with zero mean and the same variance as $ a_t $.

In this way, the value $ W_{-j} $ has the same probabilistic relationship with $ W_1, \dots, W_n $ that $ W_{n+j+1} $ have with $ W_n, W_{n-1}, \dots, W_1 $, that is, making a prediction before the series starts is equivalent to predicting the inverse series.

Example 4.6.1

Consider a time series $ Z_1, \dots, Z_n $, in which we identified an ARIMA(0,1,1) model. Be $ W_t = \Delta Z_t $, then we can write

$$a_t = W_t + \theta a_{t-1}.$$

In the conditional case, suppose $ \theta = 0,7 $ and we start $ a_t $ specifying $ a_0 = 0 $ and $ Z_0 = 200 $, therefore we can recursively calculate the values of $ a_t $. Using hypothetical data to $ Z_t $ we have

t $ \bold{Z_t} $ $ \bold{W_t = \Delta Z_t} $ $ \bold{a_t} $
0 200 0
1 197 -3 -3,0
2 190 -7 -9,1
3 194 4 -2,4
4 189 -5 -6,7
5 187 -2 -6,7
6 192 5 0,3
7 197 5 5,2
8 201 4 7,7
9 204 3 8,4
10 202 -2 3,9

Thus, it follows that the conditional sum of squares becomes

$$S^*(0,7) = \sum_{t=1}^{10} a_t^2(0,7|a_0 = 0) = 357,3.$$

20.4.7 ARIMA Model Diagnosis

After identifying and estimating the model that fits the observations to the time series, we need to check whether or not it adequately represents the data. Model checking can be done by analyzing the residuals. Suppose the fitted model is as follows

$$\phi (B) W_t = \theta (B) a_t$$

where $ W_t = \Delta^dX_t $ representing that we take d differences in the series, $ \phi (B) $ and $ \theta (B) $ It is the polynomials using delay operator B that guarantee that the process is stationary and invertible.

We can then describe the residues by

$$a_t = \theta^{-1} (B) \phi (B) W_t$$

If the model is correct, the exact residuals $ a_t $ must be i.i.d with distribution N(0,1).

One method of verifying this hypothesis is to check whether the model’s estimated residuals are uncorrelated.

20.4.7.1 Box Test - Pierce

Box and Pierce suggested a test for the autocorrelations of the estimated residuals, which indicates whether these values are too high.

The test hypotheses are

Screenshot_20

Initially, we calculated an estimate for the autocorrelations by

$$\hat{r_k} = \frac{\sum^n_{t = k+1} \hat{a_t} \hat{a_{t-k}}}{\sum^n_{t=1} \hat{a_t}^2}$$

it is possible to show that $ \hat{r}_k \sim N(0, \frac{1}{n}) $.

If the model is appropriate, the test statistic

$$Q(k) = n \sum^K_{j=1} \hat{r}^2_j$$

Screenshot_21

20.4.7.2 Ljung Test - Box

Ljung and Box proposed a small change to the Box - Pierce test, which makes the test more generalized. It has been observed in the literature that the Ljung - Box test presents better results than the Box - Pierce test.

The test hypotheses are the same:

$$\text{Os resíduos não são i.i.d..}$$

(there are missing elements in the equation above)

We calculated the autocorrelation estimates by

$$\hat{r_k} = \frac{\sum^n_{t = k+1} \hat{a_t} \hat{a_{t-k}}}{\sum_{t=1}^n \hat{a_t}^2}.$$

It is possible to show that $ \hat{r}_k \sim N(0, \frac{1}{n}) $.

If the model is appropriate, the test statistic

$$Q(k) = n(n-2) \sum^K_{j=1} \frac{\hat{r}^2_j}{(n-j)}$$

Screenshot_22

20.4.8 Forecasting with ARIMA models

One of the greatest interests in studying time series is being able to make predictions from observations over time.

Once we are able to identify and estimate an ARIMA model suitable for the observations, we will then study methods that can use ARIMA modeling to predict the values ​​of the observations h steps ahead.

It is worth highlighting that forecasts using ARIMA models will be effective for a short period and the best forecasts will be those that have a minimum mean squared error (MSE).

20.4.8.1 Introduction

We are interested in predicting a value $ X_{t+h}, h \ge 1 $, assuming that we have all observations up to time t, that is, $ …,X _{t-2}, X_{t-1}, X_t $, we say that t is the origin of the predictions.

We denote by $ \hat{X_t(h)} $ the prediction of h steps from the origin t. Let’s assume an ARIMA(p,d,q) model, stationary, invertible and with known parameters. In these situations, we have 3 possible forms of prediction:

(i) difference equation form

Screenshot_23

(ii) form of random shocks

$$X_{t+h} = \sum_{j = -\infty}^{t+h} \psi_{t+h-j}a_j = \sum_{j = 0}^{\infty} \psi_ja_{t+h-j},$$

where $ \psi_o = 1 $ and the other weights are obtained by solving a system of delay operators given by $ \phi(B)\psi(B) = \theta(B) $;

(iii) inverted form

$$X_{t+h} = \sum_{j=1}^{\infty} \pi_jX_{t+h-j} + a_{t+h},$$

where the weights $ \pi_j $ are obtained by solving the system of delay operators given by $ \phi(B) = \theta(B)\pi(B) $.

Minimum Mean Squared Error (MSE) Prediction

Screenshot_26

Screenshot_25

In this way, we want to find the weights $ \psi^*_j $ that minimizes the prediction NDE. Calculating NDE through prediction error $ e_t(h) $ we have

$$E[e_t(h)]^2 = E[X_{t+h} - \hat{X_t(h)}]^2 = E\Bigg[ \sum_{j = 0}^{\infty} \psi_ja_{t+h-j} - \sum_{j=0}^{\infty} \psi_{h+j}^*a_{t-j} \Bigg]^2$$

$$ \Longrightarrow E[e_t(h)]^2 = E\Bigg[ \psi_0a_{t+h} + psi_1a_{t+h+1} + \cdots + \psi_{h=1}a_{t+1} + \sum_{j = 0}^{\infty}(\psi_{h+j} - \psi_{h+j}^*)a_{t-j}\Bigg]^2$$

$$\Longrightarrow E[e_t(h)]^2 = (1 + \psi_1^2 + \cdots + \psi_{h-1}^2)\sigma_a^2 + \sum_{j = 0}^{\infty}(\psi_{h+j} - \psi_{h+j}^*)^2\sigma^2_a,$$

due to the fact that the $ a_t $ are uncorrelated. It follows that the NDE will be minimal when $ \psi_{h+j}^* = \psi_{h+j}, j = 1,2,…,h $ fixed.

Therefore, the prediction with minimum NDE is given by

$$X_t(h) = \psi_ha_{t} + \psi_{h+1}a_{t-1} + \cdots = \sum_{j=0}^{\infty} \psi_{h+j}a_{t-j}$$

and the prediction error due to

$$e_t(h) = a_{t+h} + \psi_{h+1}a_{t+h-1} + \cdots + \psi_{h-1}a_{t+1} = \sum_{j=0}^{h-1} \psi_ja_{t+h-j}.$$

As a consequence of the above results, we can note that

$$X_{t+h} = \hat{X_t(h)} + e_t(h), \quad h \ge 1.$$

To make things easier, we will use the notation

$$[X_{t+h}] = E[X_{t+h} | X_t, X_{t-1}, …]$$

Using the notation above, we have the following conclusions:

(i) $ [e_t(h)] = 0 $ and the variance of the forecast error is $ Var(h) = (1 + \psi_1^2 + \psi_2^2 + \cdots + \psi_{h-1}^2)\sigma_a^2. $

Screenshot_24

20.4.8.2 Prediction Equation

We assume a stationary, invertible ARIMA(p,d,q) model with known parameters, then the prediction equation, considered as a function of h, with fixed origin t is given by

$$\hat{X_t(h)} = \sum_{i = 1}^{p+q} \phi_i\hat{X_t(h-1)}, \quad h \ > \ q$$

We have to $ h \ > \ q-p-d $, the function $ \hat{X_t(h)} $ will consist of a mixture of polynomials, exponentials and sinusoidal dampings, with its exact shape determined by the roots of the delay operator $ \phi(B) = 0 $. The general solution will have the form

$$\hat{X_t(h)} = c_1^{(t)}f_1(h) + c_2^{(t)}f_2(h) + \cdots + c_{p+q}^{(t)}f_{p+q}(h), \quad h \ > \ q-p-d$$

where $ f_i(h), h=1,\dots,p+q $, are functions of h and $ c_1^{(t)},\dots,c_{p+q}^{(t)} $ are adapted coefficients that depend on the origin of the forecast and are determined by $ \hat{X_t}(1), \hat{X_t}(2),\dots, \hat{X_t}(p+d) $.

Example 4.8.2.1

We assume an ARIMA(0,1,2) model with the presence of the intercept $ \theta_0 $. Writing in the form of the delay operator we have

$$(1-B)X_t = \theta_0 + (1 - \theta_1B - \theta_2B^2)a_t \ \ \Longleftrightarrow \ \ X_t = \theta_0 + X_{t-1} - a_t - \theta_1a_{t-1} - \theta_2a_{t-2}$$

Replacing t with t+h we have

$$X_{t+h} = \theta_0 + X_{t+h-1} -a_{t+h} - \theta_1a_{t+h-1} - \theta_2a_{t+h-2}$$

so,

$$\hat{X_t(1)} = [X_{t+1}] = \theta_0 + X_t - \theta_1a_t - \theta_2a_{t-1}$$

$$\hat{X_t(2)} = [X_{t+2}] = \theta_0 + \hat{X_t(1)} - \theta_2a_{t} = 2\theta_0 + X_t - (\theta_1 + \theta_2)a_t - \theta_2a_{t-1}$$

$$\hat{X_t(3)} = [X_{t+3}] = \theta_0 + \hat{X_t(2)} = 3\theta_0 + X_t - (\theta_1 + \theta_2)a_t - \theta_2a_{t-1}$$

in general,

$$\hat{X_t(h)} = [X_{t+h}] = X_t + h\theta_0 - (\theta_1 + \theta_2)a_t - \theta_2a_{t-1}.$$

20.4.8.3 Forecast Update

Consider the predictions of $ X_{t+h+1} $ made from two origins

(i) $t+1: \hat{X_{t+1}}(h) = \psi_ha_{t+1} + \psi_{h+1}a_t + \psi_{h+2}a_{t-1} + \cdots$

(ii) $t: \hat{X_t}(h+1) = \psi_{h+1}a_t + \psi_{h+2}a_{t-1} + \cdots$

Subtracting (ii) from (i) we obtain

$$\hat{X_{t+1}}(h) = \hat{X_t}(h+1) + \psi_ha_{t+1}$$

In this way, the prediction of $ X_{t+h+1} $, made at time t, can be updated when new data $ X_{t+1} $ is observed. Therefore, we will forecast $ X_{t+h+1} $, at the origin t+1, adding to the prediction $ \hat{X}(h+1) $ a multiple of the forecast error $ a_{t+1} = X_{t+1} - \hat{X_t}(1) $. For better understanding, let’s look at an example.

Example 4.8.3.1

Be $ X_t $ an AR(2) process, then

$$X_t = \phi_1X_{t-1} + \phi_2X_{t-2} + a_t$$

at the instant (t+h) the value of the series is

$$X_{t+h} = \phi_1X_{t+h-1} + \phi_2X_{t+h-1} + a_{t+h}$$

making the prediction from the origin t, we have

$$\hat{X_t(h)} = \phi_1\hat{X_t}(h-1) + \phi_2\hat{X_t}(h-2), \quad h \ > \ 0$$

$$\hat{X_t(h)} = \phi_1^h\hat{X_t}(0) + \phi_2^{h}\hat{X_{t-1}}(0), \quad h \ > \ 0$$

Similarly, predicting the origin (t-1), we have

$$\hat{X_{t-1}}(h+1) = \phi_1\hat{X_{t-1}}(h) + \phi_2\hat{X_{t-1}}(h-1), \quad h \ > \ 0$$

$$\hat{X_{t-1}}(h+1) = \phi_1^h\hat{X_{t-1}}(1) + \phi_2^{h}\hat{X_{t-2}}(1), \quad h \ > \ 0$$

subtracting $ \hat{X_{t-1}}(h+1) $ of $ \hat{X_t(h)} $,

$$\hat{X_t(h)} - \hat{X_{t-1}}(h+1) = \phi_1^h\hat{X_t}(0) + \phi_2^{h}\hat{X_{t-1}}(0) - \phi_1^h\hat{X_{t-1}}(1) - \phi_2^{h}\hat{X_{t-2}}(1)$$

$$\hat{X_t(h)} - \hat{X_{t-1}}(h+1) = \phi_1^h[X_t - \hat{X_{t-1}}(1)] + \phi_2^{h}[X_{t-1} - \hat{X_{t-2}}(1)]$$

but we know that

$$a_t = X_t - \hat{X_{t-1}}(1)$$

$$a_{t-1} = X_{t-1} - \hat{X_{t-2}}(1)$$

So, substituting we have that the updated forecast will be given by

$$\hat{X_t(h)} - \hat{X_{t-1}}(h+1) = \phi_1^ha_t + \phi_2a_{t-1}^{h}$$

$$\hat{X_t(h)} = \hat{X_{t-1}}(h+1) + \phi_1^ha_t + \phi_2a_{t-1}^{h}.$$

Example 4.8.3.2

Consider an ARIMA(2,0,0) model with n = 105 observations, let’s calculate the first 3 estimates based on the already adjusted observations in the table below

t $ \bold{X_t} $ t $ \bold{X_t} $ t $ \bold{X_t} $ t $ \bold{X_t} $ t $ \bold{X_t} $
1 -0,255 21 -0,289 41 0,225 61 0,334 81 0,167
2 -0,409 22 -1,190 42 -0,926 62 -1,282 82 -1,547
3 -2,196 23 -2,473 43 -1,670 63 -1,092 83 -1,187
4 -1,942 24 -2,306 44 -2,361 64 -2,315 84 -1,201
5 -1,284 25 -1,873 45 -1,867 65 -1,372 85 -0,710
6 -0,352 26 -0,433 46 0,194 66 0,753 86 1,298
7 1,940 27 1,774 47 1,928 67 2,829 87 3,250
8 3,062 28 2,813 48 4,287 68 3,148 88 2,952
9 2,655 29 2,798 49 3,465 69 3,470 89 3,150
10 2,916 30 1,955 50 2,405 70 2,007 90 2,530
11 2,551 31 2,198 51 2,717 71 2,370 91 2,017
12 1,373 32 0,434 52 0,988 72 1,669 92 2,119
13 2,066 33 1,875 53 2,135 73 1,406 93 0,365
14 2,225 34 1,366 54 0,968 74 1,106 94 0,812
15 0,925 35 1,703 55 2,107 75 2,165 95 2,408
16 1,833 36 2,486 56 2,294 76 1,814 96 1,995
17 2,765 37 1,493 57 1,270 77 1,106 97 1,415
18 2,203 38 1,507 58 1,660 78 2,500 98 2,762
19 1,536 39 1,754 59 2,005 79 2,141 99 2,183
20 2,905 40 3,241 60 3,832 80 4,490 100 4,150

The fit of the ARIMA(2,0,0) model with intercept we have:

$$X_t = 1,28 + 0,35X_{t-1} + 0,54X_{t-2} + a_t$$

it follows that,

$$X_{t+h} = 1,28 + 0,35X_{t+h-1} + 0,54X_{t+h-2} + a_{t+h}$$

$$\hat{X_t(h)} = 1,28 + 0,35\hat{X_t}(h-1) + 0,54\hat{X_t}(h-2)$$

therefore, the first 3 predictions from t = 100 are given by

$$\hat{X_{100}}(1) = 1,28 + 0,35X_{100} + 0,54X_{99} = 5,27$$

$$\hat{X_{100}}(2) = 1,28 + 0,35\hat{X_{100}}(1) + 0,54X_{100} = 3,90$$

$$\hat{X_{100}}(3) = 1,28 + 0,35\hat{X_{100}}(2) + 0,54\hat{X_{100}}(1) = 4,62$$

(image missing)

From the moment we have the value $ X_{101} $ we can update the forecasts. Given that $ X_{101} = 5,41 $ we have

$$a_{101} = X_{101} - \hat{X_{100}}(1) = 5,41 - 5,27 = 0,14.$$

For the update, we need to calculate the weights $ \psi_j, j =1,2,…,5 $. We know we must have

$$\phi(B)\psi(B) = \theta(B)$$

i.e.

$$(1 - 0,35B - 0,54B^2)(1 + \psi_1B + \psi_2B^2 + \cdots) = 1$$

It’s easy to see that

$$\psi_1 = 0,35$$

$$\psi_2 = 0,35\psi_1 - 0,54 = -0,4175$$

$$\psi_3 = \psi_1\psi_2 - 0,54\psi_1 = -0,3351$$

in this way,

$$\hat{X_{101}}(1) = \hat{X_{100}}(2) + \psi_1a_{101} = 3,90 + 0,35 \ast 0,14 = 3,95$$

$$\hat{X_{101}}(2) = \hat{X_{100}}(3) + \psi_2a_{101} = 4,62 - 0,4175 \ast 0,14 = 4,56$$

Example 4.8.3.3

Consider the ARIMA(0,1,2) model given by $ X_t = X_{t-1} - a_t - 0,17a_{t-1} - 0,62a_{t-2} $. Let’s calculate a prediction for this model using the data in the table below:

t $ \bold{X_t} $ t $ \bold{X_t} $ t $ \bold{X_t} $ t $ \bold{X_t} $ t $ \bold{X_t} $
1 0 6 0,155237 11 3,024628 16 3,087684 21 6,752729
2 7,951044 7 8,624721 12 9,738347 17 8,02558 22 7,482817
3 6,397658 8 3,640904 13 3,101355 18 2,516373 23 3,561021
4 4,610894 9 4,743764 14 3,223571 19 3,519417 24 4,574021
5 4,979417 10 6,885646 15 7,654261 20 8,479282 25 7,505544

As seen in Example 4.8.2.1, predictions in this model with $ \theta_0 = 0 $, are calculated by

$$\hat{X_t(h)} = [X_{t+h}] = X_t - (\theta_1 + \theta_2)a_t - \theta_2a_{t-1}$$

$$\hat{X_t(h)} = [X_{t+h}] = X_t - 0,79a_t - 0,62a_{t-1}.$$

After adjustment, we have the following residuals

t $ \bold{a_t} $ t $ \bold{a_t} $ t $ \bold{a_t} $ t $ \bold{a_t} $ t $ \bold{a_t} $
1 0 6 0,12919554 11 2,4073518 16 -0,296116 21 2,2849263
2 1,00483218 7 -0,88764535 12 0,6177981 17 -1,247726 22 -0,727535
3 -0,16309921 8 -2,25773061 13 -0,057221 18 0,876457 23 0,9349287
4 0,32909621 9 -0,52464252 14 -1,644572 19 0,9083047 24 1,9634528
5 -0,50776379 10 0,72467078 15 0,975214 20 0,1950138 25 -1,635194

It follows that the prediction of t = 26, from the origin t = 25 is given by

$$\hat{X_{25}}(1) = X_{25} - 0,79a_{25} - 0,62a_{24}$$

$$\hat{X_{25}}(1) = 7,50 - 0,79(-1,63) - 0,62(1,96) = 7,5725$$

20.4.8.4 Confidence Intervals

We know that a forecast is not exact, so it is interesting to estimate a confidence interval for the forecasts. For this, an additional assumption will be necessary for forecast errors, that is, in addition to assuming that $ E(a_t) = 0 $, $ Var(a_t) = \sigma_a^2 $ for all you and $ E(a_ta_s) = 0 $, $ t \not= s $, we will assume that $ a_t \sim N(0,\sigma_a^2) $, for each t.

It follows that, given the past and present values of the series, $ X_t, X_{t-1}, \dots $, the conditional distribution of $ X_{t+h} $ will be $ N(\hat{X_t(h)}, Var(h)) $.

We know that

$$Z = \frac{X_{t+h} - \hat{X_t(h)}}{[Var(h)]^{1/2}} \sim N(0,1)$$

fixing the significance coefficient $ \alpha $, we have to

$$P(-z_{\alpha} \ < \ Z \ < \ z_{\alpha}) = 1 - \alpha$$

that is, a confidence interval with a confidence level of $ (1 - \alpha) $ is given by

$$\hat{X_t(h)} - z_{1-\alpha}[Var(h)]^{1/2} \le X_{t+h} \le \hat{X_t(h)} + z_{1-\alpha}[Var(h)]^{1/2}.$$

But, we have that in Var(h), the value of $ \sigma^2_a $ is not known and is therefore replaced by your estimate $ \sigma^2_a $. In this way, the confidence interval for predicting $ X_{t+h} $ will be given by

$$\hat{X_t(h)} - z_{1-\alpha}\hat{\sigma}_a^2\Bigg[1+ \sum^{h-1}_{j=1} \psi_j^2 \Bigg]^{1/2} \le X_{t+h} \le \hat{X_t(h)} + z_{1-\alpha}\hat{\sigma}_a^2\Bigg[1+ \sum^{h-1}_{j=1} \psi_j^2 \Bigg]^{1/2}.$$

Example 4.8.4.1

We will determine a confidence interval for $ X_{t+h} $ in Example 4.8.3.2 for h = 3.

So, we have

$$\hat{Var}(3) = (1 + \psi_1^2 + \psi_2^2)\hat{\sigma}^2_a, \text{ onde } \hat{\sigma}^2_a = 0,17$$

Then,

$$\hat{Var}(3) = (1+ (-0,4175)^2 + (0,3351)^2)0,17 =0,219$$

For $ \alpha = 5(porcentagem) $ we have $ z_{\alpha} = 1,96 $. Therefore,

$$\hat{X_t}(3) - 1,96[\hat{Var}(3)]^{1/2} \le X_{t+3} \le \hat{X_t}(3) + 1,96[\hat{Var}(3)]^{1/2}$$

In this way, a confidence interval for $ X_{103} $ is $ [3,703; 5,536] $.

20.5 Financial Time Series

In the financial market, a great tool to help predict the market is the estimate of asset volatility. This parameter is not directly observable and therefore models for calculating volatility were estimated using linear regression.

In this chapter, we present some methodologies for calculating volatility and what interpretation we should give to this data.

20.5.1 Returns

Most financial studies focus on analyzing return series rather than using asset price series. The reason for using a return series has two factors: the return information meets the interests of investors and the return series has more interesting statistical properties than the price series.

We denote the price of the asset at the instant $ t $ by $ P_t $, we can calculate the return between the instants $ t-1 $and $ t $ it’s because

$$R_t = \frac{P_t - P_{t-1}}{P_{t-1}} = \frac{P_t}{P_{t-1}} - 1 \quad \Longrightarrow \quad 1 + R_t = \frac{P_t}{P_{t-1}}$$

In practice, asset prices between instants $ t $ and $ t - \Delta t $ are quite close and therefore $ R_t \ < < \ 1 $.

We know that in this case, $ ln(1 + R_t) \approx R_t $ so it is advisable to use the log-return

$$r_t = ln(1 + R_t) = ln\Bigg(\frac{P_t}{P_{t-1}}\Bigg) = ln(P_t)- ln(P_{t-1}) \approx R_t$$

We use log-return due to its statistical properties, such as stationarity and ergodicity.

We can describe some stylized facts that are found in most return series:

(i) stationarity;

(ii) weak linear and non-linear dependence;

(iii) heavy tails in the distribution and excess kurtosis;

(iv) conditional heteroscedastic behavior.

Heteroscedastic behavior brings together characteristics such as volatility clusters and leverage effects, which points to the shock effect. Negative shocks typically affect conditional volatility to a greater extent than positive shocks, that is, a drop in return implies high conditional volatility.

Example 5.1.1

Consider observations of Petrobras' actions on 07/21/2009 every minute, with a total of 401 observations. We calculate returns on this day.

(image missing)

20.5.2 Volatility

Volatility is one of the most relevant parameters in share pricing. It is a variable that is not directly observable. Furthermore, volatility in financial series is not constant over time, therefore responsible for their heteroscedastic behavior.

The volatility characteristics can be modeled by conditional heteroscedastic processes ARCH (Autoregressive Conditional Heteroscedasticity) introduced by Engle (1982) and its extension GARCH (Generalized ARCH) proposed by Bollerslev (1986).

20.5.2.1 ARCH Models

The first model developed to estimate volatility was proposed by Engle (1982) called ARCH (Autoregressive Conditional Heteroscedasticity) which uses a quadratic function of past observations to estimate volatility at time t.

Consider $ r_t $ a stationary time series of returns, we estimate its conditional variance(volatility) $ h_t $ in the instant $ t $ using an ARCH model of order q by

$$r_t = \sqrt{h_t} \varepsilon_t,$$

$$h_t = \alpha_0 + \alpha_1r_{t-1}^2 + \cdots + \alpha_qr_{t-q}^2$$

where $ \alpha_0 \ > \ 0, \alpha_i \ge 0, i=1,2,…,q-1, \alpha_q \ > \ 0 $ are conditions that guarantee the positivity of $ h_t $, furthermore it follows that $ \varepsilon_t $ is i.i.d. with mean zero, and has a normal or t-student distribution. The constants $ \alpha_i, i = 0,1,2,…,q $ are calculated using Linear Regression.

A condition that guarantees that an ARCH(q) process is stationary

$$ \sum^q_{i = 1} \alpha_i \ < \ 1.$$

A stationary ARCH process has the following statistics

$$E(r_t) = 0$$

$$Var(r_t) = \alpha_0 / \Bigg (1 - \sum^q_{i=1} \alpha_i \Bigg)$$

$$Cov(r_t,r_{t-k}) = E(r_t,r_{t-k}) = 0, \quad k = 1, 2,…$$

To better understand an ARCH model, let us consider an ARCH(1) model, in which its conditional variance depends only on the previous instant.

$$r_t = \sqrt{h_t} \varepsilon_t$$

$$h_t = \alpha_0 + \alpha_1r_{t-1}^2$$

with $ \alpha_0 \ > \ 0 $ and $ \alpha_1 \ge 0 $.

It can be demonstrated that the model has the following properties:

  1. The unconditioned average of $ r_t $ is zero;
  2. The unconditional variance of $ r_t $ is given by $ Var(r_t) = \frac{\alpha_0}{1 - \alpha_1}. $

When building ARCH models, a first step is to try to fit an ARIMA model, to remove serial correlation in the series, if it exists.

It follows that when we refer to $ r_t $, we are assuming that the return series is uncorrelated or is the residue of applying an ARIMA model to the original series.

To check whether the series presents conditional heteroscedasticity, we can apply the Ljung - Box test to the series $ r_t^2 $.

Example 5.2.1.1

We consider a time series with Petrobras share prices during 07/21/2009 minute by minute. We will calculate the series of returns and adjust an ARCH model to calculate volatility on this day.

(image missing)

Applying the Ljung - Box test to analyze the autocorrelation of $ r_t^2 $ we obtain a p-value of 0.5049, that is, we accept that the series is not i.i.d., that is, there is autocorrelation in the series. We then need to fit an ARIMA model to the return series.

Using the AIC information criterion, we identified an ARIMA(2,0,0) model as the best fit to the return series.

$$r_t = 0,18r_{t-1} - 0,09r_{t-2} + a_t$$

In this way, by adjusting an ARIMA(2,0,0)-ARCH(1) model, we have that the conditional variance (volatility) can be calculated at each time t by

$$r_t = 0,18r_{t-1} - 0,09r_{t-2} + a_t$$

$$a_t = \sqrt{h_t}\varepsilon_t$$

$$h_t = 1.6 \ast 10^{-8} + 0,139a_{t-1}^2$$

Carrying out an analysis of the model’s residuals, we verified normality in the residuals and using the Ljung - Box test we obtained a p-value of 0.95 indicating that the model is suitable for modeling linear dependence between successive returns.

(image missing)

Example 5.2.1.2

Consider the values of Petrobras shares, minute by minute, during July 8, 2010. We will model the observations through a time series, calculate the returns and volatility using ARCH.

(image missing)

Initially we applied the Ljung - Box test for autocorrelation in returns and with a p-value = 0.99 we rejected the hypothesis of the observations being i.i.d.. Therefore, we need to fit an ARIMA model to the returns in order to use ARCH to calculate volatility.

Through the ADF test, we detected that the series of returns is not stationary. We calculated the series of differences to achieve stationarity and identified the ARIMA(2,1,3) model as the best model to describe the observations using the AIC criterion.

$$r_t = -1,84r_{t-1} - 0,88r_{t-2} + a_t - 0,87a_{t-1} + 0,95a_{t-2} + 0,87a_{t-3}$$

From the residuals of the ARIMA(2,1,3) model, we calculated 4 ARCH models to identify the best one using the AIC criterion

Model AIC
ARCH(1) -6244,382
ARCH(2) -6345,931
ARCH(3) -6349,556
ARCH(4) -6339,856

Therefore, the best model using the AIC criterion is ARCH(3)

$$r_t = -1,84r_{t-1} - 0,88r_{t-2} + a_t - 0,87a_{t-1} + 0,95a_{t-2} + 0,87a_{t-3}$$

$$a_t = \sqrt{h_t}\varepsilon_t$$

$$h_t = 3,24 \ast 10^{-9} + 0,009a_{t-1}^2 + 0,18a_{t-2} + 3,4 \ast 10^{-15}a_{t-3}$$

(image missing)

20.5.2.2 GARCH Models

GARCH models (generalized ARCH) are a generalization of the ARCH models, proposed by Bollerslev (1986). The difference between the models is an additional component, referring to the conditional variance in previous moments. The advantage of the GARCH model is that it can be used to describe volatility with fewer parameters than an ARCH model.

A GARCH(p,q) model is defined by

$$r_t = \sqrt{h_t}\varepsilon_t,$$

$$h_t = \alpha_o + \sum_{i=1}^{p}\alpha_ir_t^2 + \sum^q_{j=1}\beta_jh_{t-j}$$

in which $ \varepsilon_t $ is i.i.d., $ \alpha_0 \ > \ 0, \alpha_i \ge 0, \beta_j \ge 0 $. The model constants, $ \alpha_i $ and $ \beta_j $ are calculated using Linear Regression.

Analogously to the case of the ARCH model, it follows that the $ \varepsilon_t $ are normal or follow a Student’s t-distribution.

Stationarity of a GARCH model of order (p,q) is guaranteed if

$$\sum_{i=1}^m(\alpha_i + \beta_i) \ < \ 1, \quad \text{em que }m = max(p,q).$$

Identifying the order of a GARCH model to be applied to a real time series is difficult, it is recommended that you adjust several low-order models and then choose the best one based on several criteria, such as AIC or BIC, asymmetry and kurtosis values, log-likelihood or some loss function.

Example 5.2.2.1

Consider the IBOVESPA time series, referring to 07/29/2009 with observations generated minute by minute. Let’s calculate the return series and adjust a GARCH(1,1) model to calculate volatility.

(image missing)

Applying the Ljung - Box test to analyze the autocorrelation of $ r_t $, we accept the hypothesis that the returns are i.i.d., so we do not need to use an ARIMA model to fit the data.

We fit a GARCH(1,1) model directly to the returns and obtain

$$r_t = \sqrt{h_t}\varepsilon_t$$

$$h_t = 7,617 \ast 10^{-7} + 0,127r_{t-1}^2 + 0,843h_{t-1}^2$$

Carrying out an analysis of the model’s residuals, we verified the normality of the residuals and, using the Ljung - Box test on the square of the residuals, we obtained a p-value = 0.806, indicating that the model is appropriate to describe the linear dependence between successive returns.

(image missing)

Example 5.2.2.2

Consider the Bovespa Indices during May 5, 2010. We will model the minute-by-minute observations through a time series and calculate the returns and volatilities using GARCH.

(image missing)

Initially we applied the Ljung - Box test for autocorrelation in returns and accepted the hypothesis that returns are i.i.d., therefore, we can calculate volatility directly in returns.

We checked 4 models to identify the best one for calculating volatility using the AIC criterion, we obtained

Model AIC
GARCH(1,1) -6448,39
GARCH(1,2) -6359,22
GARCH(2,1) -6354,13
GARCH(2,2) -6359,84

In this way, we identified GARCH(1,1) as the most suitable model for calculating volatility.

$$r_t = \sqrt{h_t}\varepsilon_t$$

$$h_t = 2,743 \ast 10^{-7} + 0,25r_{t-1}^2 + 0,58h_{t-1}^2$$

Carrying out an analysis of the model’s residuals, we verified the normality of the residuals and, using the Ljung - Box test on the square of the residuals, we obtained a p-value = 0.466, indicating that the model is appropriate to describe the linear dependence between successive returns.

(image missing)

20.5.3 Cointegration in Time Series

Cointegration in time series is extremely important for those who work with economic series, as they make it possible to study and analyze structural relationships between the series involved. More precisely, cointegration tests allow us to determine whether or not the time series involved have a long-term relationship.

coint

There are several tests in the literature to detect cointegration in time series. The most complex ones use an autoregressive vector representation, proposed by Johansen, and we have tests that consist of regression models, studying a linear combination between the time series involved.

20.5.3.1 Introduction

To begin the study on cointegration we need to understand some initial concepts. Consider a simple linear regression model for $ y_t $ containing a fixed linear trend, of slope $ \beta $.

$$y_t = y_0 + \beta t + u_t, \quad t=1,…,T$$

So, the error term $ u_t $ is a first order autoregressive process

$$u_t = \rho u_{t-1} + \varepsilon_t$$

where $ \varepsilon_t $ is white noise, that is, it is a sequence of random I.I.D errors with distribution $ N(0,\sigma^2_\varepsilon) $.

Rewriting the above equation using the delay operator, we have

$$u_t = \frac{\varepsilon_t}{1 - \rho L}$$

Analyzing $ \rho $ we realize that if $ |\rho| < 1 $ we can expand the term $ 1/(1 - \rho L) $ by $ (1 + \rho L + \rho^2 L^2 + \cdots) $, then

$$u_t = \varepsilon_t + \rho \varepsilon_{t-1} + \rho^2 \varepsilon_{t-2} + \cdots$$

In this case, $ u_t $ will be the sum of white noise $ \varepsilon_{t-i} $ such that the disturbance effect decreases over time, as $ |\rho| < 1 $. We then say that the process $ u_t $ is non-integrated, or even integrated of order 0, denoted by $ u_t \sim I(0) $. Using words we already know, this means that the process $ u_t $ It has no unit root and is stationary.

Case $ \rho = 1 $ we have

$$u_t = \varepsilon_t + \varepsilon_{t-1} + \varepsilon_{t-2} + \cdots$$

then, $ u_t $ will have a persistent disturbance that tends to infinity over time, known as stochastic tendency $ \sum_{i=1}^t \varepsilon_t $. If we analyze the roots of the term $ (1 - \rho L) $ we notice that $ u_t $ It has a unit root and is therefore non-stationary. We then say that $ u_t $ is integrated of order 1, denoted by $ u_t \sim I(1) $.

Cointegration

To determine whether two or more time series are cointegrated we need some hypotheses to be verified:

  • The two series are non-stationary of order I(1);

  • There is at least one linear combination of time series in which the residual of the regression between them is stationary.

With these hypotheses satisfied, we say that there is a cointegration relationship in the time series involved.

Definition 6.1

We say that two time series $ X_t $ and $ Y_t $ non-stationary structures of order I(1) are cointegrated if there is a $ \beta $ such that

$$Z_t = Y_t - \beta X_t$$

So that the series $ Z_t $, known as Residual Spread, is stationary.

20.5.3.2 Engle - Granger Test

The best-known test to detect cointegration between time series is the Engle - Granger test, which basically follows the definition of cointegration. The test hypotheses are

Screenshot_27

Be $ X_t $ and $ Y_t $ two time series. Firstly we need to check whether $ X_t $ and $ Y_t $ are non-stationary of order I(1), for this we can use some unit root test, for example: ADF test, PP test or KPPS test.

After verifying the presence of a unit root in the time series $ X_t $ and $ Y_t $, we need to define which type of regression best suits our data, among the cases: With intercept, with trend and intercept or without any additional terms. In each case, the regression models are given by

$$Z_t = Y_t - \beta X_t + \alpha $$

$$Z_t = Y_t - \beta X_t + \gamma t + \alpha $$

$$Z_t = Y_t - \beta X_t $$

respectively, where $ \beta $ is the cointegration parameter, $ \alpha $ is the intercept (constant) and $ \gamma $ is the trend parameter.

Thus, we again applied a unit root test to the residues, respecting the model adopted in $ Z_t $, however, with slightly altered critical values as we are reapplying the test in an approximation. In this case, these values ​​were simulated using Monte Carlo simulation.

Example 5.3.2.1

Be $ X_t $ and $ Y_t $ two time series of the daily closing values of ACBC4 and ITUB3 assets on the São Paulo stock exchange, during the period from August 9, 2011 to August 22, 2013. We will check whether there is cointegration between $ X_t $ and $ Y_t $.

First, we applied the ADF test to the series $ X_t $ and $ Y_t $, obtaining p-values of 0.569 and 0.592 respectively, therefore we accept the null hypothesis of the series being non-stationary.

Calculating the parameter $ \beta $ we get the spread

$$Z_t = Y_t - 0,4671 X_t$$

Applying the ADF test to the regression residual we obtain a p-value of 0.031, therefore, we reject the null hypothesis that the series $ X_t $ and $ Y_t $ not be cointegrated, that is, $ X_t $ and $ Y_t $ are cointegrated.

exemplo611

20.5.3.3 Phillips - Ouliaris test

Phillips and Ouliaris proposed two tests based on residuals, called Variance Rate and Multivariate Trace. The difference between them is that the test using Multivariate Trait statistics has the property of being invariant to normalization, that is, which variable is explained and which is explanatory.

The test hypotheses are:

Screenshot_28

Be $ x_t $ and $ y_t $ two time series. Initially we check whether the series $ x_t $ and $ y_t $ are non-stationary of order I(1) using some unit root test: ADF test, PP test or KPPS test.

After verifying the presence of a unit root in $ x_t $ and $ y_t $ we take the partition $ \mu_t = (y_t, x_t \prime) $ we calculate a first order autoregressive vector, that is, we perform a regression of $ \mu_t $ in $ \mu_{t-1} $ no intercept

$$\mu_t = \alpha \mu_{t-1} + r_t$$

Based on the residual from the lag regression, Phillips and Ouliaris propose two statistics that can be used to detect cointegration between time series:

  • Variance Rate:

$$P_u = \frac{N^2\hat{\omega_{11.2}}}{\sum^N_{i=1}\hat{r_i}^2}$$

where

$$\hat{\omega_{11.2}} = \hat{\omega_{11}} - \hat{\omega_{21}}\prime\hat{\Omega_{22}}^{-1} \hat{\omega_{21}}$$

Such that $ \Omega $ represents variance and covariance matrix written in the form

Screenshot_29

and is estimated by

$$ \hat{\Omega} = N^{-1}\sum_{t=1}^N r_t^2 + N^{-1}\sum_{s=1}^l w_{sl}\sum_{t = s+1}^N (r_t r_{t-s}\prime+r_{t-s}r_t\prime)$$

where $ r_t $ are the residuals from the above lag regression and $ w_{ls} = 1 - s/(l+1) $ for some number of lags $ l $.

  • Multivariate Trait:

$$P_z = N tr(\hat{\Omega}M_{zz}^{-1}), \quad \hbox{onde} \quad M_{zz} = N^{-1}\sum_{t=1}^N \mu_t \mu_t\prime$$

in which $ \hat{\Omega} $ same as defined above.

Example 5.3.3.1

Consider the financial assets of the São Paulo stock exchange, ITSU4 and ITUB4. We will analyze whether financial assets are cointegrated during the period from 01/08/2011 to 09/09/2013 with observations every 15 minutes in a total of 14531 observations.

We use Action to perform the calculations and obtain the results:

exemplo5331_tabelas

exemplo5331

Therefore, we reject the null hypothesis that there is no cointegration between the time series.

20.5.3.4 Vector Autoregressive Model (VAR)

This methodology is an extension of a univariate regression to a multivariate environment, where each equation defined by VAR is an ordinary least squares regression of a given variable on variables lagged by itself and other variables that make up the model.

The VAR model can be expressed by

$$X_t = A_0 + A_1X_{t-1} + \cdots + A_pX_{t-p} + B_0Z_1 + B_1Z_{t-1} + \cdots + B_pZ_{t-p} + e_t$$

where:

  • $ A_0 $ is the vector of intercept terms;
  • $ A_1,..,A_p $ are matrices $ N \times N $ of coefficients that relate lagged values of endogenous variables.
  • $ B_0,…,B_p $ are matrices $ N \times N $ that report current and lagged values of exogenous variables;
  • $ e_t $ is a vector $ N \times 1 $ of errors.

To select the best VAR model, the SC and AIC information criteria are used, which are important to determine the number of lags to be included in the model. Thus, as these criteria take into account the sum of the squares of the residuals, the number of observations and parameter estimators, the lower the values, the better the model.

In the cointegration study, an adaptation of the VAR model was proposed, known as the error correction model (VEC) which can be written as

$$\Delta Z_t = \Gamma_1 \Delta Z_{t-1} + \cdots + \Gamma_{k-1} \Delta Z_{t-k+1} + \Pi Z_{t-k} + \Phi D_t + u_t$$

where:

  • $ Z_t $ is a vector with k variables;
  • $ u_t $ is a random error vector;
  • $ D_t $ is a binary vector to capture seasonal variation;
  • $ \Gamma_i = -(I - A_1 - \cdots - A_i), (i = 1,2,…,k-1) $;
  • $ \Pi = -(I - A_1 - \cdots - A_k) $

in which the matrix $ \Pi $ is of fundamental importance in the analysis of cointegration, each line of $ \Pi $ represents a cointegration relationship.

20.5.3.5 Johansen test

Be $ Z_t $ a matrix $ (n \times p) $ of time series with each column representing a time series. To use Johansen’s methodology it is necessary to model $ Z_t $ as an unconstrained vector autoregressive (VAR) involving k lags of $ Z_t $. The VAR model can be written as follows

$$Z_t = A_1 Z_{t-1} + \cdots + A_k Z_{t-k} + \Phi D_t + u_t$$

where $ u_t \sim IN(0, \sum), Z_t $ is a vector $ (n \times 1) $ and each element $ A_i $ is an array of order parameters $ (n \times n) $ and $ D_t $ represents deterministic terms such as constant, linear trend, and seasonality.

In the case of Johansen’s methodology, it is also necessary to determine the order of the lag of $ Z_t $, as this procedure is based on the hypothesis that by introducing a certain lag number, it is possible to obtain well-behaved residues, that is, stationary.

In this way, the above equation can be modified in terms of an error correction model (VEC) as follows

$$\Delta Z_t = \Gamma_1 \Delta Z_{t-1} + \cdots + \Gamma_{k-1} \Delta Z_{t-k+1} + \Pi Z_{t-k} + \Phi D_t + u_t$$

where $ \Gamma_i = -(I - A_1 - \cdots - A_i), (i = 1,2,…,k-1), $ and $ \Pi = -(I - A_1 - \cdots - A_k) $. The main advantage of writing the system in terms of the error correction model is the fact that long-term and short-term information is incorporated in this format.

Johansen’s methodology presents three situations based on the position of $ \Pi $

  1. $ \Pi $ has full rank. In this case we have $ p = r $ linearly independent columns, then the variables in $ Z_t $ are $ L(0) $, that is, the series in $ Z_t $ are stationary.
  2. $ \Pi $ has rank equal to zero, then there is no cointegration in the time series of $ Z_t $
  3. $ \Pi $ has reduced rank. This is the most important case, when there is $ r \le (p-1) $ cointegrated series in $ Z_t $, we can write $ \Pi = \alpha \beta $ being that $ \alpha $ is a matrix $ (n \times p) $ which represents the speed of adjustment of the matrix parameters in the short term and $ \beta $ is a matrix $ (n \times p) $ of long-run cointegration coefficients. We can then say that the term $ \beta Z_{t-k} $ represents the $ p-1 $ cointegration relationships in the multivariate model, thus ensuring that $ Z_t $ converges towards a long-term solution.

To test the presence of cointegrated series in $ Z_t $ There are two statistics to consider

$$J_{trace} = -T \sum_{i = r+1}^n ln(1 - \hat{\lambda}_i)$$

$$J_{max} = -T ln(1 - \hat{\lambda}_{r+1})$$

Screenshot_30

The statistic $ J_{trace} $ tests the hypotheses

$$H_0: \lambda_i = 0; \quad i=r+1, … , n$$

$$H_1: \lambda_i = 0; \quad i=1,2,…,n$$

In other words, the null hypothesis is that only $ r $ first eigenvalues are non-zero, that is, there is $ r $ cointegrated time series in $ Z_t $.

The statistic $ J_{max} $ tests the null hypothesis of existence $ r $ cointegrated series against exist $ r+1 $ cointegrated series, which in practice is not used, since the statistical test $ J_{trace} $ it has been shown to be more robust to symmetry and excess kurtosis.

The critical values of statistics $ J_{trace} $ were calculated by Johansen in 1995, through simulation studies using Brownian Motion.

Example 5.3.5.1

Consider $ Z_t $ a matrix with two time series referring to the financial assets GGBR4 and GOAU3 of the São Paulo stock exchange during the period from 08/09/2013 to 09/03/2013. Let’s test cointegration between assets using the Johansen test

Due to the fact that Johansen’s methodology is quite complex, it is not feasible to generate the calculations analytically. Therefore, using Action to perform the calculations we obtain the following results:

exemplo5351_tabela1

Therefore, we reject the hypothesis that there are 0 cointegrations and accept the hypothesis that there is 1 cointegration relation in $ Z_t $. Conclusion: The financial assets GGBR4 and GOAU3 are cointegrated.

exemplo5351

20.5.4 Pairs Trading

20.5.4.1 Introduction

Pairs trading is a strategy that involves finding cointegrated financial assets and by studying the spread it is possible to identify the right moments to invest in the financial assets involved.

We can divide the strategy into two stages:

  • Find pairs of cointegrated financial assets with the mean reversion characteristic, through historical data of financial assets;
  • Carry out tests on the spread to identify which parameters are the best times for investment.

To find out whether the cointegrated pair has the mean reversion property we can use the Dickley - Fuller test for stationarity. Consider the logarithm rate $ y_t = logA_t + logB_t $ where $ A_t $ and $ B_t $ are the prices of financial assets $ A $ and $ B $. So we tested

$$\Delta y_t = \mu + \gamma y_{t-1} + \varepsilon_t$$

In other words, we are testing $ \Delta y_t $ in the lagged values of $ y_t $. The null hypothesis of the test is that $ \gamma = 0 $, which implies that the process does not have mean reversion. Therefore, if we reject the null hypothesis with a confidence level greater than 99%, the process will be stationary and have the characteristic of mean reversion.

Studies say that if the confidence level of the test is not very high, the pairs do not have sufficiently good mean reversion, which implies unsatisfactory returns.

The second stage of the strategy is not exactly defined and has several different adjustments in each case that are essential to obtain a profit. We can consider that depending on the number of financial assets evaluated in the study, we will find many cointegrated pairs that can be evaluated for purchase and sale, but some pairs are not viable due to practical issues, such as the volume moved by financial assets.

Therefore, among the cointegrated pairs found, we used some measures to “filter” the results and use only pairs with potential.

References

[1] Morettin, Pedro A. “Financial econometrics.” Edgard Blücher, (2008).

[2] Morettin, Pedro A., and Clélia Toloi. Time series analysis. Blucher, 2006.

[3 ]Vidyamurthy, Ganapathy. Pairs Trading: quantitative methods and analysis. Vol. 217. John Wiley & Sons, 2004.

[4] Hendry, David F., and Katarina Juselius. “Explaining cointegration analysis: Part 1.” The Energy Journal (2000): 1-42.

[5] Hendry, David F., and Katarina Juselius. “Explaining cointegration analysis: Part II.” The Energy Journal (2001): 75-120.

Last modified 13.10.2026: ajuste das numerações (e4440012)
↑