Showing posts with label Hurst Exponent. Show all posts
Showing posts with label Hurst Exponent. Show all posts

Thursday, October 15, 2009

Rescaled Range Analysis

The Rescaled Range Analysis is an interesting statistical tool to detect long-range dependence in a time-series, and it also provides a method to estimate the Hurst Exponent. I have detailed to some extent this method on my other blog at this address.

Having estimated the Hurst Exponent, I was then able to write a Fractalised Moving Average, very much in the style of the FRASMA, except that this one, called RS_FRASMA, used the estimation of the Hurst Exponent coming from a Rescaled Range Analysis.
Unfortunately, this analysis is rather demanding in terms of computing power and time, I was therefore limited to small sample of values and even then, the processing time is quite long, furthermore, the result of the estimation is not very good, and not good enough anyway to be usable in terms of a fractional bands type of indicator.
Nevertheless, the RS_FRASMA may still be of some interest, if only in comparison with other MAs, and I therefore uploaded a script in MQL4 at this address.

The logic of the RS_FRASMA is similar to the one at work in the FRASMA: An SMA is modified by multiplication of its speed with a factor alpha defined as such:



Where H is the Hurst Exponent.

Here is what it looks like, the red curve is the RS_FRASMA, the yellow one is the FRASMA, and the blue one is an SMA, all with unmodified speed of 30:



The parameters of RS_FRASMA are:
period (integer): The size of the sample on which the Rescaled Range Analysis is performed, it must be a power of 2 (4,8,16,32,64,128,...), the default is 64, and in consideration of the limited computing power of MT4, I don't advise going higher than 256.
normal_speed (integer): This is the normal speed of the Moving Average before it is modified by the Hurst Parameter.
PIP_Convertor (integer): The factor necessary to convert real price to PIPS, default is 10000 (for EUR/USD)
type_data (0,1,2,3,4,5 or 6): This is the type of price the indicator will consider (0=CLOSE, 1=OPEN, 2=HIGH, 3=LOW, 4=MEDIAN, 5=TYPICAL, 6=WEIGHTED), default is 0.

Thursday, May 7, 2009

Fractional Bands

Let's consider again the equation (1) from yesterday:



We were facing the technical problem of having very small real variations of prices, leading to very small standard deviations. This can however be easily solved by converting all our values in PIPS. For EUR/USD, it simply consists in multiplying all the prices by 10000. If we then apply the above equation to PIPS, and convert it back to the scale of real prices (by dividing by 10000), we can then get a proper representation of bands, which, given that they are strictly obeying the model of FBM we are working with, I shall name Fractional Bands.

Here is a representation of these fractional bands for the 5 mn timeframe of EUR/USD, the red bands are the Fractal Bands defined as earlier, with the default parameters, the yellow bands are the Fractional Bands, with the same default parameters (without α, which we don't need anymore since we are not using equation (2)):



We can also compare the Fractional Bands (in yellow) with the Bollinger Bands (in blue-green) , to confirm what we expect from the above equation:



We indeed see that whenever the Fractal Dimension crosses the 1.5 line (i.e. whenever H crosses the 0.5 mark), the respective bands cross as well. The Fractional Bands are therefore narrower for a side-market and wider for a trendy market (even wider than the Fractal Bands for a very trendy market).

The script of Fractional Bands can be downloaded from this address.
The paramaters for the Fractional Bands are the same as for the Fractal Bands except that there is no α, and in addition, we have the following parameter:
PIP_Convertor (integer): the factor necessary to convert real price to PIPS, default is 10000 (for EUR/USD)

As for the strategy, I am not sure whether there is one for this indicator alone, it seems to cross the prices quite often, especially during a side-market, it may however be combined efficiently with the FGDI and/or the Fractal Bands.

Wednesday, May 6, 2009

From Bollinger to Fractal Bands

Bollinger Bands indicator is a well-known and interesting indicator, as it provides with entry and exit points. It basically consists in a MA and two bands above and below it. Each band is classically placed at 2 standard deviations away from the MA. If we assume that price variations follow a normal distribution, this ensures that 95% of the prices will fall within the bands.
______________________________________________________________________________________________________

I-Some theoretical points

Keeping this assumption for now, the time-series of price variations can be described by a Wiener Brownian Motion of normal distribution N(0,t). It is interesting to see the probability of the prices to be within the bands is equal to the probability of the maximum of the price (that we will name M(t)) to be within them, as shown below:



For more details and the justification of this formula, see my other blog.
We then see:



Such probabilities are calculated for the theoretical value of the standard deviation of the WBM, the Bollinger Bands, however, calculates an empirical value for it using the well known formula:



Given this practical σ and the theoretical one, we can equate the two:



And knowing the theoretical standard deviation for a FBM (see there), we get the practical standard deviation for FBM (of Hurst parameter H):




II-Implementation of Fractal Bands

A straightforward way to implement Fractal Bands seems to just take classical Bollinger Bands and merely increase the width of the bands by raising the standard deviation to the power of 2H. However, if we do that, here is what we get (the MA is the FRASMAv2, the reference period is 30, the blue bands are Bollinger Bands for the same speed) :



I don't find this indicator very useful (not useful at all actually, for me). It seems necessary here to get some perspective about how we wish to improve on the Bollinger Bands. From my point of view, as a day trader, I feel Bollinger Bands too narrow, the prices hit them too often, especially in a trending market, where I would like to get a clear signal only when the trend is over. But, with Bollinger Bands, most of the trend occurs outside the bands, prompting me to close the trade much too early and basically inciting me not to ride the trend.
Applying equation (1) however, we get the counter-productive effect of narrowing the bands when in a trend, because, in our case of price variation, the standard variation is much lower than 1(this may not be the case for stock exchange, but it clearly is for FOREX), raising it to a higher power therefore decreases its value proportionally.
A way out of this quandary is simply to apply the following treatment to the standard deviation from the Bollinger Bands instead of the one from (1):



By taking α greater than 1, the higher our H, the wider the bands will be, here is what it leads to (with the same setup as before, and α=2):



The script fractal_bands.mq4 can be downloaded from this address from the MQL4 site.
The input parameters of the indicator are as follows:
e_period (integer): This is the period considered for calculating the fractal dimension, default is 30.
normal_speed (integer): This is the speed of the SMA before being modified to become the FRASMA, default is 30.
alpha (real): This is the alpha from equation (2), default is 2.
shift (integer): This is the number of bars the FRASMA is shifted to the right(positive) or to the left(negative), default is 0.
e_type_data (0,1,2 or 3): This is the type of price the indicator will consider (0=CLOSE, 1=OPEN, 2=HIGH, 3=LOW), default is 0.


III-Strategical considerations

I have started using the Fractal Bands indicator, and am very happy of it so far. The strategy is quite straightforward.
I enter in a BUY position after the price have rebounded (after touching it) from the lower band and crossed the FRASMA, my Stop Loss is then set to the level the prices hit the lower band, and my Take Profit is when the prices hit the higher band.
Symmetrically, I enter a SELL position after the price have fallen from the higher band (after touching it) and crossed the FRASMA, Stop Loss set at the level of the hit of the higher band, and Take Profit when the lower band is hit.
It is obviously possible (and even advised) to make your Stop Loss trailing the price changes.
I used this strategy for EUR/USD on a 5 minutes timeframe, using it on other timeframes or on other instruments may require a different setup, mine was to set the speed of the FRASMA at 30, and α=2 (in equation (2) above), it is possible to change these values.

Sunday, February 15, 2009

The speed of the FRAMA (Part 2): The FRASMA

Having explained my preference for a "fractalisation" of the MA to apply on a SMA(rather than on an EMA), I shall now discuss the exact form of this "fractalisation".
A modification, close to the one recommended by Ehlers, would be to merely divide the period of the SMA by the coefficient α, where α is defined as:



For a dimension D varying between 1 and 2, such a division would indeed be equivalent to a change of speed in a ratio of 100, the SMA being slowed down 100 times from its initial pace, in the extreme case of a dimension of 2.
This dimension D is a numerical approximation of the Box Dimension, itself an approximation of the Hausdorff dimension of the graph, which is properly the most mathematically precise fractal dimension. There is however, another dimension that can also be seen as a Box Dimension, but of another object relating to the process under study, and that Mandelbrot called the Trail Dimension [MAN97,pp.161&172).

For a Fractional Brownian Motion, we saw earlier that:



Where is what we have called so far the Fractal dimension, and α is the coefficient of the FBM (which is a different thing from the α of equation (E1)) . This latter is actually known as the Hurst-Holder exponent (or sometimes as simply the Hurst exponent, in memory of the British hydrologist whose studies of the long-term dependence of the Nile discharges, were inspirational to Mandelbrot works), and most often designed by H, I used α in reference to Falconer's book, but H seems more convenient from now on. We therefore have:



And will now be known as the Graph Dimension. While the Trail Dimension will be defined as:


_________________________________________________________________________________________________________________

I-Interpretation of the Trail Dimension

It is easy to see that the Trail Dimension varies between 1 and ∞, for the coefficient H varying between 1 and 0. The first question is therefore how a "dimension" growing infinitely should be understood. In [MAN97], p.161, Mandelbrot wrote the following explanation:

"First consider a Wiener Brownian motion in the plane. Its coordinates X(t) and Y(t) are independent Brownian motions. Therefore, if a 1-dimensional Brownian motion X(t) is combined with another independent 1-dimensional Brownian motion Y(t), the process X(t) becomes "embedded" into a 2-dimensional Brownian motion {X(t),Y(t)}. The value of the trail dimension:

is the fractal dimension of the three dimensional graph of coordinates t,X(t) and Y(t), and the projected "trail" of coordinates X(t) and Y(t). However, the dimension:

applies to the projected graphs of coordinates t and X(t) or t and Y(t)."

My understanding of the above passage, in the general case of FBM (H varying between 0 and 1, while for WBM, H=1/2), is that the Trail dimension must be seen as an approximation of the number of dimensions in which the "real" process takes place (here it might be interesting to understand the term of "dimension" in a data-mining sense, rather than in a strict topological sense, prices are clearly the end-result of many independent processes, any of them with the potential of being chaotic in their own right), under the assumption that all the coordinates of the said process can be described as independent Fractional Brownian motions sharing the same Hurst exponent.

II-Slowing down the MA with the Trail Dimension

It is now possible to conceive of a formula for the coefficient α, using the Trail Dimension. The purpose of α is to slow down the MA from a reference speed when the Hurst exponent becomes very small, and also to accelerate it when this exponent becomes close to 1. The reference speed should be taken as the one used when the price varies in a gaussian way, that is when H is 1/2. So for such a value of H, we should have α=1.
If we then consider the following formula:



For a WBM, we have α=1. In addition, for a H tending towards 0, α tends towards infinity, and for H close to 1, α=1/2.
Comparing α from (E2)(red curve) with the inverse of α from (E1)(black curve)(we take the inverse in order to get a multiplicative factor rather than a dividing one to apply on the speed of the MA), we get the following graphs:



Or, for a more detailed view of their behavior below H=1/2:



Dividing the black curve by 10 in order to have an unchanged speed for the case of a WBM, we get the following:



For H varying from 0.5 to 0, we see that the α coming from (E1) varies almost linearly, for the same variation however, we know that the randomness increases in a rather non-linear fashion; a linear slowing down of the MA does not seem to reflect this properly. From this theoretical point of view, I therefore prefer the α given by equation (E2)(not to mention that it is much more simple).

III-Implementation of the FRASMA

I programmed the FRASMA(Fractally modified Simple Moving Average) in the MetaTrader platform. You may access and download freely this indicator, as well as use it on the metatrader 4 platform, at this address of the MQL4 Community.
Please, let me know your findings or any criticisms that can improve this indicator.
Meanwhile, here is a screenshot of three fractally modified MA, the Light Blue is a version of the FRAMA from Ehlers paper (modifying a EMA), the Yellow is a modification of a SMA using the following α inspired by Ehlers paper:

And the Red one is properly the FRASMA, using equation (E2).



Below is the fractal Graph Dimension. The period of reference for all original MA is 20.

IV-Conclusion

My purpose here is not to demonstrate that one indicator is better than another, since the quality of an indicator is relative to the manner one uses it. I believe that one must be acquainted intuitively with an indicator to use it productively, and it is for this reason that my preference is going to the FRASMA.
While one may just rely on direct practise to "understand" at an intuitive level a given indicator, I believe most of us can also profit from a theoretical understanding of them. My goal here is therefore to provide elements along these lines, for others to develop their own familiarity, and maybe provide me, in return, with some of their insights and experiences.
It is again naive to think that a trader, using technical analysis, can actually trade without some level of reliance on his intuition, and it is to totally miss the point of what the fractals tell us about the market to nourish expectations about a deterministic methodology to be successful as a trader, in other words, there is no Grail to be found in the first place. Nonetheless, to understand the technical tools one is using, can improve one's intuition, and the overall success of one's trading activity.