{"id":2331,"date":"2019-07-05T06:30:11","date_gmt":"2019-07-05T06:30:11","guid":{"rendered":"https:\/\/www.aiproblog.com\/index.php\/2019\/07\/05\/how-the-mathematics-of-fractals-can-help-predict-stock-markets-shifts\/"},"modified":"2019-07-05T06:30:11","modified_gmt":"2019-07-05T06:30:11","slug":"how-the-mathematics-of-fractals-can-help-predict-stock-markets-shifts","status":"publish","type":"post","link":"https:\/\/www.aiproblog.com\/index.php\/2019\/07\/05\/how-the-mathematics-of-fractals-can-help-predict-stock-markets-shifts\/","title":{"rendered":"How the Mathematics of Fractals Can Help Predict Stock Markets\u00a0Shifts"},"content":{"rendered":"<p>Author: Marco Tavora<\/p>\n<div>\n<div class=\"section-divider\">\n<p class=\"graf graf--p\">In financial markets, two of the most common trading strategies used by investors are the <a href=\"https:\/\/www.investopedia.com\/terms\/m\/momentum_investing.asp\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">momentum<\/a> and <a href=\"https:\/\/www.investopedia.com\/terms\/m\/meanreversion.asp\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">mean reversion<\/a> strategies. If a stock exhibits momentum (or trending behavior as shown in the figure below), its price on the current period is more likely to increase (decrease) if it has already increased (decreased) on the previous period.<\/p>\n<p class=\"graf graf--p\">\n<p class=\"graf graf--p\">Below, a section of the time series of the S&#038;P 500 Index or <a href=\"https:\/\/www.nasdaq.com\/symbol\/spy\" class=\"markup--anchor markup--figure-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">SPY<\/a>\u00a0is shown. This is an example of trending behavior.<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*VdUnfXY1nl6qELkbIUmeFQ@2x.png\"><\/p>\n<p class=\"graf graf--p\">When the return of a stock at time <em class=\"markup--em markup--p-em\">t<\/em> depends in some way on the return at the previous time <em class=\"markup--em markup--p-em\">t<\/em>&#8211;<em class=\"markup--em markup--p-em\">1,<\/em> the returns are said to be autocorrelated. In the momentum regime, returns are <em class=\"markup--em markup--p-em\">positively<\/em> correlated.<\/p>\n<p class=\"graf graf--p\">In contrast, the price of a mean-reverting stock fluctuates randomly around its historical mean and displays a tendency to revert to it. When there is mean reversion, if the price increased (decreased) in the current period, it is more likely to decrease (increase) in the next one.<\/p>\n<p class=\"graf graf--p\">\n<p class=\"graf graf--p\">A section of the time series of log returns of the <a href=\"https:\/\/finance.yahoo.com\/quote\/AAPL?p=AAPL\" class=\"markup--anchor markup--figure-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Apple<\/a> stock (adjusted closing price), shown below, is an example of mean-reverting behavior.<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*cTXqAW-Q-o-WTMjaV-J2Pg@2x.png\"><\/p>\n<p><\/p>\n<p class=\"graf graf--p\">Note that, since the two regimes occur in different time frames (trending behavior usually occurs in larger timescales), they can, and often do, coexist.<\/p>\n<p class=\"graf graf--p\">In both regimes, the current price contains useful information about the future price. In fact, trading strategies <strong class=\"markup--strong markup--p-strong\">can only generate profit<\/strong> <strong class=\"markup--strong markup--p-strong\">if asset prices are either trending or mean-reverting<\/strong> since, otherwise, prices are following what is known as a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Random_walk\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">random walk<\/a> (see the animation below).<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*eksZSXMCKrOP04TYOIXRpQ.gif\"><\/p>\n<p><\/p>\n<h3 class=\"graf graf--h3\">Mean-Reverting Time\u00a0Series<\/h3>\n<p class=\"graf graf--p\">Stock prices <a href=\"https:\/\/www.amazon.com\/Algorithmic-Trading-Winning-Strategies-Rationale\/dp\/1118460146\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">rarely display<\/a> mean-reverting behavior. In the vast majority of cases, they follow random walks (their corresponding returns, however, are mean-reverting and fluctuate randomly around zero). Mean-reverting price series can, however, be synthesized by combining different stocks to build a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Cointegration\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">cointegrated<\/a> portfolio (see <a href=\"https:\/\/www.oreilly.com\/library\/view\/quantitative-trading\/9780470284889\/ch07.html\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">this reference<\/a> for more details) which displays the property of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Stationary_process\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">stationarity<\/a> (a lot more about this below). Though stationarity can be identified using a variety of well-known <a href=\"https:\/\/en.m.wikipedia.org\/wiki\/Augmented_Dickey%E2%80%93Fuller_test\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">standard statistical tests<\/a>, in this article, I will focus on one powerful type of analysis based on the so-called <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hurst_exponent\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Hurst exponent<\/a>, which is related to the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Fractal_dimension\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">fractal exponent<\/a> of the price time series. The Hurst exponent provides a way to measure the amount by which a financial time series deviates from a random walk. It is a surprisingly simple tool that can help investors determine which strategy to apply.<\/p>\n<h4 class=\"graf graf--h4\">Stationarity<\/h4>\n<p class=\"graf graf--p\">In this article, for practical purposes, I will informally use the terms mean-reverting and stationary interchangeably. Now, suppose the price of a given stock, which I will represent by <em class=\"markup--em markup--p-em\">S<\/em>(<em class=\"markup--em markup--p-em\">t<\/em>), exhibits mean-reverting behavior. This behavior can be more formally described the following <a href=\"https:\/\/en.wikipedia.org\/wiki\/Stochastic_differential_equation\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">stochastic differential equation<\/a> (SDE)<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*8mcmyxRUfVErEH41Iwrg5Q@2x.png\"><br \/><a href=\"https:\/\/en.wikipedia.org\/wiki\/Stochastic_differential_equation\" class=\"markup--anchor markup--figure-anchor\" title=\"Stochastic differential equation\" rel=\"noopener noreferrer\" target=\"_blank\">SDE<\/a> describing a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Ornstein%E2%80%93Uhlenbeck_process\" class=\"markup--anchor markup--figure-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">mean-reverting process<\/a>.<\/p>\n<p class=\"graf graf--p\">Here, the symbols<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*GZ626d3H6w4OCoGjOydnxA@2x.png\"><\/p>\n<p class=\"graf graf--p\">are, respectively, the stock price at time <em class=\"markup--em markup--p-em\">t<\/em>, a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Wiener_process\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Wiener process<\/a> (or Brownian motion) at time <em class=\"markup--em markup--p-em\">t<\/em>, the rate of reversion <em class=\"markup--em markup--p-em\">\u03b8<\/em> to the mean, the equilibrium or mean value of the process <em class=\"markup--em markup--p-em\">\u03bc<\/em> and its volatility <em class=\"markup--em markup--p-em\">\u03c3<\/em>. According to this SDE, the variation of the price at <em class=\"markup--em markup--p-em\">t+1<\/em> is proportional to the difference between the price at time <em class=\"markup--em markup--p-em\">t<\/em> and the mean. As we can see, the price variation is more likely to be positive (negative) if the price is smaller (greater) than the mean. A well-known special case of this SDE is the so-called <a href=\"https:\/\/en.wikipedia.org\/wiki\/Ornstein%E2%80%93Uhlenbeck_process\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Ornstein-Uhlenbeck process<\/a>. The Ornstein-Uhlenbeck process was named after the Dutch physicist <a href=\"https:\/\/en.wikipedia.org\/wiki\/Leonard_Ornstein\" class=\"markup--anchor markup--figure-anchor\" title=\"Leonard Ornstein\" rel=\"noopener noreferrer\" target=\"_blank\">Leonard Ornstein<\/a> and the Dutch-American physicist <a href=\"https:\/\/history.aip.org\/phn\/11610022.html\" class=\"markup--anchor markup--figure-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">George Eugene Uhlenbeck<\/a>\u00a0(see figure below).<\/p>\n<p class=\"graf graf--p\">\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*aaBpqex2xXR7QLstd6wEXg@2x.png\"><\/p>\n<p><\/p>\n<p class=\"graf graf--p\">Two of the best-known tests for (non-)stationarity are the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dickey%E2%80%93Fuller_test\" class=\"markup--anchor markup--p-anchor\" title=\"Dickey\u2013Fuller test\" rel=\"noopener noreferrer\" target=\"_blank\">Dickey-Fuller test<\/a> (DF) and the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Augmented_Dickey%E2%80%93Fuller_test\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Augmented Dickey-Fuller<\/a> (ADF) tests.<\/p>\n<h4 class=\"graf graf--h4\">Dickey-Fuller and Augmented Dickey-Fuller Tests: A Bird\u2019s-Eye View<\/h4>\n<p class=\"graf graf--p\">The ADF test is an extension of the DF test, so let us first understand the latter. It can be illustrated as follows. Consider the simple model given by:<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*f-V5FOVseGLscN05KGe_xw@2x.png\"><\/p>\n<p class=\"graf graf--p\">where <em class=\"markup--em markup--p-em\">S<\/em>(<em class=\"markup--em markup--p-em\">t<\/em>) are stock prices varying in time, <em class=\"markup--em markup--p-em\">\u03c1<\/em> is a coefficient and the last term is an error term. The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Null_hypothesis\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">null hypothesis<\/a> here is that <em class=\"markup--em markup--p-em\">\u03c1=<\/em>1. Since under the null hypothesis both <em class=\"markup--em markup--p-em\">S<\/em>(<em class=\"markup--em markup--p-em\">t<\/em>) and <em class=\"markup--em markup--p-em\">S<\/em>(<em class=\"markup--em markup--p-em\">t-<\/em>1) are non-stationary, the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Central_limit_theorem\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">central limit theorem<\/a> is violated and one has to resort to the following trick.<\/p>\n<p class=\"graf graf--p\">The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dickey%E2%80%93Fuller_test\" class=\"markup--anchor markup--figure-anchor\" title=\"Dickey\u2013Fuller test\" rel=\"noopener noreferrer\" target=\"_blank\">Dickey-Fuller test<\/a> is named for the statisticians <a href=\"https:\/\/en.wikipedia.org\/wiki\/Wayne_Arthur_Fuller\" class=\"markup--anchor markup--figure-anchor\" title=\"Wayne Arthur Fuller\" rel=\"noopener noreferrer\" target=\"_blank\">Wayne Fuller<\/a> and <a href=\"https:\/\/en.wikipedia.org\/wiki\/David_Dickey\" class=\"markup--anchor markup--figure-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">David Dickey<\/a> (picture below). The ADF is an extension of this test for more complex time series\u00a0models.<\/p>\n<p class=\"graf graf--p\">\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*NFo2TUcCuO9UvbyQD9EZyA@2x.png\"><\/p>\n<p class=\"graf graf--p\">Defining the first difference and the parameter <em class=\"markup--em markup--p-em\">\u03b4<\/em> as follows<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*VcCkW7AlahK9dQZ82rc5sA@2x.png\"><\/p>\n<p class=\"graf graf--p\">the regression model can be conveniently rewritten as:<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*hSB0I8_mkTaLSo0fmmG1nQ@2x.png\"><\/p>\n<p class=\"graf graf--p\">The Dickey-Fuller then tests the hypothesis (technically the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Null_hypothesis\" class=\"markup--anchor markup--p-anchor\" title=\"Null hypothesis\" rel=\"noopener noreferrer\" target=\"_blank\">null hypothesis<\/a>) that<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*wVzKTng09r5BPYh-7jJZPg@2x.png\"><\/p>\n<p class=\"graf graf--p\">where the distribution of <em class=\"markup--em markup--p-em\">\u03b4<\/em> was tabulated by <a href=\"https:\/\/en.wikipedia.org\/wiki\/Wayne_Arthur_Fuller\" class=\"markup--anchor markup--p-anchor\" title=\"Wayne Arthur Fuller\" rel=\"noopener noreferrer\" target=\"_blank\">Wayne Fuller<\/a> and <a href=\"https:\/\/en.wikipedia.org\/wiki\/David_Dickey\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">David Dickey<\/a>.<\/p>\n<p class=\"graf graf--p\">The logic behind the DF test can be heuristically understood as follows. If <em class=\"markup--em markup--p-em\">S<\/em>(<em class=\"markup--em markup--p-em\">t<\/em>) is <a href=\"https:\/\/en.wikipedia.org\/wiki\/Stationary_process\" class=\"markup--anchor markup--p-anchor\" title=\"Stationary process\" rel=\"noopener noreferrer\" target=\"_blank\">stationary<\/a> it tends to return to some constant mean (or possibly a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dickey%E2%80%93Fuller_test\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">trend that evolves deterministically<\/a>) which means that larger values are likely to follow smaller ones and vice-versa. That makes the current value of the series a strong predictor of the following value and we would have <em class=\"markup--em markup--p-em\">\u03b4<\/em> < 0. If <em class=\"markup--em markup--p-em\">S<\/em>(<em class=\"markup--em markup--p-em\">t<\/em>) is non-stationary future changes do not depend on the current values (for example, if the process is a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Random_walk\" class=\"markup--anchor markup--p-anchor\" title=\"Random walk\" rel=\"noopener noreferrer\" target=\"_blank\">random walk<\/a>, the current value does not affect the next).<\/p>\n<p class=\"graf graf--p\">The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Augmented_Dickey%E2%80%93Fuller_test\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">ADF<\/a> test follows a similar procedure but it is applied to a more complex hence more complete model given by:<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*HO_tFX9k-f6gEo2ga_Bn7w@2x.png\"><\/p>\n<p class=\"graf graf--p\">Here, <em class=\"markup--em markup--p-em\">\u03b1<\/em> is a real constant, <em class=\"markup--em markup--p-em\">\u03b2<\/em> is the coefficient of the trend in time (a drift term), the <em class=\"markup--em markup--p-em\">\u03b4<\/em>s are the coefficients of the differences<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*AvHS5w3i8OC8CMCCs2Uqkg@2x.png\"><\/p>\n<p class=\"graf graf--p\">where <em class=\"markup--em markup--p-em\">p<\/em> is the lag order of the process and the last term is the error. The test statistic here is<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*HTQ-DIN3Ezjl93wLmNnXwg@2x.png\"><\/p>\n<p class=\"graf graf--p\">where the denominator is the standard error of the regression fit. The distribution of this test statistic was also tabulated by Dickey and Fuller. As in the case of the DF test, we expect <em class=\"markup--em markup--p-em\">\u03b3<\/em><0. Details on how to carry on the test can be found in any <a href=\"https:\/\/www.amazon.com\/Analysis-Financial-Time-Ruey-Tsay\/dp\/0470414359\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">time series book<\/a>.<\/p>\n<h4 class=\"graf graf--h4\">Python Code<\/h4>\n<p class=\"graf graf--p\">The following Python snippet illustrates the application of the ADF test to <a href=\"https:\/\/finance.yahoo.com\/quote\/AAPL\/\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Apple<\/a> stocks prices. Though stock prices are rarely mean reverting, stock log returns usually are. <a href=\"https:\/\/gist.github.com\/marcotav\/da7a34de53f132493e8b45708fb4c0a1.js\" target=\"_blank\" rel=\"noopener noreferrer\">This\u00a0Python code<\/a>\u00a0obtains log differences, plots the result and applies the ADF test.<\/p>\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--fullWidth\"><\/div>\n<div class=\"section-inner sectionLayout--fullWidth\">\n<p class=\"graf graf--p\">The plot is the following:<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*HNTIrqy0oji6Y9EgWt6Zkw.png\"><br \/> Log returns for Apple\u00a0stocks.<\/p>\n<p class=\"graf graf--p\">The output from the ADF test is:<\/p>\n<pre class=\"graf graf--pre\">Augmented Dickey-Fuller test statistic: -28.653611206757994<br>p-value: 0.0<br>Critical Values:<br>\n        1%: -3.4379766581448803<br>\n        5%: -2.8649066016199836<br>\n        10%: -2.5685626352082207<\/pre>\n<p class=\"graf graf--p\">In general, we are more likely to reject the null hypothesis, according to which the series is non-stationary (it has a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Unit_root\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">unit root<\/a>), the \u201cmore negative\u201d the ADF test statistic is. The above test corroborates the hypothesis that the log return series is indeed stationary. The result shows that the statistic value of around -28.65 is less than -3.438 at 1%, the significance level with which we can reject the null hypothesis (see this <a href=\"https:\/\/machinelearningmastery.com\/time-series-data-stationary-python\/\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">link<\/a> for more details).<\/p>\n<h3 class=\"graf graf--h3\">The Hurst\u00a0Exponent<\/h3>\n<p class=\"graf graf--p\">There is an alternative way to investigate the presence of mean reversion or trending behavior in a process. As will be explained in detail shortly, this can be done by analyzing the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Diffusion\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">diffusion<\/a> speed of the series and comparing it with the diffusion rate of a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Random_walk#Anomalous_diffusion\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">random walk<\/a>. This procedure will lead us to the concept of the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hurst_exponent\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Hurst exponent<\/a> which, as we shall see, is closely connected to fractal exponents.<\/p>\n<p class=\"graf graf--p\">Though applications of the Hurst exponent can be found in multiple areas of mathematics, our focus here will be in two of them only, namely fractals and long memory processes.<\/p>\n<h4 class=\"graf graf--h4\">Fractals<\/h4>\n<p class=\"graf graf--p\">A fractal can be <a href=\"https:\/\/www.google.com\/search?q=fractals&#038;oq=fractals&#038;aqs=chrome..69i57j69i61l2j0j35i39j0.2642j0j7&#038;sourceid=chrome&#038;ie=UTF-8\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">defined<\/a> as follows:<\/p>\n<blockquote class=\"graf graf--pullquote graf--startsWithDoubleQuote\"><p>\u201cA curve or geometric figure, each part of which has the same statistical character as the whole. Fractals are useful in modeling structures (such as eroded coastlines or snowflakes) in which similar patterns recur at progressively smaller scales, and in describing partly random or chaotic phenomena such as crystal growth, fluid turbulence, and galaxy formation.\u201d<\/p><\/blockquote>\n<p class=\"graf graf--p\">An example of a fractal is the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Sierpi%C5%84ski_triangle\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Sierpinski triangle<\/a> shown in the figure below.<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*1GK1yiIAWRG00Il52sMHiA.gif\"><\/p>\n<p class=\"graf graf--p\">The \u201cfractal dimension\u201d which measures the roughness of a surface, has the following simple relation with <em class=\"markup--em markup--p-em\">H,<\/em><\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*mckI0351fFqz-JbKAtCs8Q@2x.png\"><\/p>\n<p class=\"graf graf--p\">We see that large Hurst exponents are associated with small fractal dimensions i.e. with smoother curves or surfaces. An example is shown below. This illustration, taken from <a href=\"https:\/\/link.springer.com\/chapter\/10.1007%2F978-1-4612-3784-6_2\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">this article<\/a>, clearly shows that as <em class=\"markup--em markup--p-em\">H<\/em> increases, the curve indeed gets smoother.<\/p>\n<p class=\"graf graf--p\">\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*xqTvZDeKnK5w5TwKFVchnQ@2x.png\"><\/p>\n<p><\/p>\n<p class=\"graf graf--p\">Fractals have a property called <a href=\"https:\/\/en.wikipedia.org\/wiki\/Self-similarity\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">self-similarity<\/a>. One type of self-similarity which occurs in several branches of engineering and applied mathematics is called <a href=\"https:\/\/science.sciencemag.org\/content\/156\/3775\/636\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">statistical self-similarity<\/a>. In data sets displaying this kind of self-similarity, any subsection is statistically similar to the full set. Probably the most famous example of statistical self-similarity is found in coastlines.<\/p>\n<p class=\"graf graf--p\">\n<p class=\"graf graf--p\">\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*FV8U7-qDyq6ivYRG8Ok3JQ@2x.png\"><\/p>\n<p class=\"graf graf--p\">In 1967, <a href=\"https:\/\/en.m.wikipedia.org\/wiki\/Benoit_Mandelbrot\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Benoit Mandelbrot<\/a>, one of the fathers of the field of fractal geometry, published on <a href=\"https:\/\/science.sciencemag.org\/\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Science Magazine<\/a> a <a href=\"https:\/\/science.sciencemag.org\/content\/156\/3775\/636\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">seminal paper<\/a> entitled \u201cHow Long Is the Coast of Britain? Statistical Self-Similarity and Fractional Dimension\u201d where he discussed the properties of fractals such as self-similarity and <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hausdorff_dimension\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">fractional (Hausdorff) dimensions<\/a>.\u00a0The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Coastline_paradox\" target=\"_blank\" rel=\"noopener noreferrer\">picture above<\/a> shows an example of the\u00a0<a href=\"https:\/\/en.wikipedia.org\/wiki\/Coastline_paradox\" class=\"markup--anchor markup--figure-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">coastline paradox<\/a>. According to it, if one measures coastlines using different units one obtains different results.<\/p>\n<h4 class=\"graf graf--h4\">Long Range Dependence<\/h4>\n<p class=\"graf graf--p\">One important kind of departure from random walks occurs when processes have long-range dependence. These processes display a high persistence degree: past events are nontrivially correlated with future events even if they are very far apart. One example, conceived by <a href=\"https:\/\/books.google.com.br\/books?id=w8HPcMJsk-cC&#038;pg=PA121&#038;lpg=PA121&#038;dq=Granger,+Joyeux,+and+Hosking&#038;source=bl&#038;ots=nRsiyBj7Nv&#038;sig=ACfU3U1x3n11cVBT8JGHIS5zeGWJXie92g&#038;hl=en&#038;sa=X&#038;ved=2ahUKEwjwqK2s2u7iAhW4ILkGHQdoABEQ6AEwAXoECAkQAQ#v=onepage&#038;q=Granger%2C%20Joyeux%2C%20and%20Hosking&#038;f=false\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Granger, Joyeux, and Hosking<\/a>, is given by the following <em class=\"markup--em markup--p-em\">fractionally<\/em> differenced time series:<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*W9MQNBaa_OrvLmg9kZmBRw@2x.png\"><\/p>\n<p class=\"graf graf--p\">where <em class=\"markup--em markup--p-em\">L<\/em> is the usual <a href=\"https:\/\/en.wikipedia.org\/wiki\/Lag_operator\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">lag operator<\/a>, the exponent <em class=\"markup--em markup--p-em\">d<\/em> is noninteger and <em class=\"markup--em markup--p-em\">\u03f5<\/em> is an error term. Using a simple <a href=\"https:\/\/en.wikipedia.org\/wiki\/Binomial_theorem\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">binomial expansion<\/a> this equation can be expressed in terms of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Gamma_function\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Gamma functions<\/a><\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*swQdN2GG8BDYdaG9tCq3fw@2x.png\"><\/p>\n<p class=\"graf graf--p\">Comparing the autocorrelation function of a simple <a href=\"https:\/\/en.wikipedia.org\/wiki\/Autoregressive_model\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">AR(1)<\/a> process we find that the autocorrelation function of the latter has a much slower decay rate than the one from the former. For example, for a lag of <em class=\"markup--em markup--p-em\">\u03c4<\/em>~25,<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*x2ycER8XBTpgGPpD1RqDNg@2x.png\"><\/p>\n<p class=\"graf graf--p\">whereas the corresponding value of the autocorrelation function of the fractionally differenced process is ~-0.17.<\/p>\n<h4 class=\"graf graf--h4\">Origins of the Hurst\u00a0Exponent<\/h4>\n<p class=\"graf graf--p\">Though most recent developments regarding methods of estimation of the Hurst exponent are coming from the mathematics of fractals and chaos theory, the Hurst exponent was curiously first used in the field of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hydrology\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">hydrology<\/a>, which is <a href=\"https:\/\/www.google.com\/search?q=Dictionary#dobs=hydrology\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">mainly concerned<\/a> with water distribution, quality, and its movement in relation to land. Furthermore, recent tests for long term dependence in financial time series are based on a statistic called Rescaled Range (see below), originally developed by the English hydrologist <a href=\"https:\/\/en.wikipedia.org\/wiki\/Harold_Edwin_Hurst\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Harold Hurst<\/a>. The front page of Hurst\u2019s original paper is <a href=\"https:\/\/www.tandfonline.com\/doi\/pdf\/10.1080\/02626665609493644\" target=\"_blank\" rel=\"noopener noreferrer\">shown below<\/a>.\u00a0<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*mbWfEzdwP3emThHFEV2B_w@2x.png\"><\/p>\n<h3 class=\"graf graf--h3\">Hurst Exponent and Anomalous Diffusion<\/h3>\n<p class=\"graf graf--p\">One way to gain some understanding of the nature of a price series is to analyze its speed of diffusion. Diffusion is a widely used concept which describes the \u201c<a href=\"https:\/\/en.wikipedia.org\/wiki\/Diffusion#Diffusion_in_the_context_of_different_disciplines\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">spreading out<\/a>\u201d of some object (which could be an idea, the price of an asset, a disease, etc) from a location where its concentration is higher than in most other places.<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/2400\/1*vh5WS_PiPI6GGSHm8OmO3g@2x.png\"><br \/> The plot shows how the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Mean_squared_displacement%5D\" class=\"markup--anchor markup--figure-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">mean squared displacement<\/a> varies with the elapsed time \u03c4 for three types of diffusion (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Anomalous_diffusion\" class=\"markup--anchor markup--figure-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">source<\/a>).<\/p>\n<p class=\"graf graf--p\">Diffusion can be measured studying how the <a href=\"https:\/\/www.investopedia.com\/terms\/v\/variance.asp\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">variance<\/a> depends on the difference between subsequent measurements:<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*9XGry0tS-LXGKrxazsE2FQ@2x.png\"><\/p>\n<p class=\"graf graf--p\">In this expression, <em class=\"markup--em markup--p-em\">\u03c4<\/em> is the time interval between two measurements and <em class=\"markup--em markup--p-em\">x<\/em> is a generic function of the price <em class=\"markup--em markup--p-em\">S<\/em>(<em class=\"markup--em markup--p-em\">t<\/em>). This function is often chosen to be the log price:<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*ILeLC_Ar8mioEYCmU64xWA@2x.png\"><\/p>\n<p class=\"graf graf--p\">It is a well-known fact that the variance of stock price returns depends strongly on the frequency one chooses to measure it. Measurements at high frequencies say, in 1-minute intervals, differ significantly from daily measurements.<\/p>\n<p class=\"graf graf--p\">If stock prices follow, which is not always the case (in particular for daily returns), a geometric random walk (or equivalently a geometric Brownian motion or GBM), the variance would vary linearly with the lag <em class=\"markup--em markup--p-em\">\u03c4<\/em><\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*eYaDcpLCagSfOnkaBXphGQ@2x.png\"><\/p>\n<p class=\"graf graf--p\">and the returns would be normally distributed. However, when there are small deviations from a pure random walk, as it often occurs, the variance for a given lag <em class=\"markup--em markup--p-em\">\u03c4<\/em> is not proportional to the <em class=\"markup--em markup--p-em\">\u03c4<\/em> anymore but instead, it acquires an <a href=\"https:\/\/en.wikipedia.org\/wiki\/Anomalous_diffusion\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">anomalous exponent<\/a><\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/2400\/1*mvAbICdkFLLtvOwoqgOitw@2x.png\"><br \/> The anomalous exponent is proportional to the Hurst exponent (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Anomalous_diffusion\" class=\"markup--anchor markup--figure-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">source<\/a>).<\/p>\n<p class=\"graf graf--p\">The parameter <em class=\"markup--em markup--p-em\">H<\/em> is the so-called <a href=\"https:\/\/en.wikipedia.org\/wiki\/Hurst_exponent\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Hurst exponent<\/a>. Both mean-reverting and trending stocks are characterized by<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*hFt-ws6Tv9RsbUQO7kuBYg@2x.png\"><\/p>\n<p class=\"graf graf--p\">Daily returns satisfying this equation do not have a normal distribution. Instead, the distribution has fatter tails and thinner and higher peaks around the mean.<\/p>\n<p class=\"graf graf--p\">The Hurst exponent can be used to distinguish three possible market regimes:<\/p>\n<ul class=\"postList\">\n<li class=\"graf graf--li\">If <em class=\"markup--em markup--li-em\">H<\/em> < 0.5, the time series is mean reverting or stationary. The log-price volatility increases at a slower rate compared to normal diffusion associated with geometric Brownian motion. In this case, the series displays what is known as <em class=\"markup--em markup--li-em\">antipersistence<\/em> (long-term switching between high and low values in adjacent points)<\/li>\n<li class=\"graf graf--li\">If <em class=\"markup--em markup--li-em\">H<\/em> > 0.5, the series displays trending behavior and it is characterized by the presence of <em class=\"markup--em markup--li-em\">persistent<\/em> behavior (long-term positive autocorrelation i.e. high values are likely to follow high values)<\/li>\n<li class=\"graf graf--li\">The <em class=\"markup--em markup--li-em\">H<\/em> = 0.5 case corresponds to a Geometric Brownian Motion<\/li>\n<\/ul>\n<p class=\"graf graf--p\">The Hurst exponent, therefore, measures the level of persistence of a time series and can be used to identify the market state: if at some time scale, the Hurst exponent changes, this may signal a shift from a mean reversion to a momentum regime or vice versa.<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*hrxoGi2X894HzlK657XaxA@2x.png\"><br \/> Relations between market regimes and the Hurst exponent.<\/p>\n<blockquote class=\"graf graf--pullquote\"><p>The Hurst exponent, therefore, measures the level of persistence of a time series and can be used to identify the market\u00a0state.<\/p><\/blockquote>\n<p class=\"graf graf--p\">Examples of each case are plotted below:<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*sn47Tb-e8H_BH6NgZUqUTg@2x.png\"><\/p>\n<p class=\"graf graf--p\">In the next figure, we see how the Hurst exponent can vary with time indicating a change in regime.<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*GSPz1Lmr3FgU4T9MVAsCmQ.png\"><\/p>\n<p><\/p>\n<h4 class=\"graf graf--h4\">Autocorrelation<\/h4>\n<p class=\"graf graf--p\">The autocorrelation function for the stock price <em class=\"markup--em markup--p-em\">S<\/em>(<em class=\"markup--em markup--p-em\">t<\/em>) is defined as follows:<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*XJrYjWZbtCvp_0KlpmjWKA@2x.png\"><\/p>\n<p class=\"graf graf--p\">Processes with autocorrelations that decay very slowly are termed long memory processes. Such processes have some memory of past events (past events have a decaying influence on future events). Long memory processes are characterized by autocorrelation functions <em class=\"markup--em markup--p-em\">\u03c1<\/em>(<em class=\"markup--em markup--p-em\">\u03c4<\/em>) with power-law decay<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*Dv8R8EKbs_2KiropWr_4AA@2x.png\"><\/p>\n<p class=\"graf graf--p\">The relation between <em class=\"markup--em markup--p-em\">\u03b1<\/em> and the Hurst exponent is<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*fBIMZqkIiYEX_AOZ_mJRSQ@2x.png\"><\/p>\n<p class=\"graf graf--p\">Note that as <em class=\"markup--em markup--p-em\">H<\/em> approaches 1, the decay becomes slower and slower since the exponent <em class=\"markup--em markup--p-em\">\u03b1<\/em> approaches zero, indicating \u201cpersistent behavior\u201d. It often happens that processes that appear random at first, are actually long memory processes, having Hurst exponents within the open interval<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*w8O9A6MjWY7N-xOAzg4Biw@2x.png\"><\/p>\n<p class=\"graf graf--p\">Those processes are often referred to as <a href=\"https:\/\/en.wikipedia.org\/wiki\/Fractional_Brownian_motion\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">fractional Brownian motion<\/a> (fBm) or <a href=\"https:\/\/books.google.com.br\/books?id=_bkoySKyc_cC&#038;pg=PA183&#038;lpg=PA183&#038;dq=fBm+%22black+noise%22&#038;source=bl&#038;ots=sOymnxU0GN&#038;sig=ACfU3U2OmL0QXl027PvJbi3Ab8NNq9Dvag&#038;hl=en&#038;sa=X&#038;ved=2ahUKEwjDtuG936TiAhVsLLkGHSpPBvkQ6AEwCXoECAYQAQ#v=onepage&#038;q=fBm%20%22black%20noise%22&#038;f=false\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">black noise<\/a>, a generalization of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Brownian_motion\" class=\"markup--anchor markup--p-anchor\" title=\"Brownian motion\" rel=\"noopener noreferrer\" target=\"_blank\">Brownian motion<\/a>.<\/p>\n<h4 class=\"graf graf--h4\">Important Issues with Using the Variance to Estimate the\u00a0Hurst<\/h4>\n<p class=\"graf graf--p\">To obtain the variance dependence on <em class=\"markup--em markup--p-em\">\u03c4<\/em>, we must repeat the same calculation for many lags, and extract the slope of the logarithmic plot of the result. As we will see now, the value of <em class=\"markup--em markup--p-em\">H<\/em> depends strongly on our choices of lags. This section is based on the analysis found in <a href=\"https:\/\/robotwealth.com\/demystifying-the-hurst-exponent-part-2\/\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">this blog post<\/a>.<\/p>\n<p class=\"graf graf--p\">Let us consider the S&#038;P 500 Index <a href=\"https:\/\/www.nasdaq.com\/symbol\/spy\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">SPY<\/a> and estimate the Hurst exponent for different lags. We first run <a href=\"https:\/\/gist.github.com\/marcotav\/c38656a7bb39f057d432664449441f8d\" target=\"_blank\" rel=\"noopener noreferrer\">this code<\/a>, which takes the range of lags to be from 2 to 20.<\/p>\n<p class=\"graf graf--p\">We obtain the following value for <em class=\"markup--em markup--p-em\">H<\/em>:<\/p>\n<pre class=\"graf graf--pre\">hurst =  0.43733191005891303<br><br><\/pre>\n<p class=\"graf graf--p\">As previously explained, this value of <em class=\"markup--em markup--p-em\">H<\/em> indicates a mean-reverting regime, albeit rather mild. The same code with lags 300\u2013400, gives:<\/p>\n<pre class=\"graf graf--pre\">hurst =  0.6107941846903405<br><br><\/pre>\n<p class=\"graf graf--p\">This value of <em class=\"markup--em markup--p-em\">H<\/em> indicates the presence of a trending regime. We see, therefore, that the choice of lags strongly affects the value of the Hurst exponent. This means that this time series is neither purely mean-reverting nor trending, but changes behavior or <strong class=\"markup--strong markup--p-strong\">shifts regimes<\/strong> depending on whether one measures it over short intervals or over the long term. Furthermore, as noted <a href=\"https:\/\/robotwealth.com\/demystifying-the-hurst-exponent-part-2\/\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">here<\/a>, since these conclusions are far from obvious for the naked eye, we conclude that this analysis based on the Hurst exponent can give important insights.<\/p>\n<h3 class=\"graf graf--h3\">Long-Range Dependence and the Rescaled\u00a0Range<\/h3>\n<p class=\"graf graf--p\">The presence of long term anomalous behavior of stock returns was <a href=\"https:\/\/www.jstor.org\/stable\/1937966?seq=1#page_scan_tab_contents\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">noticed<\/a> in 1971 by <a href=\"https:\/\/en.wikipedia.org\/wiki\/Benoit_Mandelbrot\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Mandelbrot<\/a>\u00a0(picture below).<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*RbQtoe-8jTDGI_P3odVPHA@2x.png\"><\/p>\n<p class=\"graf graf--p\">To test for such long-range dependence, Mandelbrot <a href=\"https:\/\/www.jstor.org\/stable\/1937966?seq=1#page_scan_tab_contents\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">used<\/a> the Rescaled Range or R\/S test statistic, briefly mentioned above. The R\/S statistic <a href=\"https:\/\/press.princeton.edu\/titles\/5904.html\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">is<\/a> the range of partial sums of deviations of a series from its mean rescaled by the standard deviation (see <a href=\"https:\/\/press.princeton.edu\/titles\/5904.html\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">this book<\/a> for more details). Mandelbrot and others showed that using the R\/S statistic leads to far superior results when compared with other methods such as the analysis of autocorrelations, variance ratios, and spectral decomposition, though it does have shortcomings, such as sensitivity to short-range dependence (for more details, see <a href=\"http:\/\/www.jonathankinlay.com\/Articles\/Long%20Memory%20and%20Regime%20Shifts%20in%20Asset%20Volatility.pdf\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">this article<\/a> and <a href=\"https:\/\/robotwealth.com\/exploring-mean-reversion-and-cointegration-with-zorro-and-r-part-1\/\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">this excellent blog post<\/a>).<\/p>\n<p class=\"graf graf--p\">The R\/S statistic can be obtained as follows. Consider for example the following time series of stock returns of length <em class=\"markup--em markup--p-em\">n<\/em><\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*vbDpYXmFUpFwezxE039EKg@2x.png\"><\/p>\n<p class=\"graf graf--p\">The partial sum of the first <em class=\"markup--em markup--p-em\">k<\/em> deviations from the mean is given by:<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*AKb7ecSCFWu7byAMXv7IMg@2x.png\"><\/p>\n<p class=\"graf graf--p\">The R\/S statistic is proportional to the difference between the maximum and minimum of such sums where <em class=\"markup--em markup--p-em\">k<\/em> \u2208 [<em class=\"markup--em markup--p-em\">1<\/em>,<em class=\"markup--em markup--p-em\">n<\/em>]:<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*UYRciH3kmftaizd1A6dgtQ@2x.png\"><\/p>\n<p class=\"graf graf--p\">The denominator <em class=\"markup--em markup--p-em\">\u03c3<\/em>(<em class=\"markup--em markup--p-em\">n<\/em>) is the <a href=\"https:\/\/statistics.laerd.com\/statistical-guides\/measures-of-spread-standard-deviation.php\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">maximum likelihood standard deviation estimator<\/a>. The rescaled range and the number <em class=\"markup--em markup--p-em\">n<\/em> of observations have the following relation<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*QkpVVZesyDdKSJxGFW9gtA@2x.png\"><\/p>\n<p class=\"graf graf--p\">where <em class=\"markup--em markup--p-em\">H<\/em> is the Hurst exponent. This scaling behavior was first used by <a href=\"https:\/\/agupubs.onlinelibrary.wiley.com\/doi\/abs\/10.1029\/WR005i002p00321\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Mandelbrot and Wallis<\/a> to find the presence of long-range dependence. Since the relation between the rescaled range and the number of observations is polynomial, one can calculate the value of <em class=\"markup--em markup--p-em\">H<\/em> with a simple log-log plot since<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*6d3iAD_INHzYoGY9aCr23g@2x.png\"><\/p>\n<p class=\"graf graf--p\">In the plot below, the Hurst exponent is estimated to be around 0.53 which approximately corresponds to a random walk. <a href=\"https:\/\/gist.github.com\/marcotav\/78690b027a632d327d940add982838cf\" target=\"_blank\" rel=\"noopener noreferrer\">The corresponding code<\/a> uses the <code class=\"markup--code markup--p-code\">hurst<\/code> library (the link to the Github repo is <a href=\"https:\/\/github.com\/Mottl\/hurst\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">here<\/a>).<\/p>\n<p><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*va0SwCKYvzPirXcIZczZQQ@2x.png\"><br \/> Estimation of the Hurst exponent gives H~0.5183. The code uses the Github repo found\u00a0<a href=\"https:\/\/github.com\/Mottl\/hurst\" class=\"markup--anchor markup--figure-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">here<\/a>. There are other methods to obtain the Hurst. You can check <a href=\"http:\/\/www.jonathankinlay.com\/Articles\/Long%20Memory%20and%20Regime%20Shifts%20in%20Asset%20Volatility.pdf\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">this article<\/a> for more details on that.<\/p>\n<p><\/p>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<h3 class=\"graf graf--h3\">Conclusions and\u00a0Outlook<\/h3>\n<p class=\"graf graf--p\">We saw that using the concept of the Hurst exponent can lead to very useful insights about the market regime. With that information in hand, one can decide which of the two strategies, mean reversion or momentum, is more appropriate to adopt.<\/p>\n<p class=\"graf graf--p\">In short, the value of the Hurst exponent identifies if the time series has some memory of past events. The fact that the value of the Hurst is not always equal to 1\/2 shows that the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Efficient-market_hypothesis\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">efficient market hypothesis<\/a>, according to which markets are completely unpredictable is often violated. Properly identifying such anomalies can in principle be extremely useful for building efficient trading strategies.<\/p>\n<\/div>\n<\/div>\n<div class=\"section-divider\">Thanks for reading and see you soon! As always, constructive criticism and feedback are always welcome!<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<p class=\"graf graf--p\">My <a href=\"https:\/\/github.com\/marcotav\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">Github<\/a> and personal website <a href=\"https:\/\/marcotavora.me\/\" class=\"markup--anchor markup--p-anchor\" rel=\"noopener noreferrer\" target=\"_blank\">www.marcotavora.me<\/a> have (hopefully) some other interesting stuff about data science and quantitative finance.<\/p>\n<p class=\"graf graf--p\">\n<p class=\"graf graf--p\">This article was originally published on <a href=\"https:\/\/towardsdatascience.com\/how-the-mathematics-of-fractals-can-help-predict-stock-markets-shifts-19fee5dd6574\" target=\"_blank\" rel=\"noopener noreferrer\">Towards Data Science<\/a>.<\/p>\n<\/div>\n<\/div>\n<p><\/div>\n<div class=\"section-inner sectionLayout--insetColumn\"><\/div>\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<p class=\"graf graf--p\">\n<\/div>\n<\/div>\n<\/div>\n<p><a href=\"https:\/\/www.datasciencecentral.com\/xn\/detail\/6448529:BlogPost:848585\">Go to Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Author: Marco Tavora In financial markets, two of the most common trading strategies used by investors are the momentum and mean reversion strategies. If a [&hellip;] <span class=\"read-more-link\"><a class=\"read-more\" href=\"https:\/\/www.aiproblog.com\/index.php\/2019\/07\/05\/how-the-mathematics-of-fractals-can-help-predict-stock-markets-shifts\/\">Read More<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":2332,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"footnotes":""},"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts\/2331"}],"collection":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/comments?post=2331"}],"version-history":[{"count":0,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/posts\/2331\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/media\/2332"}],"wp:attachment":[{"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/media?parent=2331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/categories?post=2331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aiproblog.com\/index.php\/wp-json\/wp\/v2\/tags?post=2331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}