<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>time series &#8211; Aptech</title>
	<atom:link href="https://www.aptech.com/blog/tag/time-series/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.aptech.com</link>
	<description>GAUSS Software - Fastest Platform for Data Analytics</description>
	<lastBuildDate>Thu, 19 Oct 2023 13:19:05 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>A Guide to Conducting Cointegration Tests</title>
		<link>https://www.aptech.com/blog/a-guide-to-conducting-cointegration-tests/</link>
					<comments>https://www.aptech.com/blog/a-guide-to-conducting-cointegration-tests/#comments</comments>
		
		<dc:creator><![CDATA[Eric]]></dc:creator>
		<pubDate>Tue, 28 Jan 2020 14:26:32 +0000</pubDate>
				<category><![CDATA[Econometrics]]></category>
		<category><![CDATA[Time Series]]></category>
		<category><![CDATA[cointegration]]></category>
		<category><![CDATA[error correction model]]></category>
		<category><![CDATA[time series]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=21405</guid>

					<description><![CDATA[Cointegration is an important tool for modeling the long-run relationships in time series data. If you work with time series data, you will likely find yourself needing to use cointegration at some point. This blog provides an in-depth introduction to cointegration and will cover all the nuts and bolts you need to get started. 
]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Cointegration is an important tool for modeling the long-run relationships in time series data. If you work with time series data, you will likely find yourself needing to use cointegration at some point.</p>
<p>This blog provides an in-depth introduction to cointegration and will cover all the nuts and bolts you need to get started. In particular, we will look at:</p>
<ul>
<li>The fundamentals of cointegration.</li>
<li>The error correction model.</li>
<li>How to prepare for cointegration testing. </li>
<li>What cointegration tests to use with and without structural breaks. </li>
<li>How to interpret cointegration tests. </li>
<li>How to perform cointegration tests in GAUSS.</li>
</ul>
<p>Though not necessary, you may find it helpful to review the blogs on <a href="https://www.aptech.com/blog/introduction-to-the-fundamentals-of-time-series-data-and-analysis/">time series modeling</a> and <a href="https://www.aptech.com/blog/how-to-conduct-unit-root-tests-in-gauss/">unit root testing</a> before continuing with this blog. </p>
<h2 id="what-is-cointegration">What is Cointegration?</h2>
<p>Economic theory suggests that many time series datasets will move together, fluctuating around a long-run equilibrium. In econometrics and statistics, this long-run equilibrium is tested and measured using the concept of cointegration.</p>
<p>Cointegration occurs when two or more nonstationary time series:</p>
<ul>
<li>Have a long-run equilibrium.</li>
<li>Move together in such a way that their linear combination results in a stationary time series.  </li>
<li>Share an underlying common stochastic trend. </li>
</ul>
<table>
 <thead>
 <tr>
      <th colspan="3">
         <h3 id="what-is-an-example-of-cointegrated-time-series"><br>What is an Example of Cointegrated Time Series? </h3>
      </th>
   </tr>

<tr><th>Field</th><th>Supporting Theory</th><th>Time Series</th></tr>
</thead>
<tbody>
<tr><td>Economics</td><td>The <a href="https://www.nber.org/chapters/c4405.pdf">permanent income hypothesis</a> describes how agents spread their consumption out  over their lifetime based on their expected income. </td><td>
Consumption and income.
</td></tr>
<tr><td>Economics</td><td>Purchasing power parity is a theory that relates the prices of a basket of goods across different countries.</td><td>Nominal exchange rates and domestic and foreign prices.</td></tr>
<tr><td>Finance</td><td>The present value model of stock prices implies a long-run relationship between stock prices and their dividends or earnings. 
</td><td>Stock prices and stock dividends/earnings.</td></tr>
<tr><td>Epidemiology</td><td><a href="https://ideas.repec.org/a/eee/insuma/v90y2020icp80-93.html">Joint mortality models</a> imply a long-run relationship between mortality rates across different demographics. </td><td>Male and female mortality rates.</td></tr>
<tr><td>Medicine</td><td><a href="https://papers.ssrn.com/sol3/papers.cfm?abstract_id=3311794">Time series methodologies</a> have been used to examine comorbidities of different types of cancers and trends in medical welfare.</td><td>Occurrence rates of different types of cancer.</td></tr>
</tbody>
</table>
<h3 id="the-mathematics-of-cointegration">The Mathematics of Cointegration</h3>
<p>To understand the mathematics of cointegration, let's consider a group of time series, $Y_t$, which is composed of three separate time series:</p>
<p>$$y_1 = (y_{11}, y_{12}, \ldots, y_{1t})$$
$$y_2 = (y_{21}, y_{22}, \ldots, y_{2t})$$
$$y_3 = (y_{31}, y_{32}, ..., y_{3t})$$ </p>
<p>All three series are <a href="https://www.aptech.com/blog/how-to-conduct-unit-root-tests-in-gauss/">nonstationary time series</a>. </p>
<p>Cointegration implies that while $y_1$, $y_2$, and $y_3$ are independently nonstationary, they can be combined in a way that their linear combination is stationary :</p>
<p>$$\beta Y_t = \beta_1 y_{1t} + \beta_2 y_{2t} + \beta_3 y_{3t} \sim I(0)$$</p>
<p><b>The Cointegrating Vector</b><br />
In the context of cointegration, $\beta$ is commonly known as the cointegrating vector. This vector:</p>
<ul>
<li>Dictates how cointegrating series are combined. </li>
<li>Does not have to be unique - there can be multiple ways of cointegrating.</li>
</ul>
<p><b>Normalization</b>
Because there can be multiple cointegrating vectors that fit the same economic model, we must impose identification restrictions to normalize the cointegrating vector for estimation. </p>
<p>A common normalization of the cointegrating vector is to set $\beta = ( 1,  -\beta_2, \ldots, -\beta_N)$. For example, applying these restrictions to our earlier system yields</p>
<p>$$\beta Y_t = y_{1t} - \beta_2 y_{2t} - \beta_3 y_{3t} \sim I(0)$$</p>
<p>Part of the appeal of this normalization is that it can be rewritten in a standard regression form</p>
<p>$$y_{1t} = \beta_2 y_{2t} + \beta_3 y_{3t} + u_t$$</p>
<p>where $u_t$ is a stationary cointegrating error component. Intuitively, $u_t$ can be thought of as short-term deviations from the long-run equilibrium. </p>
<p>While the regression format is a common normalization, it is important to remember that economic theory should inform our identifying restrictions. </p>
<h2 id="what-is-the-error-correction-model">What is the Error Correction Model?</h2>
<p>Cointegration implies that time series will be connecting through an error correction model. The error correction model is important in time series analysis because it allows us to better understand long-run dynamics. Additionally, failing to properly model cointegrated variables can result in biased estimates. </p>
<p>The error correction model:</p>
<ul>
<li>Reflects the long-run equilibrium relationships of variables. </li>
<li>Includes a short-run dynamic adjustment mechanism that describes how variables adjust when they are out of equilibrium.</li>
<li>Uses adjustment coefficients to measure the forces that push the relationship towards long-run equilibrium.</li>
</ul>
<h3 id="the-mathematics-of-the-error-correction-model">The Mathematics of the Error Correction Model</h3>
<p>Let's assume that there is a bivariate cointegrated system with $Y_t = (y_{1t}, y_{2t})$ and a cointegrating vector $\beta = (1, -\beta_2)$ such that </p>
<p>$$\beta Y_{t} = y_{1t} - \beta_2 y_{2t}$$</p>
<p>The error correction model depicts the dynamics of a variable as a function of the deviations from long-run equilibrium</p>
<p>$$\Delta y_{1t} = c_1 + \alpha_1 (y_{1,t-1} - \beta_2 y_{2,t-1}) + \sum_j \psi^j_{11} \Delta y_{1, t-j} + \sum_j \psi^j_{12} \Delta y_{2, t-j} + \epsilon_1t$$
$$\Delta y_{2t} = c_2 + \alpha_2 (y_{1,t-1} - \beta_2 y_{2,t-1}) + \sum_j \psi^j_{21} \Delta y_{1, t-j} + \sum_j \psi^j_{22} \Delta y_{2, t-j} + \epsilon_2t$$</p>
<table>
<thead>
<tr><th>Term</th><th>Description</th><th>Intuition</th></tr>
</thead>
<tbody>
<tr><td>$y_{1,t-1} - \beta_2 y_{2,t-1}$</td><td>Cointegrated long-run equilibrium</td><td>Because this is an equilibrium relationship, it plays a role in dynamic paths of both $y_{1t}$ and $y_{2t}$.</td></tr>
<tr><td>$\alpha_1$, $\alpha_2$</td><td>Adjustment coefficients</td><td>Captures the reactions of $y_{1t}$ and $y_{2t}$ to disequilibrium.</td></tr>
<tr><td>$\sum_j \psi^j_{11} \Delta y_{1, t-j} + \sum_j \psi^j_{12} \Delta y_{2, t-j}$</td><td>Autoregressive distributed lags</td><td>Captures additional dynamics.</td></tr>
</tbody>
</table>
<h3 id="estimating-the-error-correction-model">Estimating the Error Correction Model</h3>
<p>If the cointegrating vector has been previously estimated, then standard OLS or DOLS can be used to estimate the error correction relationship. In this case:</p>
<ul>
<li>The estimate of the cointegrating vector can be treated like a known variable.   </li>
<li>The estimated disequilibrium error can be treated like a known variable. </li>
</ul>
<p>The <a href="https://www.aptech.com/examples/tsmt/ecmfit-simulated/">ECM relationship can be estimated</a> using OLS, seemingly unrelated regressions (SUR), or maximum likelihood estimation.</p>
<h3 id="the-vector-error-correction-model-vecm">The Vector Error Correction Model (VECM)</h3>
<p>The vector error correction model (VECM) is the multivariate extension of the ECM. If we are working in a vector autoregressive context, cointegration implies a VECM such that</p>
<p>$$\Delta Y_t = \Phi D_t + \Pi Y_{t-1} + \Gamma_1 \Delta Y_{t-1} + \cdots + \Gamma_{p-1} \Delta Y_{t-p+1} + \epsilon_t$$ </p>
<p>Like the ECM, the VECM parameters reflect the long-run and short-run dynamics of system as shown in the table below:</p>
<table>
<thead>
<tr><th>Term</th><th>Description</th><th>Intuition</th></tr>
</thead>
<tbody>
<tr><td>$\Pi$</td><td>Long-run impact matrix.</td><td>$\Pi = \Pi_1 + \Pi_2 + \cdots + \Pi_p - I_n$, captures adjustments towards the long-run equilibrium and contains the cointegrating relationships.</td></tr>
<tr><td>$\Gamma_k$</td><td>Short-run impact matrix.</td><td>The short-run impact matrix is constructed from  $-\sum_{j=k+1}^p \Pi_j$ and captures short-run deviations from the equilibrium.</td></tr>
<tr><td>$D_t$</td><td>Deterministic terms.</td><td>These terms take the form $D_t = u_0 + u_1 t$ where $u_0$ is the constant component and $u_1 t$ is the trend component.</td></tr>
</tbody>
</table>
<h3 id="estimating-the-vecm">Estimating the VECM</h3>
<p>The VECM model can be estimated using the Johansen method:</p>
<ul>
<li>Estimate the appropriate VAR(p) model for $Y_t$.</li>
<li>Determine the number of cointegrating vectors, using a likelihood ratio test for the rank of $\Pi$.  </li>
<li>Impose identifying restrictions to normalize the cointegrating vector.</li>
<li>Using the normalized cointegrating vectors, estimate the resulting VECM by maximum likelihood.</li>
</ul>
<h2 id="preparing-for-cointegration-tests">Preparing For Cointegration Tests</h2>
<p>Before jumping directly to cointegration testing, there are a number of other time series modeling steps that we should consider first. </p>
<h3 id="establishing-underlying-theory">Establishing Underlying Theory</h3>
<p>One of the key considerations prior to testing for cointegration, is whether there is theoretical support for the cointegrating relationship.  It is important to remember that cointegration occurs when separate time series share an underlying stochastic trend. The idea of a shared trend should be supported by economic theory.</p>
<p>As an example, consider growth theory which suggests that productivity is a key driver of economic growth. As such, it acts as the common trend, driving the comovements of many indicators of economic growth. Hence, this theory implies that consumption, investment, and income are all cointegrated. </p>
<h3 id="time-series-visualization">Time Series Visualization</h3>
<p>One of the first steps in time series modeling should be data visualization. <a href="https://www.aptech.com/resources/tutorials/time-series-plots/">Time series plots</a> provide good preliminary insights into the behavior of time series data:</p>
<ul>
<li>Is a series mean-reverting or has explosive behavior?</li>
<li>Does it have a time trend?</li>
<li>Is there seasonality?</li>
<li>Are there structural breaks?</li>
</ul>
<h3 id="unit-root-testing">Unit Root Testing</h3>
<p>We've established that cointegration occurs between nonstationary, I(1), time series. This implies that before testing for or estimating a cointegrating relationship, we should perform <a href="https://www.aptech.com/why-gauss-for-unit-root-testing/">unit root testing</a>.  </p>
<p>Our previous blog, <a href="https://www.aptech.com/blog/how-to-conduct-unit-root-tests-in-gauss/">&quot;How to Conduct Unit Root Testing in GAUSS&quot;</a>, provides an in-depth look at how to perform unit root testing in GAUSS.  </p>
<p>GAUSS tools for performing unit root tests are available in a number of libraries, including the <a href="https://store.aptech.com/gauss-applications-category/time-series-mt.html">Time Series MT (TSMT)</a>, the open-source <a href="https://github.com/aptech/tspdlib">TSPDLIB</a>, and the <a href="https://store.aptech.com/third-party-applications-category/coint-2-1-co-integrated-systems.html">coint</a> libraries.  All of these can be directly located and installed using the <a href="https://www.aptech.com/blog/gauss-package-manager-basics/">GAUSS package manager</a>. </p>
<p>Full example programs for testing for unit roots using TSMT procedures and TSPDLIB procedures are available on our <a href="https://github.com/aptech/gauss_blog/tree/master/time_series/cointegration-1.20.19">Aptech GitHub page</a>. </p>
<table>
<thead>
<tr><th>Panel Data Unit Root Test</th><th>TSMT procedure</th><th>TSPDLIB procedure</th></tr>
</thead>
<tbody>
<tr><td><b>Hadri</b></td><td>hadri</td><td></td></tr>
<tr><td><b>Im, Pesaran, and Shin</b></td><td>ips</td><td></td></tr>
<tr><td><b>Levin-Lu-Chin</b></td><td>llc</td><td></td></tr>
<tr><td><b>Schmidt and Perron LM test</b></td><td></td><td>lm</td></tr>
<tr><td><b>Breitung and Das</b></td><td>breitung</td><td></td></tr>
<tr><td><b>Cross-sectionally augmented IPS test (CIPS)</b></td><td></td><td><a href="https://github.com/aptech/tspdlib/blob/master/examples/cips.e">cips</a></td></tr>
<tr><td><b>Panel analysis of nonstationary and idiosyncratic and common (PANIC)</b></td><td></td><td><a href="https://github.com/aptech/tspdlib/blob/master/examples/panic_bng.e">bng_panic</a></td></tr>
</tbody>
</table>
<table>
<thead>
<tr><th>Time Series Unit Root Test</th><th>TSMT procedure</th><th>TSPDLIB procedure</th></tr>
</thead>
<tbody>
<tr><td><b>Augmented-Dickey Fuller</b></td><td>vmadfmt</td><td><a href="https://github.com/aptech/tspdlib/blob/master/examples/adf.e">adf</a></td></tr>
<tr><td><b>Phillips-Perron</b></td><td>vmppmt</td><td><a href="https://github.com/aptech/tspdlib/blob/master/examples/pp.e">pp</a></td></tr>
<tr><td><b>KPSS</b></td><td>kpss</td><td>lmkpss</td></tr>
<tr><td><b>Schmidt and Perron LM test</b></td><td></td><td>lm</td></tr>
<tr><td><b>GLS-ADF</b></td><td>dfgls</td><td><a href="https://github.com/aptech/tspdlib/blob/master/examples/dfgls.e">dfgls</a></td></tr>
<tr><td><b>Quantile ADF</b></td><td></td><td><a href="https://github.com/aptech/tspdlib/blob/master/examples/qr_adf.e">qr_adf</a></td></tr>
</tbody>
</table>
<h3 id="testing-for-structural-breaks">Testing for structural breaks</h3>
<p>A complete time series analysis should consider the possibility that <a href="https://www.aptech.com/structural-breaks/">structural breaks</a> have occurred. In the case that structural breaks have occurred, standard tests for cointegration are invalid. </p>
<p>Therefore, it is important to:</p>
<ul>
<li>Test whether structural breaks occur in the individual series. </li>
<li>In the case that there is evidence of structural breaks, employ cointegration tests that allow for structural breaks.</li>
</ul>
<p>The GAUSS <code>sbreak</code> procedure, available in TSMT, is an easy-to-use tool for identifying multiple, unknown structural breaks. </p>
<h2 id="cointegration-tests">Cointegration Tests</h2>
<p>In order to test for cointegration, we must test that a long-run equilibrium exists for a group of data. There are a number of things that need to be considered:</p>
<ul>
<li>Are there multiple cointegrating vectors or just one?</li>
<li>Is the cointegrating vector known or does it need to be estimated?</li>
<li>What deterministic components are included in the cointegrating relationship?</li>
<li>Do we suspect structural breaks in the cointegrating relationship?</li>
</ul>
<p>In this section, we will show how to use these questions to guide cointegration testing without structural breaks.  </p>
<h3 id="the-engle-granger-cointegration-test">The Engle-Granger Cointegration Test</h3>
<p>The Engle-Granger cointegration test considers the case that there is a single cointegrating vector. The test follows the very simple intuition that if variables are cointegrated, then the residual of the cointegrating regression should be stationary. </p>
<p><b> Forming the cointegrating residual</b><br />
How to form the cointegrating residual depends on if the cointegrating vector is known or must be estimated:</p>
<p><b>If the cointegrating vector is known,</b> the cointegrating residuals are directly computed using $u_t = \beta Y_t$. The residuals should be stationary and:</b>  </p>
<ul>
<li>Any standard unit root tests, such as the ADF or PP test, can be used to test the residuals. The test statistics follow the standard distributions.</li>
<li>The test compares the null hypothesis of no cointegration against the alternative of cointegration.</li>
<li>The cointegrating residuals should be examined for the presence of a constant or trend, and the appropriate unit root test should be utilized. </li>
</ul>
<p><b>If the cointegrating vector is unknown</b>, OLS is used to estimate the normalized cointegrating vector from the regression
$$y_{1t} = c + \beta y_{2t} + u_{t}$$</p>
<ul>
<li>The residuals from the cointegrating regression are estimated
$$\hat{u_t} = y_{1t} - \hat{c} - \hat{\beta_2}y_{2t}$$</li>
<li>Any standard <a href="https://www.aptech.com/blog/how-to-conduct-unit-root-tests-in-gauss/">unit root test</a>, such as the ADF or PP test, can be used to test the residuals. The test statistics follow the nonstandard Phillips-Ouliaris (PO) distributions. </li>
<li>The PO distribution depends on the trend behavior of the data. </li>
</ul>
<h3 id="the-johansen-tests">The Johansen Tests</h3>
<p>There are two Johansen cointegrating tests for the VECM context, the trace test and the maximal eigenvalue test. These tests hinge on the intuition that in the VECM, the rank of the long-run impact matrix, $\Pi$, determines if the VAR(p) variables are cointegrated. </p>
<p>Since the rank of the long-run impact matrix equals the number of cointegrating relationships:</p>
<ul>
<li>A likelihood ratio statistic for determining the rank of $\Pi$ can be used to establish the number of cointegrating relationships.</li>
<li>Sequential testing can be used to test the number, $k$, of the cointegrating relationships. </li>
</ul>
<p>The Johansen testing process has two general steps:</p>
<ol>
<li>Estimate the VECM model using maximum likelihood under various assumptions:
<ul>
<li>With and without trend. </li>
<li>With and without constant. </li>
<li>With varying number, $k$, of cointegrating vectors.</li>
</ul></li>
<li>Compare the models using likelihood ratio tests. </li>
</ol>
<p><b>The Johansen Trace Statistics</b><br />
The Johansen trace statistic:</p>
<ul>
<li>Is a likelihood ratio test of an unrestricted VECM against the restricted VECM with $k$ cointegrating vectors, where $k = m-1, \ldots, 0$.   </li>
<li>Is formed from the trace of a diagonal matrix of generalized eigenvalues from $\Pi$. </li>
<li>As the $LR_{trace}(k)$ statistic gets closer to zero, we are less likely to reject the null hypothesis. </li>
<li>If the $LR_{trace}(k)>CV$, then the null hypothesis is rejected. </li>
</ul>
<p>The Johansen testing procedure sequentially tests the null hypothesis that the number of cointegrating vectors, $k = m$ against the alternative that $k > m$.</p>
<table>
<thead>
<tr><th>Stage</th><th>Null Hypothesis</th><th>Alternative</th><th>Conclusion</th></tr>
</thead>
<tbody>
<tr><td>One</td><td>$H_0: k = 0$</td><td>$H_A: k&gt;0$</td><td>If $H_0$ cannot be rejected, stop testing, and $k = 0$. If null is rejected, perform next test.</td></tr>
<tr><td>Two</td><td>$H_0: k \leq 1$</td><td>$H_A: k&gt;1$</td><td>If $H_0$ cannot be rejected, stop testing, and $k \leq 1$. If null is rejected, perform next test.</td></tr>
<tr><td>Three</td><td>$H_0: k \leq 2$</td><td>$H_A: k&gt;2$</td><td>If $H_0$ cannot be rejected, stop testing, and $k \leq 2$. If null is rejected, perform next test.</td></tr>
<tr><td>m-1</td><td>$H_0: k \leq m-1$</td><td>$H_A: k&gt;m-1$</td><td>If $H_0$ cannot be rejected, stop testing, and $k \leq m-1$. If null is rejected, perform next test.</td></tr>
</tbody>
</table>
<p>The test statistic follows a nonstandard distribution and depends on the dimension and the specified deterministic trend.</p>
<p><b>The Johansen Maximum Eigenvalue Statistic</b><br />
The maximal eigenvalue statistic:</p>
<ul>
<li>Considers the null hypothesis that the cointegrating rank is $k$ against the alternative hypothesis that the cointegrating rank is $k + 1$.</li>
<li>The statistic follows a nonstandard distribution.</li>
</ul>
<h2 id="cointegration-test-with-structural-breaks">Cointegration Test with Structural Breaks</h2>
<p>In the case that there are structural breaks in the cointegrating relationship, the cointegration tests in the previous station should not be used. In this section we look at three tests for cointegration with structural breaks:</p>
<ul>
<li>The <a href="https://www.sciencedirect.com/science/article/abs/pii/0304407669416857">Gregory and Hansen (1996)</a> test for cointegration with a single structural break.</li>
<li>The <a href="https://ideas.repec.org/c/boc/bocode/g00006.html">Hatemi-J test (2009)</a> for cointegration with two structural breaks. </li>
<li>The Maki test for cointegration with multiple structural breaks. </li>
</ul>
<h3 id="the-gregory-and-hansen-cointegration-test">The Gregory and Hansen Cointegration Test</h3>
<p>The Gregory and Hansen (1996) cointegration test is a residual-based cointegration test that tests the null hypothesis of no cointegration against the alternative of cointegration in the presence of a <a href="https://www.aptech.com/structural-breaks/">single regime shift</a>. </p>
<p>The <a href="https://www.sciencedirect.com/science/article/abs/pii/0304407669416857">Gregory and Hansen (1996)</a> test:</p>
<ul>
<li>Is an extension of the ADF and PP residual tests for cointegration.</li>
<li>Allows for unknown regimes shifts in either the intercept or the coefficient vector.</li>
<li>Is valid for three different model cases: level shift with trend, regime shifts (changes in coefficients), regime shift with a shift in trend.</li>
</ul>
<p>Because the structural break date is unknown, the test computes the cointegration test statistic for each possible breakpoint, and the smallest test statistics are used.</p>
<p>Gregory and Hansen (1996) suggest running their tests in combination with the standard cointegration tests:</p>
<ul>
<li>If the standard ADF test and the Gregory and Hansen ADF test both reject the null hypothesis of no cointegration, there is evidence in support of cointegration. </li>
<li>If the standard ADF test does not reject the null hypothesis but the Gregory and Hansen ADF does, structural change in the cointegrating vector <em>may</em> be important.</li>
<li>If the standard ADF test and the Gregory and Hansen ADF both reject the null hypothesis, there is no evidence from this test that structural change has occurred. </li>
</ul>
<h3 id="the-hatemi-j-cointegration-test-with-two-structural-breaks">The Hatemi-J Cointegration Test with Two Structural Breaks</h3>
<p>The Hatemi-J cointegration test is an extension of the Gregory and Hansen cointegration test. It allows for two possible structural breaks with unknown timing.  </p>
<h3 id="the-maki-cointegration-test">The Maki Cointegration Test</h3>
<p>The Maki cointegration test builds on the Gregory and Hansen and the Hatemi-J cointegration tests to allow for an unknown number of structural breaks. </p>
<h2 id="where-to-find-cointegration-tests-for-gauss">Where to Find Cointegration Tests for GAUSS</h2>
<p>GAUSS tools for performing cointegration tests and estimating VECM models are available in a number of libraries, including the <a href="https://store.aptech.com/gauss-applications-category/time-series-mt.html">Time Series MT (TSMT) library</a>,  <a href="https://github.com/aptech/tspdlib">TSPDLIB</a>, and the <a href="https://store.aptech.com/third-party-applications-category/coint-2-1-co-integrated-systems.html">coint</a> libraries.  All of these can be directly located and installed using the <a href="https://www.aptech.com/blog/gauss-package-manager-basics/">GAUSS package manager</a>. </p>
<table>
<thead>
<tr><th>Cointegration test</th><th>Null Hypothesis</th><th>Decision Rule</th><th>GAUSS library</th></tr>
</thead>
<tbody>
<tr><td><b>Engle-Granger (ADF)</b></td><td>No cointegration.</td><td>Reject the null hypothesis if the $ADF$ test statistic is less than the critical value.</td><td>TSMT, tspdlib, coint</td></tr>
<tr><td><b>Phillips</b></td><td>No cointegration.</td><td>Reject the null hypothesis if the $Z$ test statistic is less than the critical value.</td><td>coint, tspdlib</td></tr>
<tr><td><b>Stock and Watson common trend</b></td><td>$Y$ is a non-cointegrated system after allowing for the pth order polynomial common trend.</td><td>Reject the null hypothesis if the $SW$ test statistic is less than the critical value.</td><td>coint</td></tr>
<tr><td><b>Phillips and Ouliaris </b></td><td>$Y$ and $X$ are not cointegrated.</td><td>Reject the null hypothesis if the $P_u$ or $P_z$ statistic is greater than the critical value.</td><td>coint, tspdlib</td></tr>
<tr><td><b>Johansen trace</b></td><td>Rank of $\Pi$ is equal to $r$ against the alternative that the rank of $\Pi$ is greater than $r$.</td><td>Reject the null hypothesis if $LM_{max}(k)$ is greater than the critical value.</td><td>TSMT, coint</td></tr>
<tr><td><b>Johansen maximum eigenvalue</b></td><td>Rank of $\Pi$ is equal to $r$ against the alternative that the rank of $\Pi$ is equal to $r+1$.</td><td>Reject the null hypothesis if $LM(r)$ is greater than the critical value.</td><td>TSMT, coint</td></tr>
<tr><td><b>Gregory and Hansen</b></td><td>No cointegration against the alternative of cointegration with one structural break.</td><td>Reject the null hypothesis if $ADF$, $Z_{\alpha}$, or $Z_t$ are less than the critical value.</td><td>tspdlib</td></tr>
<tr><td><b>Hatemi-J</b></td><td>No cointegration against the alternative of cointegration with an two structural breaks.</td><td>Reject the null hypothesis if $ADF$, $Z_{\alpha}$, or $Z_t$ are less than the critical values.</td><td>tspdlib</td></tr>
<tr><td><b>Maki</b></td><td>No cointegration against the alternative of cointegration with an unknown number of breaks.</td><td>Reject the null hypothesis if $ADF$, $Z_{\alpha}$, or $Z_t$ are less than the critical value.</td><td>tspdlib</td></tr>
<tr><td><b>Shin test</b></td><td>Cointegration.</td><td>Reject the null hypothesis if the test statistic is less than the critical value.</td><td>tspdlib</td></tr>
</tbody>
</table>
<h2 id="how-to-test-for-cointegration-using-gauss">How to Test for Cointegration using GAUSS</h2>
<p>In this section, we will test for cointegration between monthly gold and silver prices, using historic monthly price date starting in 1915. Specifically, we will work through several stages of analysis:</p>
<ol>
<li>Graphing the data and checking deterministic behavior. </li>
<li>Testing each series for unit roots. </li>
<li>Testing for cointegration without structural breaks. </li>
<li>Testing for cointegration with structural breaks. </li>
</ol>
<h3 id="graphing-the-data">Graphing the Data</h3>
<p>As a first step, we will create a <a href="https://www.aptech.com/resources/tutorials/tsmt/wpi-visualizing-time-series-data/">time series graph</a> of our data. This allows us to visually examine the deterministic trends in our data.</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/01/gold_silver_prices_small.jpg"><img src="https://www.aptech.com/wp-content/uploads/2020/01/gold_silver_prices_small.jpg" alt="Shows comovements between gold and silver prices since 1915." width="800" height="600" class="aligncenter size-full wp-image-21494" /></a></p>
<p>From our graphs, we can draw some preliminary conclusions about the dynamics of gold and silver prices over our time period:</p>
<ul>
<li>There appears to be some foundation for the comovement of silver and gold prices.   </li>
<li>Neither gold nor silver prices appear to have a time trend. </li>
</ul>
<h3 id="testing-each-series-for-unit-roots">Testing Each Series for Unit Roots</h3>
<p>Before testing if silver and gold prices are cointegrated, we should test if the series have unit roots. We can do this using the unit roots tests available in the TSMT and TSPDLIB libraries.  </p>
<table>
<thead>
 <tr>
      <th colspan="3">
         Gold monthly closing prices (2015-2020)
      </th>
   </tr>
<tr><th>Time Series Unit Root Test</th><th>Test Statistic</th><th>Conclusion</th></tr>
</thead>
<tbody>
<tr><td><b>Augmented-Dickey Fuller</b></td><td>-1.151</td><td>Cannot reject the null hypothesis of unit root.</td></tr>
<tr><td><b>Phillips-Perron</b></td><td>-1.312</td><td>Cannot reject the null hypothesis of unit root.</td></tr>
<tr><td><b>KPSS</b></td><td>2.102</td><td>Reject the null hypothesis of stationarity at the 1% level.</td></tr>
<tr><td><b>Schmidt and Perron LM test</b></td><td>-2.399</td><td>Cannot reject the null hypothesis of unit root.</td></tr>
<tr><td><b>GLS-ADF</b></td><td>-0.980</td><td>Cannot reject the null hypothesis of unit root.</td></tr>
</tbody>
</table>
<table>
<thead>
 <tr>
      <th colspan="3">
         Silver monthly closing prices (2015-2020)
      </th>
   </tr>
<tr><th>Time Series Unit Root Test</th><th>Test Statistic</th><th>Conclusion</th></tr>
</thead>
<tbody>
<tr><td><b>Augmented-Dickey Fuller</b></td><td>-5.121</td><td>Reject the null hypothesis of unit root at the 1% level.</td></tr>
<tr><td><b>Phillips-Perron</b></td><td>-5.446</td><td>Reject the null hypothesis of unit root at the 1% level.</td></tr>
<tr><td><b>KPSS</b></td><td>0.856</td><td>Reject the null hypothesis of stationarity at the 1% level.</td></tr>
<tr><td><b>Schmidt and Perron LM test</b></td><td>-4.729 </td><td>Reject the null hypothesis of unit root at the 1% level.</td></tr>
<tr><td><b>GLS-ADF</b></td><td>-4.895</td><td>Reject the null hypothesis of unit root at the 1% level.</td></tr>
</tbody>
</table>
<p>These results provide evidence that gold prices are nonstationary but suggest that the silver prices are stationary.
At this point, we would not likely proceed with cointegration testing or we may wish to perform additional unit root testing. For example, we may want to perform <a href="https://www.aptech.com/blog/unit-root-tests-with-structural-breaks/">unit root tests that allow for structural breaks</a>. </p>
<p>The GAUSS code for the tests in this section is available <a href="https://github.com/aptech/gauss_blog/blob/master/time_series/cointegration-1.20.19/examples/2_unitroot_tsmt.e">here</a>.</p>
<h3 id="testing-for-cointegration">Testing for Cointegration</h3>
<p>Now, let's test for cointegration without structural breaks using two different tests, the Johansen tests and the Engle-Granger test.</p>
<p><b> The Johansen Tests</b><br />
We will use the <code>vmsjmt</code> procedure from the TSMT library. This procedure should be used with the <code>vmc_sjamt</code> and <code>vmc_sjtmt</code> procedures, which find the critical values for the Maximum Eigenvalue and Trace statistics, respectively. </p>
<p>The <code>vmsjmt</code> procedure requires four inputs:</p>
<hr>
<dl>
<dt>y</dt>
<dd>Matrix, contains the data to be tested for cointegration.</dd>
<dt>p</dt>
<dd>Scalar, the order of the time polynomial in the fitted regression. Set to $p=-1$ for no deterministic component, $p=0$ for a constant only, $p=1$ for a constant and trend.</dd>
<dt>k</dt>
<dd>Scalar, the number of lagged differences to use when computing the estimator.</dd>
<dt>no_det</dt>
<dd>Scalar, set $no\_det = 1$ to suppress the constant term from the fitted regression and include it in the cointegrating regression.
<hr></dd>
</dl>
<p>The <code>vmsjmt</code> procedure returns both the Johansen Trace and the Johansen Maximum Eigenvalue statistic. In addition, it returns the associated eigenvalues and eigenvectors. </p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;

// Load tsmt library
library tsmt;

// Set filename (with path) for loading
fname2 = __FILE_DIR $+ "commodity_mon.dat";

// Load real prices data
y_test_real = loadd(fname2, "P_gold_real + P_silver_real");

// No deterministic component 
// the fitted regression
p = -1;

// Set number of lagged differences
// for computing estimator
k = 2;

// No determinant
no_det = 0;

{ ev, evec, trace_stat, max_ev }  = vmsjmt(y_test_real, p, k, no_det);
cv_lr2 = vmc_sjamt(cols(y), p);
cv_lr1 = vmc_sjtmt(cols(y), p);</code></pre>
<p>Both <code>trace_stat</code> and <code>max_ev</code> will contain statistics for all possible ranks of $\Pi$. </p>
<p>For example, since we are testing for cointegration of just two time series, there will be at most one cointegrating vector. This means <code>trace_stat</code> and <code>max_ev</code> will be 2 x 1 matrices, testing both null hypotheses that $r=0$ and $r=1$. </p>
<table>
<thead>
<tr><th>Test</th><th>Test Statistic</th><th>10% Critical Value</th><th>Conclusion</th></tr>
</thead>
<tbody>
<tr><td><b>Johansen Trace Statistic</b></td><td>$$H_0: r=1, 56.707$$ $$H_0: r=0, 0.0767$$</td><td>10.46</td><td>Cannot reject the null hypothesis that $r=0$.</td></tr>
<tr><td><b>Johansen Maximum Eigenvalue</b></td><td>$$H_0: r=1, 56.631$$ $$H_0: r=0, 0.0766$$</td><td>9.39</td><td>Cannot reject the null hypothesis that $r=0$.</td></tr>
</tbody>
</table>
<p>These results indicate that there is no cointegration between monthly gold and silver prices. This should not be a surprise, given the results of our unit root testing. </p>
<div class="alert alert-info" role="alert">In the table above we report the results for all possible number of cointegrating vectors ($k=0$ and $k=1$). This is consistent with the results that are returned from <code>vmsjmt</code>. However, the Johansen tests are sequential tests and since we cannot reject the null that $k=0$ for either test, we technically do not need to continue testing for any higher rank. </div>
<p><b> The Engle-Granger</b><br />
Since there is only one possible cointegrating vector for this system, we could have also used the Engle-Granger test for cointegration. This test can be implemented using the <code>coint_egranger</code> procedure from the TSPDLIB library. </p>
<p>The <code>coint_egranger</code> procedure requires five inputs:</p>
<hr>
<dl>
<dt>y</dt>
<dd>Vector, independent variable in the testing regression. This is the variable the cointegrating variable is normalized to.</dd>
<dt>X</dt>
<dd>Matrix, dependent variable(s) in the testing regression. This should contain all other variables.</dd>
<dt>model</dt>
<dd>Scalar, specifies which deterministic components to include in the model. Set equal to 0 to include no deterministic components, 1 to include a constant, and 2 to include a constant and trend.</dd>
<dt>pmax</dt>
<dd>Scalar, the maximum number of lags to include in the cointegrating vector.</dd>
<dt>ic</dt>
<dd>Scalar, which information criteria to use to select the lags included in the ADF regression. Set equal to 1 for the AIC, 2 for the SIC.
<hr></dd>
</dl>
<p>The <code>coint_egranger</code> procedure returns the test statistic along with the 1%, 5% and 10% critical values.</p>
<p>Using the data already loaded in the previous example:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss"> /*
** Information Criterion:
** 1=Akaike;
** 2=Schwarz;
** 3=t-stat sign.
*/
ic = 2;

// Maximum number of lags
pmax = 12;

// No constant or trend
model = 0
{ tau0, cvADF0 } = coint_egranger(y_test_real[., 1], y_test_real[., 2], model, pmax, ic);

// Constant
model = 1
{ tau1, cvADF1 } = coint_egranger(y_test_real[., 1], y_test_real[., 2], model, pmax, ic);

// Constant and trend
model = 2
{ tau2, cvADF2 } = coint_egranger(y_test_real[., 1], y_test_real[., 2], model, pmax, ic);</code></pre>
<table>
<thead>
<tr><th>Test</th><th>Test Statistic</th><th>10% Critical Value</th><th>Conclusion</th></tr>
</thead>
<tbody>
<tr><td><b>Engle-Granger, no constant</b></td><td>-3.094</td><td>-2.450</td><td>Reject the null of no cointegration at the 10% level.</td></tr>
<tr><td><b>Engle-Granger, constant</b></td><td>-1.609</td><td>-3.066 </td><td>Cannot reject the null hypothesis of no cointegration.</td></tr>
<tr><td><b>Engle-Granger, constant and trend</b></td><td>-2.327</td><td>-3.518</td><td>Cannot reject the null hypothesis of no cointegration.</td></tr>
</tbody>
</table>
<p>These results provide evidence for our conclusion that there is no cointegration between gold and silver prices. Note, however, that these results are not conclusive and depend on whether we include a constant. This sheds light on the importance of including the correct deterministic components in our model. </p>
<h3 id="testing-for-cointegration-with-structural-breaks">Testing for Cointegration with Structural Breaks</h3>
<p>To be thorough we should also test for cointegration using tests that allow for a structural break. As an example, let's use the Gregory-Hansen test to compare the null hypothesis of no cointegration against the alternative that there is cointegration with one structural break.</p>
<p>This test can be implemented using the <code>coint_ghansen</code> procedure from the TSPDLIB. </p>
<p>The <code>coint_ghansen</code> procedure requires eight inputs:</p>
<hr>
<dl>
<dt>y</dt>
<dd>Vector, dependent variable in the testing regression. This is the variable the cointegrating variable is normalized to.</dd>
<dt>X</dt>
<dd>Matrix, independent variable(s) in the testing regression. This should contain all other variables.</dd>
<dt>model</dt>
<dd>Scalar, specified what type of regime shifts to include. Set equal to 1 for a level shift (C model), 2 for level shift with trend (C/T model), 3 for regime shift (C/S model), and 4 for regime and trend shifts.</dd>
<dt>bwl</dt>
<dd>Scalar, Bandwidth for kernel estimator for Phillips-Perron type test.</dd>
<dt>pmax</dt>
<dd>Scalar, the maximum number of lags to include in the cointegrating vector.</dd>
<dt>ic</dt>
<dd>Scalar, which information criteria to use to select the lags included in the ADF regression. Set equal to 1 for the AIC, 2 for the SIC.</dd>
<dt>varm</dt>
<dd>Scalar, long-run consistent variance type to use for the Phillips-Perron type test:
                 1 = iid,
                 2 = Bartlett,
                 3 = Quadratic Spectral (QS),
                 4 = SPC with Bartlett /see (Sul, Phillips &amp; Choi, 2005),
                 5 = SPC with QS,
                 6 = Kurozumi with Bartlett,
                 7 = Kurozumi with QS.</dd>
<dt>trimm</dt>
<dd>Scalar, amount to trim from consideration as break date.
<hr></dd>
</dl>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** Information Criterion:
** 1=Akaike;
** 2=Schwarz;
** 3=t-stat sign.
*/
ic = 2;

//Maximum number of lags
pmax = 12;

// Trimming rate
trimm= 0.15;

// Long-run consistent variance estimation method
varm = 3;

// Bandwidth for kernel estimator
T = rows(y_test_real);
bwl = round(4 * (T/100)^(2/9));

// Level shift
model = 1;
{ ADF_min1, TBadf1, Zt_min1, TBzt1, Za_min1, TBza1, cvADFZt1, cvZa1 }=
    coint_ghansen(y_test_real[., 1], y_test_real[., 2], model, bwl, ic, pmax, varm, trimm);

// Level shift with trend
model = 2;
{ ADF_min2, TBadf2, Zt_min2, TBzt2, Za_min2, TBza2, cvADFZt2, cvZa2 }=
    coint_ghansen(y_test_real[., 1], y_test_real[., 2], model, bwl, ic, pmax, varm, trimm);

// Regime shift
model = 3;
{ ADF_min3, TBadf3, Zt_min3, TBzt3, Za_min3, TBza3, cvADFZt3, cvZa3 }=
    coint_ghansen(y_test_real[., 1], y_test_real[., 2], model, bwl, ic, pmax, varm, trimm);

// Regime shift with trend
model = 4;
{ ADF_min4, TBadf4, Zt_min4, TBzt4, Za_min4, TBza4, cvADFZt4, cvZa4 }=
    coint_ghansen(y_test_real[., 1], y_test_real[., 2], model, bwl, ic, pmax, varm, trimm);</code></pre>
<p>The <code>coint_ghansen</code> has eight returns:</p>
<hr>
<dl>
<dt>ADFmin</dt>
<dd>Scalar, the minimum $ADF$ test statistic across all breakpoints.</dd>
<dt>TBadf</dt>
<dd>Scalar, the breakpoint associated with the minimum $ADF$ statistic.</dd>
<dt>Ztmin</dt>
<dd>Scalar, the minimum $Z_t$ test statistic across all breakpoints.</dd>
<dt>TBzt</dt>
<dd>Scalar, the breakpoint associated with the minimum $Z_t$ statistic.</dd>
<dt>Zamin</dt>
<dd>Scalar, the minimum $Z_{\alpha}$ test statistic across all breakpoints.</dd>
<dt>TBza</dt>
<dd>Scalar, the breakpoint associated with the minimum $Z_{\alpha}$ statistic.</dd>
<dt>cvADFZt</dt>
<dd>Vector, the 1%, 5%, and 10% critical values for the $ADF$ and $Z_t$ statistics.</dd>
<dt>cvZa</dt>
<dd>Vector, the 1%, 5%, and 10% critical values for the $Z_{\alpha}$ statistic.
<hr></dd>
</dl>
<table>
<thead>
<tr><th>Test</th><th>$ADF$ Test Statistic</th><th>$Z_t$ Test Statistic</th><th>$Z_{\alpha}$ Test Statistic</th><th>10% Critical Value $ADF$,$Z_t$</th><th>10% Critical Value $Z_{\alpha}$</th><th>Conclusion</th></tr>
</thead>
<tbody>
<tr><td><b>Gregory-Hansen, Level shift</b></td><td>-3.887</td><td>-4.331</td><td>-39.902</td><td>-4.34</td><td>-36.19</td><td>Cannot reject the null of no cointegration for $ADF$ and $Z_t$. Reject the null of no cointegration at the 10% level for $Z_{\alpha}$.</td></tr>
<tr><td><b>Gregory-Hansen, Level shift with trend</b></td><td>-3.915</td><td>-5.010</td><td>-50.398</td><td>-4.72</td><td>-43.22</td><td>Reject the null of no cointegration at the 10% level for $Z_{\alpha}$ and $Z_t$. Cannot reject the null for $ADF$ test.</td></tr>
<tr><td><b>Gregory-Hansen, Regime change</b></td><td>-5.452</td><td>-6.4276</td><td>-80.379</td><td>-4.68</td><td>-41.85</td><td>Reject the null of no cointegration at the 10% level.</td></tr>
<tr><td><b>Gregory-Hansen, Regime change with trend</b></td><td>-6.145</td><td>-7.578</td><td>-106.549</td><td>-5.24</td><td>-53.31</td><td>Reject the null of no cointegration at the 10% level.</td></tr>
</tbody>
</table>
<p>Note that our test for cointegration with one structural break is inconsistent and depends on which type of structural breaks we include in our model. This provides some indication that further exploration of structural breaks is needed. </p>
<p>Some examples of additional steps that we could take:</p>
<ol>
<li>Perform more complete structural breaks testing to inform if structural breaks are valid, how many structural breaks should be included, and which structural break model is most appropriate. </li>
<li>Perform cointegration tests that are most consistent with the structural breaks analysis. </li>
</ol>
<h2 id="conclusion">Conclusion</h2>
<p>Congratulations! You now have an established guide for cointegration and the background you need to perform cointegration testing. </p>
<p>In particular, today's blog covered:</p>
<ul>
<li>The fundamentals of cointegration.</li>
<li>The error correction model.</li>
<li>How to prepare for cointegration testing. </li>
<li>What cointegration tests to use with and without structural breaks. </li>
<li>How to interpret cointegration tests. </li>
<li>How to perform cointegration tests in GAUSS.</li>
</ul>
<p>    <!-- MathJax configuration -->
    <style>
        .mjx-svg-href {
            fill: "inherit" !important;
            stroke: "inherit" !important;
        }
    </style>
    <script type="text/x-mathjax-config">
        MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "AMS"} } });
    </script>
    <script type="text/javascript">
window.MathJax = {
  tex2jax: {
    inlineMath: [ ['$','$'] ],
    displayMath: [ ['$$','$$'] ],
    processEscapes: true,
    processEnvironments: true
  },
  // Center justify equations in code and markdown cells. Elsewhere
  // we use CSS to left justify single line equations in code cells.
  displayAlign: 'center',
  "HTML-CSS": {
    styles: {'.MathJax_Display': {"margin": 0}},
    linebreaks: { automatic: false }
  },
  "SVG": {
    styles: {'.MathJax_SVG_Display': {"margin": 0}},
    linebreaks: { automatic: false }
  },
  showProcessingMessages: false,
  messageStyle: "none",
  menuSettings: { zoom: "Click" },
  AuthorInit: function() {
    MathJax.Hub.Register.StartupHook("End", function() {
            var timeout = false, // holder for timeout id
            delay = 250; // delay after event is "complete" to run callback
            var shrinkMath = function() {
              //var dispFormulas = document.getElementsByClassName("formula");
              var dispFormulas = document.getElementsByClassName("MathJax_SVG_Display");
              if (dispFormulas){
                // caculate relative size of indentation
                var contentTest = document.getElementsByTagName("body")[0];
                var nodesWidth = contentTest.offsetWidth;
                // if you have indentation
                var mathIndent = MathJax.Hub.config.displayIndent; //assuming px's
                var mathIndentValue = mathIndent.substring(0,mathIndent.length - 2);
                for (var i=0; i<dispFormulas.length; i++){
                  var dispFormula = dispFormulas[i];
                  var wrapper = dispFormula;
                  //var wrapper = dispFormula.getElementsByClassName("MathJax_Preview")[0].nextSibling;
                  var child = wrapper.firstChild;
                  wrapper.style.transformOrigin = "center"; //or top-left if you left-align your equations
                  var oldScale = child.style.transform;
                  //var newValue = Math.min(0.80*dispFormula.offsetWidth / child.offsetWidth,1.0).toFixed(2);
                  var newValue = Math.min(dispFormula.offsetWidth / child.offsetWidth,1.0).toFixed(2);
                  var newScale = "scale(" + newValue + ")";
                  if(newValue != "NaN" && !(newScale === oldScale)){
                    wrapper.style.transform = newScale;
                    wrapper.style["margin-left"]= Math.pow(newValue,4)*mathIndentValue + "px";
                    var wrapperStyle = window.getComputedStyle(wrapper);
                    var wrapperHeight = parseFloat(wrapperStyle.height);
                    wrapper.style.height = "" + (wrapperHeight * newValue) + "px";
                    if(newValue === "1.00"){
                      wrapper.style.cursor = "";
                      wrapper.style.height = "";
                    }
                    else {
                      wrapper.style.cursor = "zoom-in";
                    }
                  }

                }
            }
            };
            shrinkMath();
            window.addEventListener('resize', function() {
              clearTimeout(timeout);
              timeout = setTimeout(shrinkMath, delay);
            });
          });
  }
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS_SVG"></script>
</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/a-guide-to-conducting-cointegration-tests/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>A Simple Test for Structural Breaks in Variance</title>
		<link>https://www.aptech.com/blog/a-simple-test-for-structural-breaks-in-variance/</link>
					<comments>https://www.aptech.com/blog/a-simple-test-for-structural-breaks-in-variance/#respond</comments>
		
		<dc:creator><![CDATA[Eric]]></dc:creator>
		<pubDate>Fri, 30 Nov 2018 21:02:11 +0000</pubDate>
				<category><![CDATA[Econometrics]]></category>
		<category><![CDATA[Time Series]]></category>
		<category><![CDATA[ICSS]]></category>
		<category><![CDATA[structural breaks]]></category>
		<category><![CDATA[time series]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=17073</guid>

					<description><![CDATA[Though many standard econometric models assume that variance is constant, structural breaks in variance are well-documented, particularly in economic and finance data. If these changes are not accurately accounted for, they can hinder forecast inference measures, such as forecast variances and intervals. In this blog, we consider a tool that can be used to help locate structural breaks in variance -- the iterative cumulative sum of squares algorithm(ICSS) (Inclan and Tiao, 1994).]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Though many standard econometric models assume that variance is constant, <a href="https://www.aptech.com/structural-breaks/">structural breaks</a> in variance are well-documented, particularly in economic and finance data. If these changes are not accurately accounted for, they can hinder forecast inference measures, such as forecast variances and intervals.</p>
<p>In this blog, we consider a tool that can be used to help locate <a href="https://www.aptech.com/structural-breaks/">structural breaks</a> in variance -- the <a href="https://www.jstor.org/stable/2290916?seq=1#page_scan_tab_contents">iterative cumulative sum of squares algorithm</a> (ICSS) (Inclan and Tiao, 1994).</p>
<h2 id="centered-cumulative-sum-of-squares">Centered Cumulative Sum of Squares</h2>
<p>The first step of the algorithm is to find the cumulative sum of squares test statistic. This statistic can be found in four easy steps:
    <!-- MathJax configuration -->
    <style>
        .mjx-svg-href {
            fill: "inherit" !important;
            stroke: "inherit" !important;
        }
    </style>
    <script type="text/x-mathjax-config">
        MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "AMS"} } });
    </script>
    <script type="text/javascript">
window.MathJax = {
  tex2jax: {
    inlineMath: [ ['$','$'] ],
    displayMath: [ ['$$','$$'] ],
    processEscapes: true,
    processEnvironments: true
  },
  // Center justify equations in code and markdown cells. Elsewhere
  // we use CSS to left justify single line equations in code cells.
  displayAlign: 'center',
  "HTML-CSS": {
    styles: {'.MathJax_Display': {"margin": 0}},
    linebreaks: { automatic: false }
  },
  "SVG": {
    styles: {'.MathJax_SVG_Display': {"margin": 0}},
    linebreaks: { automatic: false }
  },
  showProcessingMessages: false,
  messageStyle: "none",
  menuSettings: { zoom: "Click" },
  AuthorInit: function() {
    MathJax.Hub.Register.StartupHook("End", function() {
            var timeout = false, // holder for timeout id
            delay = 250; // delay after event is "complete" to run callback
            var shrinkMath = function() {
              //var dispFormulas = document.getElementsByClassName("formula");
              var dispFormulas = document.getElementsByClassName("MathJax_SVG_Display");
              if (dispFormulas){
                // caculate relative size of indentation
                var contentTest = document.getElementsByTagName("body")[0];
                var nodesWidth = contentTest.offsetWidth;
                // if you have indentation
                var mathIndent = MathJax.Hub.config.displayIndent; //assuming px's
                var mathIndentValue = mathIndent.substring(0,mathIndent.length - 2);
                for (var i=0; i<dispFormulas.length; i++){
                  var dispFormula = dispFormulas[i];
                  var wrapper = dispFormula;
                  //var wrapper = dispFormula.getElementsByClassName("MathJax_Preview")[0].nextSibling;
                  var child = wrapper.firstChild;
                  wrapper.style.transformOrigin = "center"; //or top-left if you left-align your equations
                  var oldScale = child.style.transform;
                  //var newValue = Math.min(0.80*dispFormula.offsetWidth / child.offsetWidth,1.0).toFixed(2);
                  var newValue = Math.min(dispFormula.offsetWidth / child.offsetWidth,1.0).toFixed(2);
                  var newScale = "scale(" + newValue + ")";
                  if(newValue != "NaN" && !(newScale === oldScale)){
                    wrapper.style.transform = newScale;
                    wrapper.style["margin-left"]= Math.pow(newValue,4)*mathIndentValue + "px";
                    var wrapperStyle = window.getComputedStyle(wrapper);
                    var wrapperHeight = parseFloat(wrapperStyle.height);
                    wrapper.style.height = "" + (wrapperHeight * newValue) + "px";
                    if(newValue === "1.00"){
                      wrapper.style.cursor = "";
                      wrapper.style.height = "";
                    }
                    else {
                      wrapper.style.cursor = "zoom-in";
                    }
                  }

                }
            }
            };
            shrinkMath();
            window.addEventListener('resize', function() {
              clearTimeout(timeout);
              timeout = setTimeout(shrinkMath, delay);
            });
          });
  }
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS_SVG"></script></p>
<ol>
<li>Using the model error terms find the cumulative sum of squares (CSS) for all potential breakpoints observations 1 through <em>k</em> :
$$C_1 = \sum_{t=1}^1 a_t^2 \\ C_2 = \sum_{t=1}^2 a_t^2 \\ \vdots \\ C_k = \sum_{t=1}^k a_t^2 \\ C_T = \sum_{t=1}^T a_t^2$$
 
$$ a = \begin{bmatrix} 0.1 \\ 0.3 \\ 0.5 \\ 0.7 \\ 0.2 \end{bmatrix} \rightarrow C_{k=1,2,..T} = \begin{bmatrix} 0.01 \\ 0.1 \\ 0.35 \\ 0.84 \\ 0.88 \end{bmatrix} $$
 </li>
<li>Normalize and center the cumulative sum of squares, using the partial series CSS , $C_k$, and the full series CSS, $C_T$ :
$$D_k = \frac{C_k}{C_T} - \frac{k}{T}\\$$
 
$$D_{k=1,2,..T} = \begin{bmatrix} 0.01/0.88 \\ 0.1/0.88 \\ 0.35/0.88 \\ 0.84/0.88 \\ 0.88/0.88 \end{bmatrix} - \begin{bmatrix} 1/5 \\ 2/5 \\ 3/5 \\ 4/5 \\ 5/5 \end{bmatrix} = \begin{bmatrix} -0.189\\ -0.286 \\ -0.202\\ 0.155 \\ 0.000 \end{bmatrix} $$
 </li>
<li>Find the maximum centered cumulative sum of squares. The potential breakpoint, k*, is the location in the series of the maximum absolute value of the centered cumulative sum of squares, $D_{k^{*}}$ :
$$D_{k^{*}} = \max\limits_{k} | D_k |\\$$
 
$$ \begin{bmatrix} abs(-0.189)\\ abs(-0.286) \\ abs(-0.202)\\ abs(0.155)\\ abs(0.000) \end{bmatrix} \rightarrow D_{k^{*}} = 0.286, k^{*} = 2 $$
 </li>
<li>Finally, if $IT = \sqrt{T/2}D_{k^{*}}$ exceeds the critical value of the limiting distribution, then $k^*$ represents a statistically significant breakpoint.</li>
</ol>
<h2 id="iterative-cumulative-sum-of-squares-algorithm">Iterative Cumulative Sum of Squares Algorithm</h2>
<p>Finding $k^*$ would be sufficient if we were certain that there was only one break point in the variance. However, how can we definitively know that this is the case?</p>
<p>Because we cannot eliminate the possibility that there are multiple breaks in the variance, we must iteratively search for all potential additional breakpoints.</p>
<p>The ICSS algorithm searches for breakpoints in each of the sections created by newly found breakpoints. Once new breakpoints are no longer found, the search stops.</p>
<p>Considering our hypothetical example, our first potential break was located at $k^{*} = 2$, therefore, our iterative search for breakpoints would begin again in the section of data bounded by $t = 3$ and $t = 5$.</p>
<h2 id="using-the-icss-algorithm-in-gauss">Using the ICSS algorithm in GAUSS</h2>
<p>The ICSS test is available in the GAUSS <a href="https://github.com/aptech/gauss-carrion-library" target="_blank" rel="noopener">carrionlib</a> package. This package is a free package that should be installed using the <a href="https://www.aptech.com/blog/gauss-package-manager-basics/" target="_blank" rel="noopener">GAUSS Package Manager</a>.</p>
<div class="alert alert-info" role="alert">For more information about using GAUSS library, please see our blog, <a href="https://www.aptech.com/blog/using-gauss-packages-complete-guide/" target="_blank" rel="noopener">&quot;Using GAUSS Packages [Complete Guide]&quot;</a>.</div>
<h3 id="the-icss-procedure">The icss Procedure</h3>
<p>The carrionlib package includes the <code>icss</code> procedure for implementing the ICSS test. Because the <code>icss</code> function also provides options to perform the modifications discussed in the paper, the <code>icss</code> function requires the following three inputs:</p>
<hr />
<dl>
<dt>e</dt>
<dd>Vector, the stochastic series to be tested.</dd>
<dt>test</dt>
<dd>Scalar, an indicator of which test to run, should always be set to zero to run the standard ICSS test.</dd>
<dt>cri</dt>
<dd>Vector, 3x1, sets the bandwidth for the modification models. This is irrelevant to the standard ICSS and can be set to any 3x1 vector.</dd>
</dl>
<hr />
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">{ cp, nbre } = icss(e, test, cri);</code></pre>
<h2 id="empirical-example">Empirical Example</h2>
<p>Let's use quick empirical example to get a better understanding of how to use the <code>icss</code> procedure. </p>
<p><a href="https://www.aptech.com/wp-content/uploads/2018/11/gblog-sp500-icss-test.png"><img class="aligncenter size-full wp-image-18561" src="https://www.aptech.com/wp-content/uploads/2018/11/gblog-sp500-icss-test.png" alt="ICSS structural break test." width="800" height="400" /></a></p>
<p>Today, we'll use the S&amp;P 500 data provided by <a href="http://www.aefin.es/articulos/pdf/A4-2_443809.pdf">Sanso, Arago, and Carrion-i-Silvestre, 2004</a> to demonstrate how to use the <code>icss</code> procedure.</p>
<p>The first step is to load the library and load our data using the <a href="https://docs.aptech.com/gauss/loadd.html" target="_blank" rel="noopener"><code>loadd</code></a> procedure: </p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Load library
new;
library carrionlib;

// Load S&amp;P data
x = loadd("sp.dat");</code></pre>
<p>Next, to prepare our data for testing, we'll demean our data:</p>
<pre class="hljs-container hljs-container-solo"><code>// Demean data
e = x - meanc(x);</code></pre>
<p>Finally we are ready to run our test:</p>
<pre class="hljs-container hljs-container-solo"><code>// Set our test to run ICSS
test = 0;

// Set cri vector to be any
// 3x1 vector
cri = 0|0|0;

// Run
{ cp, nbre } = icss(e, test, cri);</code></pre>
<p>The function returns two outputs:</p>
<ol>
<li>A vector containing the change points (<em>cp</em>).</li>
<li>A scalar containing the number of break points (<em>nbre</em>).</li>
</ol>
<h2 id="conclusion">Conclusion</h2>
<p>Identifying structural breaks in the variance of data is an important step in modeling time series data. In this tutorial we've covered:</p>
<ul>
<li>What the ICSS algorithm is.</li>
<li>How to use the ICSS algorithm in GAUSS.</li>
</ul>
<p>Code and data from this blog can be found <a href="https://github.com/aptech/gauss_blog/tree/master/time_series/icss-11.30.2018">here</a>.</p>
<h2 id="references">References</h2>
<p>Inclan, C., &amp; Tiao, G. C. (1994). Use of cumulative sums of squares for retrospective detection of changes of variance. <em>Journal of the American Statistical Association, 89</em>(427), 913-923.</p>
<p>Sansó, A., Aragó, V., &amp; Carrion, J. L. (2004). Testing for changes in the unconditional variance of financial time series. <em>Revista de Economía financiera, 4</em>(1), 32-53.</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/a-simple-test-for-structural-breaks-in-variance/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
