Testing predictability and random walks
- Use of autocorrelation
- Unit root hypothesis test: ADF and KPSS
- Sequence and reversal test
- Getting market data in Python using the package Alpha-Vantage
Hello!
Last post, I briefly discussed some differences between data and market driven models. One of the assumptions commonly employed in market driven models regards the random nature of future movements of market variables, such as asset prices and interest rates. Under this assumption a stochastic equation provides guidelines for a random walk that represents the movement of the variables. This stochastic equation is previously parameterized with the current conditions of the market data. For financial derivatives, for instance, the models intend to calculate prices that take into account these randomness and provide fair prices for both sellers and buyers (preventing arbitrage opportunities), as well as adequate hedges. But how do we test such assumptions? Moreover, what are the consequences of the corresponding results? In this post, we will briefly walk through both questions.
This post is organized as follows. First, I will illustrate some applications of autocorrelation for both idealized and real market data obtained by means of the package Alpha-Vantage (in Python). In the following, I will discuss some hypothesis tests, named unit root tests and sequences and reversals test. One of the main references for this post is the book The Econometrics of Financial Markets (Authors: Campbell, Lo, and Craig MacKinlay).
This post is organized as follows. First, I will illustrate some applications of autocorrelation for both idealized and real market data obtained by means of the package Alpha-Vantage (in Python). In the following, I will discuss some hypothesis tests, named unit root tests and sequences and reversals test. One of the main references for this post is the book The Econometrics of Financial Markets (Authors: Campbell, Lo, and Craig MacKinlay).
Autocorrelation
In principle, empirical tests that take randomness into account may be used to guide the choose of the stochastic process that should be used to model the financial variable. Another obvious goal is the search for strategies that take advantage of determined tendency observed during the tests. Let us consider a simple (but unrealistic) example using an Ornstein-Uhlenbeck process, which is the mean reverting process upon which the well-known Vasicek model relies (a discussion is presented in this post):
$dX = \alpha \left( X_0 - X \right) dt + \sigma dW$
where $\alpha$ is the mean reverting speed, $X_0$ is the long-term average, $\sigma$ is the volatility, and $W$ is a Brownian motion under a probability measure $P$. The code below builds a random path based on this process:Above, in order to insert some artificial "reality" in the model, I am considering uniform distributions for $\sigma$ and $\alpha$, whereas $X_0$ remains constant. This kind of process presents mean reversion, which means that random process tends to the average $X_0$ (more on this here). Intuitively, one could guess that this kind of process might present some degree of autocorrelation, which is in fact what is observed running the code below:
resulting in:
Although the magnitude of the autocorrelation is low, some structure does appear. This magnitude can be tuned by adjusting parameters and a mathematical discussion of the presence of this structure can be seen in the Andersen´s and Piterbarg´s book (volume 2, chapter 10). This example is quite appealing and very rarely a situation like this would be so clear in the real world. In fact, quant strategists are frequently searching for assets (or spreads, or portfolios) that could present a tendency to behave as illustrated above. Let´s talk more about it but...
Autocorrelation: this time for real
In order to get some intuition from the real world, we can use real market data and assess the results of autocorrelation. I will use data of stock prices of Apple and Brooks Automation, Inc, that is, a very liquid stock and a small cap. Market data are taken by means the package Alpha-Vantage.In principle, Apple is a very liquid asset. The quotation illustrated below is extracted for each minute of some trading days. Notice that any graphical inference extracted from the figure below is highly dependent on the time scale that one is focusing. While a line could be drawn indicating a upward tendency, one also sees a sharp decrease in the last quotations. In some sense a purely graphical inference of this asset price is worth the same as a questionable qualitative analysis.
Evaluating results of autocorrelation of this data set results in
The clear structure previously observed for autocorrelation from our artificial process simply does not appear in this case. This illustrates the challenge for quants to identify strategies for investment. Maybe some structure might appear if one applies some noise reduction treatment, I haven´t tried but this could be proved to be an interesting exercise. The intuition behind the difficulty in finding any structure is directly related to the fact that an efficient market almost immediately take advantage of any more visible tendency that could be observed.
Consider the results for Brooks Automation, Inc:
Hmmm this behavior looks more interesting. Don´t you agree that somehow it resembles the behavior of the path generated by the Ornstein-Uhlenbeck process? Maybe, only after a statistical evaluation one can say something. The results for autocorrelation are given below:
In fact, once again no clear structure appears, but this is far from being the end of the history. In the following let´s talk about unit root tests.
Unit root tests
One of the tests that can give indication of the presence of a tendency in the historical data is the Augmented Dick-Fuller test (already discussed here). Let´s briefly discuss this test by looking at some code and corresponding results:Applying this test to the Ornstein-Uhlenbeck process results in:
ADF Statistic: -5.004915 p-value: 0.000022 Critical Values: 1%: -3.435 5%: -2.863 10%: -2.568
Results above should be (fair informally) interpreted as folllows. Since ADF statistics is lower than the critical values with a very low p-value, the result is indicating that one should disregard the possibility of the presence of a unit root, which could be interpreted as the presence of a stationarity in the employed data. Notice however that when one interprets the result above as an indication of a tendency, it is immediately assumed that the future periods of the process are somehow connected with the historical behavior. This assumption is totally ad hoc since it is not included at all in the ADF test.
For Apple stock prices presented above, ADF test results in:
Results above show a completely opposite behavior with respect to the results of the mean reverting process. Put in other words, one should not neglect the presence of a unit root, so stationarity is not statistically significant in Apple stock price according to ADF test, other tests could and should be applied (such as KPSS, discussed here). This might be an astonishing result for those that uniquely follow the graphical analysis considering a upstream line drawn in the whole period.For Apple stock prices presented above, ADF test results in:
ADF Statistic: -1.443899 p-value: 0.561059 Critical Values: 1%: -3.434 5%: -2.863 10%: -2.568
For Brooks Automation, Inc stocks, ADF test provides the following results:
ADF Statistic: -1.895038 p-value: 0.334399 Critical Values: 1%: -3.435 5%: -2.864 10%: -2.568
For BRKS, a tendency is also not statistically significant (again, according to ADF test) although the say severity of this denial is weaker than the one observed for Apples´ data. In order to confirm the rejection of the stationary trend for BRKS, I applied a KPSS test resulting in
KPSS Statistic: 0.890803 p-value: 0.010000 lags: 24.000000 Critical Values: 10%: 0.347 5%: 0.463 2.5%: 0.574 1%: 0.739
Notice that although a stationarity is rejected for the BRKS asset, the KPSS statistic is not so far from the point of being considered a mean reversion process. One might pay attention for the future movements of this asset, something interesting may arise...
Sequences and reversions
Another interesting randomness test considers the ups and downs in the supposed random variable. It begins by computing the number of these ups and down:
$Y_i=1$ if $p_{i-1}<p_i$
$Y_i=0$ if $p_{i-1}\geq p_i$
where $i=1, 2, 3, ..., n$. Denote as $N_s$ the number of sequences $Y_i=1$ and $N_r=n-N_s$ as the number of reversals $Y_i=0$. In a driftless process, sequences and reversals are equally distributed and so the Cowles-Jones ratio $CJ=N_s/N_r$ should be one.
In the presence of drift, the balance between ups and downs disappears and one side of the movement has a higher probability and the general specification of the CJ ratio becomes:
$CJ=\frac{\pi^2+(1-\pi)^2}{2\pi(1-\pi)}$
where $\pi$ is the upward probability. In this case, the test is highly model dependent, since the probability is calculated using some probability density function assumed for the process. A simple possibility explored in this book is the use of a Normal distribution, which is a quite appealing assumption. This distribution depends on only the average and variance. Consider an example of an asset with a historical return of $\mu=5 \%$ and a volatility of $\sigma=25 \%$. Using the normal distribution assumption, the up probability will be calculated as
$\pi=\Theta \left(\frac{\mu}{\sigma} \right)=\Theta \left(\frac{0.05}{0.25} \right)=0.58$
Using the formula for the Cowles-Jones ratio given above we find:
$CJ=\frac{0.58^2+(1-0.58)^2}{2*0.58(1-0.58)} \approx 1.05$
In order to check if empirical values of CJ are statistically significantly comparable to the table value we can use the approximate variance given below:
I hope you enjoyed the post! Leave your comments and share!
$var\left(\frac{N_s}{N_r} \right) \approx \frac{\pi(1-\pi)+2(\pi^3+(1-\pi)^3-\pi^2)}{n(1-\pi)^4}$
I hope you enjoyed the post! Leave your comments and share!
May the Force be with you.
#=================================
Diogo de Moura Pedroso
LinkedIn: www.linkedin.com/in/diogomourapedroso
Comments
Post a Comment