<?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>Mandelbrot &#8211; The Financial Hacker</title>
	<atom:link href="https://financial-hacker.com/tag/mandelbrot/feed/" rel="self" type="application/rss+xml" />
	<link>https://financial-hacker.com</link>
	<description>A new view on algorithmic trading</description>
	<lastBuildDate>Sun, 04 Dec 2022 09:36:36 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://financial-hacker.com/wp-content/uploads/2017/07/cropped-mask-32x32.jpg</url>
	<title>Mandelbrot &#8211; The Financial Hacker</title>
	<link>https://financial-hacker.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>The Market Meanness Index</title>
		<link>https://financial-hacker.com/the-market-meanness-index/</link>
					<comments>https://financial-hacker.com/the-market-meanness-index/#comments</comments>
		
		<dc:creator><![CDATA[jcl]]></dc:creator>
		<pubDate>Mon, 21 Sep 2015 05:00:40 +0000</pubDate>
				<category><![CDATA[Indicators]]></category>
		<category><![CDATA[Ehlers]]></category>
		<category><![CDATA[Mandelbrot]]></category>
		<category><![CDATA[Market Meanness Index]]></category>
		<category><![CDATA[Mean Reversion]]></category>
		<category><![CDATA[Momentum]]></category>
		<guid isPermaLink="false">http://www.financial-hacker.com/?p=250</guid>

					<description><![CDATA[This indicator can improve &#8211; sometimes even double &#8211; the profit expectancy of trend following systems. The Market Meanness Index tells whether the market is currently moving in or out of a &#8220;trending&#8221; regime. It can this way prevent losses by false signals of trend indicators. It is a purely statistical algorithm and not based on volatility, &#8230; <a href="https://financial-hacker.com/the-market-meanness-index/" class="more-link">Continue reading<span class="screen-reader-text"> "The Market Meanness Index"</span></a>]]></description>
										<content:encoded><![CDATA[<p>This indicator can improve &#8211; sometimes even double &#8211; the profit expectancy of trend following systems. The <strong>Market Meanness Index</strong> tells whether the market is currently moving in or out of a &#8220;trending&#8221; regime. It can this way prevent losses by <strong>false signals</strong> of trend indicators. It is a purely statistical algorithm and not based on volatility, trends, or cycles of the price curve.<span id="more-250"></span></p>
<p>There are already several methods for differentiating trending and nontrending market regimes. Some of them are rumored to really work, at least occasionally. John Ehlers proposed the <strong>Hilbert Transform</strong> or a <strong>Cycle / Trend decomposition</strong>, Benoit Mandelbrot the <strong>Hurst Exponent</strong>. In comparison, the source code of the Market Meanness Index is relatively simple:</p>
<pre class="prettyprint">// Market Meanness Index
double MMI(double *Data,int Length)
{
  double m = Median(Data,Length);
  int i, nh=0, nl=0;
  for(i=1; i&lt;Length; i++) {
    if(Data[i] &gt; m &amp;&amp; Data[i] &gt; Data[i-1]) // mind Data order: Data[0] is newest!
      nl++;
    else if(Data[i] &lt; m &amp;&amp; Data[i] &lt; Data[i-1])
      nh++;
  }
  return 100.*(nl+nh)/(Length-1);
}</pre>
<p>This code is in C for Zorro, but meanwhile also versions for MT4, Amibroker, Ninja Trader, and other platforms have been programmed by users. As the name suggests, the indicator measures the meanness of the market &#8211; its tendency to revert to the mean after pretending to start a trend. If that happens too often, all trend following systems will bite the dust.</p>
<h3>The Three-Quarter Rule</h3>
<p>Any series of independent random numbers reverts to the mean &#8211; or more precisely, to their median &#8211; with a probability of 75%. Assume you have a sequence of random, uncorrelated daily data &#8211; for instance, the daily rates of change of a random walk price curve. If Monday&#8217;s data value was above the median, then in 75% of all cases Tuesday&#8217;s data will be lower than Monday&#8217;s. And if Monday was below the median, 75% chance is that Tuesday will be higher. The proof of the 75% rule is relatively simple and won&#8217;t require integral calculus. Consider a data series with median <strong>M</strong>. By definition, half the values are less than <strong>M</strong> and half are greater (for simplicity&#8217;s sake we&#8217;re ignoring the case when a value is exactly <strong>M</strong>). Now combine the values to pairs each consisting of a value <strong>Py</strong> and the following value <strong>Pt</strong>. Thus each pair represents a change from <strong>Py</strong> to <strong>Pt</strong>. We now got a lot of changes that we divide into four sets:</p>
<ol>
<li><strong>(Pt &lt; M, Py &lt; M)</strong></li>
<li><strong><span style="line-height: 1.75;">(Pt &lt; M, Py &gt; M)</span></strong></li>
<li><strong><span style="line-height: 1.75;">(Pt &gt; M, Py &lt; M)</span></strong></li>
<li><strong><span style="line-height: 1.75;">(Pt &gt; M, Py &gt; M) </span></strong></li>
</ol>
<p><span style="line-height: 1.75;">These four sets have obviously the same number of elements &#8211; that is, 1/4 of all <strong>Py-&gt;Pt</strong> changes &#8211; when <strong>Pt</strong> and <strong>Py</strong> are uncorrelated, i.e. completely independent of one another. The value of <strong>M</strong> and the kind of data in the series won&#8217;t matter for this. Now how many data pairs revert to the median? All pairs that fulfill this condition:</span> <strong>(Py &lt; M and Pt &gt; Py) or (Py &gt; M and Pt &lt; Py)</strong> <span style="line-height: 1.75;">The condition in the first bracket is fulfilled for half the data in set 1 (in the other half is <strong>Pt</strong> less than<strong> Py</strong>) and in the whole set 3 (because <strong>Pt</strong> is always higher than <strong>Py</strong> in set 3). So the first bracket is true for </span><span style="line-height: 1.75;">1/2 * 1/4 + 1/4 = 3/8 of all data changes. Likewise,  the second bracket is true in half the set 4 and in the whole set 2, thus also for 3/8 of all data changes. 3/8 + 3/8 yields 6/8, i.e. <strong>75%</strong>. This is the three-quarter rule for random numbers.</span></p>
<p><span style="line-height: 1.75;">The <strong>MMI</strong> function just counts the number of data pairs for which the conditition is met, and returns their percentage. The <strong>Data</strong> series may contain prices or price changes. Prices have always some serial correlation: If EUR / USD today is at 1.20, it will also be tomorrow around 1.20. That it will end up tomorrow at 70 cents or 2 dollars per EUR is rather unlikely. This serial correlation is also true for a price series calculated from random numbers, as not the prices themselves are random, but their changes. Thus, the MMI function should return a smaller percentage, such as 55%, when fed with prices.</span></p>
<p><span style="line-height: 1.75;"> </span><span style="line-height: 1.75;">Unlike prices, price changes have not necessarily serial correlation. A one hundred percent efficient market has no correlation between the price change from yesterday to today and the price change from today to tomorrow. If the MMI function is fed with perfectly random price changes from a perfectly efficient market, it will return a value of about 75%. The less efficient and the more trending the market become</span><span style="line-height: 1.75;">s, the more the MMI decreases. Thus a falling MMI is a indicator of an upcoming trend. A rising MMI hints that the market will get nastier, at least for trend trading systems.</span></p>
<h3>Using the MMI in a trend strategy</h3>
<p>One could assume that MMI predicts the price direction. A high MMI value indicates a high chance of mean reversion, so when prices were moving up in the last time and MMI is high, can we expect a soon price drop? Unfortunately it doesn&#8217;t work this way. The probability of mean reversion is not evenly distributed over the <strong>Length</strong> of the <strong>Data</strong> interval. For the early prices it is high (since the median is computed from future prices), but for the late prices, at the very time when MMI is calculated, it is down to just 50%. Predicting the next price with the MMI would work as well as flipping a coin.</p>
<p>Another mistake would be using the MMI for detecting a cyclic or mean-reverting market regime. True, the MMI will rise in such a situation, but it will also rise when the market becomes more random and more effective. A rising MMI alone is no promise of profit by cycle trading systems.</p>
<p>So the MMI won&#8217;t tell us the next price, and it won&#8217;t tell us if the market is mean reverting or just plain mean, but it can reveal information about the success chance of trend following. For this we&#8217;re making an assumption: <strong>Trend itself is trending</strong>. The market does not jump in and out of trend mode suddenly, but with some inertia. Thus, when we know that MMI is rising, we assume that the market is becoming more efficient, more random, more cyclic, more reversing or whatever, but in any case bad for trend trading. However when MMI is falling, chances are good that the next beginning trend will last longer than normal.</p>
<p>This way the MMI can be an excellent trend filter &#8211; in theory. But we all know that there&#8217;s often a large gap between theory and practice, especially in algorithmic trading. So I&#8217;m now going to test what the Market Meanness Index does to the collection of the <a href="http://www.financial-hacker.com/trend-and-exploiting-it/">900 trend following systems</a> that I&#8217;ve accumulated. For a first quick test, this was the equity curve of one of the systems, <strong>TrendEMA</strong>, without MMI (44% average annual return):</p>
<figure id="attachment_375" aria-describedby="caption-attachment-375" style="width: 1079px" class="wp-caption alignnone"><a href="http://www.financial-hacker.com/wp-content/uploads/2015/09/TrendEMA_EURUSD.png"><img fetchpriority="high" decoding="async" class="wp-image-375 size-full" src="http://www.financial-hacker.com/wp-content/uploads/2015/09/TrendEMA_EURUSD.png" alt="" width="1079" height="301" srcset="https://financial-hacker.com/wp-content/uploads/2015/09/TrendEMA_EURUSD.png 1079w, https://financial-hacker.com/wp-content/uploads/2015/09/TrendEMA_EURUSD-300x84.png 300w, https://financial-hacker.com/wp-content/uploads/2015/09/TrendEMA_EURUSD-1024x286.png 1024w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /></a><figcaption id="caption-attachment-375" class="wp-caption-text">EMA strategy without MMI</figcaption></figure>
<p>This is the same system with MMI (55% average annual return):</p>
<figure id="attachment_377" aria-describedby="caption-attachment-377" style="width: 1079px" class="wp-caption alignnone"><a href="http://www.financial-hacker.com/wp-content/uploads/2015/09/TrendEMA_EURUSD1.png"><img decoding="async" class="wp-image-377 size-full" src="http://www.financial-hacker.com/wp-content/uploads/2015/09/TrendEMA_EURUSD1.png" alt="" width="1079" height="301" srcset="https://financial-hacker.com/wp-content/uploads/2015/09/TrendEMA_EURUSD1.png 1079w, https://financial-hacker.com/wp-content/uploads/2015/09/TrendEMA_EURUSD1-300x84.png 300w, https://financial-hacker.com/wp-content/uploads/2015/09/TrendEMA_EURUSD1-1024x286.png 1024w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /></a><figcaption id="caption-attachment-377" class="wp-caption-text">EMA strategy with MMI</figcaption></figure>
<p>We can see that the profit has doubled, from $250 to $500. The profit factor climbed from 1.2 to 1.8, and the number of trades (green and red lines) is noticeable reduced. On the other hand, the equity curve started with a drawdown that wasn&#8217;t there with the original system. So MMI obviously does not improve all trades. And this was just a randomly selected system. If our assumption about trend trendiness is true, the indicator should have a significant effect also on the other 899 systems.</p>
<p>This experiment will be the topic of the next article, in about a week. As usually I&#8217;ll include all the source code for anyone to reproduce it. Will the MMI miserably fail? Or improve only a few systems, but worsen others? Or will it light up the way to the Holy Grail of trend strategies? Let the market be the judge.</p>
<p><a href="http://www.financial-hacker.com/boosting-systems-by-trade-filtering/">Next: Testing the Market Meanness Index</a></p>
<hr />
<p><strong>Addendum (2022).</strong> I thought my above proof of the 3/4 rule was trivial and no math required, but judging from some comments, it is not so. The rule appears a bit counter-intuitive at first glance. Some comments also confuse a random walk (for example, prices) with a random sequence (for example, price differences). Maybe I have just bad explained it &#8211; in that case, read up the proof anywhere else. I found the two most elaborate proofs of the 3/4 rule, geometrical and analytical, in this book:</p>
<p>(1)  Andrew Pole, Statistical Arbitrage, Wiley 2007</p>
<p>And with no reading and no math: Take a dice, roll it 100 times, write down each result, get the median of all, and then count how often a pair reverted to the median.</p>
<p>Below you can see the MMI applied to a synthetic price curve, first sidewards (black) and then with added trend (blue). For using the MMI with real prices or price differences, read the next article.</p>
<p><img decoding="async" src="http://financial-hacker.com/images/Regime.png " alt="MMI" /></p>
<p>The code:</p>
<pre class="prettyprint">function run()
{
	BarPeriod = 60;
	MaxBars = 1000;
	LookBack = 500;
	asset(""); // dummy asset
	ColorUp = ColorDn = 0; // don't plot a price curve
	set(PLOTNOW);
	
	if(Init) seed(1000);
	int TrendStart = LookBack + 0.4*(MaxBars-LookBack);
	vars Signals = series(1 + 0.5*genNoise());
	if(Bar &gt; TrendStart) 
		Signals[0] += 0.003*(Bar-TrendStart);
	int Color = RED;
	int TimePeriod = 0.5*LookBack;
	if(Bar &lt; TrendStart)
		plot("Sidewards",Signals,MAIN,BLACK);
	else
		plot("Trending",Signals,MAIN,BLUE);
	plot("MMI",MMI(Signals,TimePeriod),NEW|LINE,Color);
}</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://financial-hacker.com/the-market-meanness-index/feed/</wfw:commentRss>
			<slash:comments>139</slash:comments>
		
		
			</item>
	</channel>
</rss>
