Friday, April 17, 2009

Fractal dimensions...And a Fractal Graph Dimension Indicator

I have already alluded to the possible confusion with regard to what the fractal dimension exactly is, and even though I try to always clarify the kind of fractal dimension I am considering in a given context, I never provided with a detailed discussion of this problem. So here it is, I am going, in this overview, to discuss the various definition of this entity, and give some references which examine their relationship in more detail.
Eventually, I shall provide with a new indicator that slightly improves on the previous calculation of the fractal dimension of a graph.

1) Hausdorff Dimension (or Besicovitch-Hausdorff Dimension).
This is the oldest and most mathematically convenient definition of the fractal dimension of an object, but it is also extremely difficult to calculate exactly for most object, especially those who are not exactly self-similar, which is basically the case of all interesting objects in any applied domain.
We first need to define a measure of an object F as such:



Where a δ-cover is a countable (or finite) collection of sets of diameter at most δ that covers F.
The s-dimensional Hausdorff measure of F is then defined as:



The Hausdorff Dimension is then defined as:



The difficulty in computing this quantity lies in the definition of a δ-cover. The sets of the collection are indeed not necessarily having a diameter of δ, on the contrary, it will be frequent to have an optimal collection (in the sense of optimizing equation (1)) that will have sets with a diameter much smaller than δ, and to explicit the logic behind such a construction is only possible for extremely simple sets (typically, sets that are explicitly built through a well-known iterative process). That is obviously not the case of sets found in practice as a model of a real phenomenon.
This difficulty can be overcome by the Box-counting Dimension to which I come now. For more details about the Hausdorff Dimension see Chapter 2 in [FALC03].

2) Box-counting Dimension (or Kolmogorov Entropy, Entropy Dimension, Capacity Dimension, Metric Dimension, Logarithmic Density and Information Dimension)
The Box-counting Dimension can be defined simply as:



Where can be any of the following (not exhaustive list):
- The smallest number of closed balls of radius δ that cover F;
- The smallest number of cubes of side δ that cover F;
- The number of δ-mesh cubes that intersect F;
- The smallest number of sets of diameter at most δ that cover F;
- The largest number of disjoint balls of radius δ with centres in F.

From the definition of both the Hausdorff and the Box-counting Dimension, it is easy to see intuitively (from equation (1)) that:



For a formal proof of that and more detail about the Box-counting Dimension, see Chapter 3 in [FALC03].
There are some other alternatives to define the fractal dimension, but so far, I have not seen applications of those to finance, and therefore, I will not mention them here, see [FALC03] for a short overview of those.

3) Fractal Graph Dimension Indicator
I have already referred to the code written by iliko that implemented a calculation of the fractal dimension. This computation is actually inspired from this article that provides with a method to estimate the Box-counting Dimension (and not directly the Hausdorff Dimension as it is claimed in the article itself)(see equation (6) in the article).
I however noticed two slight mistakes in iliko's code:

- At line 199:
Instead of : for( iteration=0; iteration < g_period_minus_1; iteration++ )
It should be : for( iteration=0; iteration <= g_period_minus_1; iteration++ )

- At line 213:
Instead of : fdi=1.0 +(MathLog( length)+ LOG_2 )/MathLog( 2 * e_period );
It should be : fdi=1.0 +(MathLog( length)+ LOG_2 )/MathLog( 2 * g_period_minus_1)

After correction however, there is not much change in the indicator itself.
In addition I added a calculation of the standard deviation of the fractal dimension so estimated. It is also given in the article as equations (10) and (11); and that may provide information for a more precise entry point for a trade.
The MQ4 file of the FGDI Indicator can be downloaded from this address in the MQL4 Community forum.

Here is a daily EUR/USD chart representing this new indicator along with the FRASMA, and the original fractal dimension by iliko (lower window):

3 comments:

Eliphas Wong said...

Man, FGDI is really a wonderful indicator which tell the market whether is in trend or in wave

Thanks for the code as well.
But can I learn from your experience that how will you set an indicative line to tell whether it is in trend (e.g. FGDI < k, say, K = 1.5) and in wave (e.g. FGDI >= k, say K = 1.5).

Do you have any idea on how to set such an indicator?

Jean-Philippe said...

Hi Eliphas,

FGDI already has the functionality that you mention. It is simply realised by inserting the following lines in the code:

#property indicator_levelcolor LimeGreen
#property indicator_levelwidth 1
#property indicator_levelstyle STYLE_DASH
...
extern double e_random_line =1.5;
...
SetLevelValue( 0, e_random_line );

You can also check the following page on MQL4 that explains another way to set up such a level line: http://docs.mql4.com/customind/SetLevelStyle
And here is a discussion about the different methods: http://forum.mql4.com/7084

Blogger said...

I recommend that you pick the highest ranking Forex broker - AvaTrade.