<?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>Price distribution &#8211; The Financial Hacker</title>
	<atom:link href="https://financial-hacker.com/tag/price-distribution/feed/" rel="self" type="application/rss+xml" />
	<link>https://financial-hacker.com</link>
	<description>A new view on algorithmic trading</description>
	<lastBuildDate>Mon, 20 Dec 2021 10:21:40 +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>Price distribution &#8211; The Financial Hacker</title>
	<link>https://financial-hacker.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>The Mechanical Turk</title>
		<link>https://financial-hacker.com/the-mechanical-turk/</link>
					<comments>https://financial-hacker.com/the-mechanical-turk/#comments</comments>
		
		<dc:creator><![CDATA[jcl]]></dc:creator>
		<pubDate>Mon, 10 Dec 2018 07:17:27 +0000</pubDate>
				<category><![CDATA[Indicators]]></category>
		<category><![CDATA[System Development]]></category>
		<category><![CDATA[Options]]></category>
		<category><![CDATA[Price distribution]]></category>
		<category><![CDATA[Sentiment]]></category>
		<category><![CDATA[SPY]]></category>
		<guid isPermaLink="false">http://www.financial-hacker.com/?p=2974</guid>

					<description><![CDATA[We can see thinking machines taking over more and more human tasks, such as car driving, Go playing, or financial trading. But sometimes it&#8217;s the other way around: humans take over jobs supposedly assigned to thinking machines. Such a job is commonly referred to as a Mechanical Turk in reminiscence to Kempelen&#8217;s famous chess machine &#8230; <a href="https://financial-hacker.com/the-mechanical-turk/" class="more-link">Continue reading<span class="screen-reader-text"> "The Mechanical Turk"</span></a>]]></description>
										<content:encoded><![CDATA[<p>We can see thinking machines taking over more and more human tasks, such as car driving, Go playing, or financial trading. But sometimes it&#8217;s the other way around: humans take over jobs supposedly assigned to thinking machines. Such a job is commonly referred to as a <strong>Mechanical Turk</strong> in reminiscence to Kempelen&#8217;s famous chess machine from 1768. In our case, a Mechanical Turk is an automated trading algorithm based on human intelligence. <span id="more-2974"></span></p>
<p>Theoretically, many trend trading systems would fall in the Turk category since they are based on following the herd. But here we&#8217;re not looking into trader&#8217;s opinions of the current market situation, but into their expectations of the future. There are several methods. The most usual is evaluating the <strong>Commitment Of Traders</strong> report, for which many platforms, also Zorro, provide easy-to-use indicators. But some publications (1) found that using the COT report for predicting the markets produces mixed results at best.</p>
<p>There&#8217;s a more precise way to get the market&#8217;s expectations. It&#8217;s using <a href="https://www.financial-hacker.com/algorithmic-options-trading/">options premiums</a>. If an option expires in 6 weeks, its current premium reflects what option buyers or sellers think about the underlying price in 6 weeks.</p>
<h3>The price probability distribution</h3>
<p>For deriving the expected underlying price at expiration, we have to take all strike prices in consideration. Here&#8217;s the algorithm in short (I haven&#8217;t invented it, a longer description can be found in (2)). Assume SPY is currently trading at $200. For getting the probability that it will rise to between 210 and 220 in 6 weeks, we&#8217;re looking into the 210 call and the 220 call. Suppose they trade at $14 and $10. So we can buy the 210 call and sell the 220 call and pay $4 difference. If at expiration SPY is under 210, both contracts have no worth and we lose the 4 dollars. If it is above 220, our gain is the $10 strike difference minus $4 premium difference, so we win 6 dollars. If it is between 210 and 220, our win or loss is also inbetween, with an average of (-4+6)/2 = 1 dollar.</p>
<p>When options prices are &#8220;fair&#8221;, i.e. solely determined by probabilities where the price will end up at expiration, summing up over all possible outcomes yields zero profit or loss. So</p>
<p><em><strong>-$4×L + $1×M + $6×H = $0</strong></em></p>
<p>where <em><strong>L</strong></em> is the probability for SPY to end up below 210, <em><strong>M</strong></em> is the probability that it will be between 210 and 220, and <em><strong>H</strong></em> is the probability that it will be above 220. Since one of these three alternatives will always happen, the sum of all 3 probabilities must be 1:</p>
<p><em><strong>L + M + H = 1</strong></em></p>
<p>Now let&#8217;s assume that we know <em><strong>L</strong></em> already. Then we have two equations with two unknowns, which are easily solved:</p>
<p><em><strong>5L &#8211; 5H = 1    =&gt;  H = L &#8211; 0.2<br />
10L + 5M = 6    =&gt;  M = 1.2 -2L </strong></em></p>
<p>Assuming <em><strong>L = 50%</strong></em> yields <em><strong>H = 30%</strong></em> and <em><strong>M = 20%</strong></em>.</p>
<p>How do we now get the value <em><strong>L</strong></em>? We simply take the lowest strike offered at the market, and assume that the probability of SPY ending up even below that is zero. So our first <em><strong>L</strong></em> is 0.  We can now use the method above to calculate the <em><strong>M</strong></em> belonging to the interval between the lowest and the second-lowest strike. That <em><strong>M</strong></em> is then added to <em><strong>L</strong></em> since it&#8217;s the probability of SPY ending up at or below the second-lowest strike. We continue that process with the next interval, getting a specific <em><strong>L</strong></em> and <em><strong>M</strong></em> for any interval until we arrived at the highest strike. If the traders have been consistent with their assumptions, the final <em><strong>L</strong></em> &#8211; the sum over all <em><strong>M</strong></em>s &#8211; should be now at or close to 1.</p>
<p>Here&#8217;s a small script that displays the 6-weeks <em><strong>L</strong></em> distribution of SPY:</p>
<pre class="prettyprint">void main() 
{
	StartDate = 20170601;
	LookBack = 0;

	assetList("AssetsIB");
	asset("SPY"); 

// load today's contract chain
	contractUpdate(0,0,CALL|PUT);
	printf("\n%i contracts",NumContracts);
	if(!NumContracts) return;

// get underlying price
	var Price,Current = priceClose(0);
	printf("\nCurrent price %.2f",Current);

// plot CPD histogram	
	contractCPD(45);	// 6 weeks
	int N = 0;
	for(Price = 0.75*Current; Price &lt; 1.25*Current; N++, Price += 0.01*Current)
		plotBar("CPD",N,floor(Price),cpd(Price),BARS|LBL2,RED);
	printf("\nExpected price %.2f",cpdv(50));

// compare with real future price
	set(PEEK);
	N = timeOffset(UTC,-45,0,0);
	printf("\nFuture price %.2f",priceClose(N));
}</pre>
<p>The result is a histogram of expected probabilities, in percent, that the SPY price will be at or below the price at the x-axis six weeks in the future. I&#8217;ve marked the current price with a black bar.</p>
<figure id="attachment_3093" aria-describedby="caption-attachment-3093" style="width: 699px" class="wp-caption alignnone"><a href="https://www.financial-hacker.com/wp-content/uploads/2019/06/cpd.png"><img fetchpriority="high" decoding="async" class="wp-image-3093 size-full" src="https://www.financial-hacker.com/wp-content/uploads/2019/06/cpd.png" alt="" width="699" height="284" srcset="https://financial-hacker.com/wp-content/uploads/2019/06/cpd.png 699w, https://financial-hacker.com/wp-content/uploads/2019/06/cpd-300x122.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /></a><figcaption id="caption-attachment-3093" class="wp-caption-text">SPY 6 weeks price probability distribution at June 1, 2017</figcaption></figure>
<p>The <strong><a href="https://manual.zorro-project.com/contractcpd.htm">contractCPD</a></strong> function generates the distribution with the above described algorithm, <strong>cpd</strong> returns the accumulated probability <em><strong>L</strong></em> (in percent) at a given price, and <strong>cpdv</strong> returns the price at a given <em><strong>L</strong></em>. Therefore, <strong>cpdv(50)</strong> is the median of market expectations. In our case, at June 1 2017, a modest price increase to $245 was expected for mid-July (in fact the price ended up at $245.51, but don&#8217;t get too excited &#8211; often trader&#8217;s expectations fall short by several dollars). We can also see an unusal step at the begin of the histogram: about 10% of traders expected a strong drop to below $200. Maybe Trump twittered something that morning.</p>
<h3>The strategy</h3>
<p>We will now exploit trader&#8217;s expectations for a strategy, and this way check if they have any merit. This is our mechanical Turk:</p>
<pre class="prettyprint">#define Sentiment AssetVar[0]

void run() 
{
	StartDate = 20120102;
	EndDate = 20171231;
	BarPeriod = 1440;

	assetList("AssetsIB");
	asset("SPY");
	MaxLong = MaxShort = 1;

// load today's contract chain
	contractUpdate(0,0,CALL|PUT);
	int N = contractCPD(45);

// increase/decrease market sentiment 
	if(N) {
		var Expect = cpdv(50) - priceClose();
		if(Expect &lt; 0)
			Sentiment = min(Expect,Sentiment+Expect);
		else
			Sentiment = max(Expect,Sentiment+Expect);
	}
	if(Sentiment &gt; 5)
		enterLong();
	else if(Sentiment &lt; -5)
		enterShort();
	
	plot("Sentiment",Sentiment,NEW,RED);
}</pre>
<p>We&#8217;re checking the market expectation every day and add it to a previously defined <strong>Sentiment</strong> asset variable. If the expectation changes sign, so does <strong>Sentiment</strong>. If its amount has accumulated above 5, we buy a long or short position dependent on its sign. This way we&#8217;re only considering the market expectation when it&#8217;s either relatively strong or had the same direction for several days.</p>
<p>The result:</p>
<p><a href="https://www.financial-hacker.com/wp-content/uploads/2019/06/turkresult.png"><img decoding="async" class="alignnone wp-image-3098 size-full" src="https://www.financial-hacker.com/wp-content/uploads/2019/06/turkresult.png" alt="" width="699" height="359" srcset="https://financial-hacker.com/wp-content/uploads/2019/06/turkresult.png 699w, https://financial-hacker.com/wp-content/uploads/2019/06/turkresult-300x154.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 984px) 61vw, (max-width: 1362px) 45vw, 600px" /></a></p>
<p>The system produces about 20% annual return with profit factor 3. The red line in the lower chart is the Sentiment variable &#8211; we can see that it often steadily increases, but sometimes also decreases. Since SPY normally rises, shorting it with this strategy produces less profit than going long, but is still slightly profitable with an 1.16 profit factor.</p>
<h3>Predicting the price in 6 weeks</h3>
<p>What are traders currently thinking of the SPY price in 6 weeks? For this, the first script above needs just be slightly modified so that it does not use historical options data, but connects to IB and downloads the current options chain with all prices:</p>
<pre class="prettyprint">void main() 
{
	StartDate = NOW;
	LookBack = 0;

	assetList("AssetsIB");
	asset("SPY"); 

// load today's contract chain
	contractUpdate(0,0,CALL|PUT);
	printf("\n%i contracts",NumContracts);
	if(!NumContracts) return;

// get underlying price
	var Price,Current = priceClose(0);
	printf("\nCurrent price %.2f",Current);

// plot CPD histogram
	printf("\nWait time approx %i minutes",1+NumContracts/200);
	contractCPD(45);
	int N = 0;
	for(Price = 0.75*Current; Price &lt; 1.25*Current; N++, Price += 0.01*Current)
		plotBar("CPD",N,floor(Price),cpd(Price),BARS|LBL2,RED);
	printf("\nExpected price %.2f",cpdv(50));
}</pre>
<p>This script must be started in Zorro&#8217;s Trade mode with the IB plugin selected. Mind the displayed &#8220;wait time&#8221;. IB sometimes needs up to ten seconds for returning the price of an option contract, so downloading the prices of all 6-weeks contracts can take half an hour or more.</p>
<p>I ran that script today (Dec 11 2018) and the option traders expect the SPY price to rise to $269 in six weeks. So I&#8217;ll check the price by the end of January and post here if they have been right.</p>
<p>I&#8217;ve added the scripts to the 218 repository. You&#8217;ll need Zorro 1.99 or above, and SPY options EOD history for the first 2 scripts. You&#8217;ll really have to buy it this time, the free <a href="https://www.financial-hacker.com/algorithmic-options-trading/">artificial options history</a> won&#8217;t do for market sentiment.</p>
<h3>Conclusions</h3>
<ul>
<li>A Turk can beat a thinking machine.</li>
<li>Option traders tend to underestimate future price changes.</li>
<li>But they are often right in the price direction.</li>
</ul>
<h3>Literature</h3>
<p>(1) <a href="http://www.farmdoc.illinois.edu/nccc134/conf_2007/pdf/confp01-07.pdf">Sanders, Irwin, Merrin: Smart Money? The Forecasting Ability of CFTC Large Traders (2007)</a></p>
<p>(2) <a href="https://www.globalcapital.com/article/k6543wh6f19l/option-prices-imply-a-probability-distribution">Pat Neal, Option Prices Imply a Probability Distribution</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://financial-hacker.com/the-mechanical-turk/feed/</wfw:commentRss>
			<slash:comments>39</slash:comments>
		
		
			</item>
	</channel>
</rss>
