<?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>Portfolio Probe</title>
	<atom:link href="http://www.portfolioprobe.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.portfolioprobe.com</link>
	<description>Investment technology for the 21st century</description>
	<lastBuildDate>Mon, 20 May 2013 12:37:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Implied alpha and minimum variance</title>
		<link>http://www.portfolioprobe.com/2013/05/20/implied-alpha-and-minimum-variance/</link>
		<comments>http://www.portfolioprobe.com/2013/05/20/implied-alpha-and-minimum-variance/#comments</comments>
		<pubDate>Mon, 20 May 2013 09:19:51 +0000</pubDate>
		<dc:creator>Pat</dc:creator>
				<category><![CDATA[Quant finance]]></category>
		<category><![CDATA[R language]]></category>
		<category><![CDATA[implied alpha]]></category>
		<category><![CDATA[minimum variance portfolio]]></category>
		<category><![CDATA[reverse optimization]]></category>

		<guid isPermaLink="false">http://www.portfolioprobe.com/?p=10721</guid>
		<description><![CDATA[Under the covers of strange bedfellows. Previously The idea of implied alpha was introduced in &#8220;Implied alpha &#8212; almost wordless&#8221;. In a comment to that post Jeff noticed that the optimal portfolio given for the example is ever so close to the minimum variance portfolio.  That is because there is a problem with the example &#8230; <a href="http://www.portfolioprobe.com/2013/05/20/implied-alpha-and-minimum-variance/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Under the covers of strange bedfellows.</p>
<h2>Previously</h2>
<p>The idea of implied alpha was introduced in <a href="http://www.portfolioprobe.com/2010/09/06/implied-alpha-almost-wordless/">&#8220;Implied alpha &#8212; almost wordless&#8221;</a>.</p>
<p>In a comment to that post Jeff noticed that the optimal portfolio given for the example is ever so close to the minimum variance portfolio.  That is because there is a problem with the example (though it sort of doesn&#8217;t matter).</p>
<p>It uses a risk aversion of 2.5 (which would be a risk aversion of 5 in some people&#8217;s minds).  That is a moderate risk aversion.  Except that the variance and the expected returns are scaled to percent.  This means that the risk aversion should have been divided by 100, but it wasn&#8217;t.  I should have given a risk aversion of 0.025.</p>
<h2>Connection</h2>
<p>This made me wonder about how implied alpha and minimum variance are connected.</p>
<p>Implied alpha tells you what you must have been thinking about the returns of the assets when you formed the portfolio (where &#8220;must&#8221; is subject to a list of assumptions and caveats).</p>
<p>A reason to do minimum variance is because you <strong>don&#8217;t</strong> think you know about returns.  Yet implied alpha goes against your wishes and tells you that you do have a view on returns &#8212; whether you like it or not.</p>
<p>What do the implied alphas of a minimum variance portfolio look like?</p>
<h2>Computation</h2>
<p>If <strong><em>w</em></strong> is the vector of weights for the portfolio and <em>V</em> is the <a href="http://www.portfolioprobe.com/2010/08/25/what-the-hell-is-a-variance-matrix/">variance matrix</a>, then the implied alphas are:</p>
<p style="text-align: center;"><em>cV<strong>w</strong></em></p>
<p>for whatever positive value of <em>c</em> you like.</p>
<p>The assumption is that you are maximizing mean-variance utility, which is:</p>
<p style="text-align: center;"><em>α&#8217;<strong>w</strong> &#8211; c<strong>w</strong>&#8216;V<strong>w</strong></em></p>
<p>where <em>c</em> is the risk aversion (but some people have a division by 2).</p>
<p>In calculus you can find a maximum by taking the derivative of a function and setting it to zero.  If <em>w</em> were a scalar rather than a vector, we would have:</p>
<p style="text-align: center;"><em>aw &#8211; cVw<sup>2</sup></em></p>
<p>Taking the derivative with respect to <em>w</em> and setting it to zero gives us:</p>
<p style="text-align: center;"><em>a &#8211; 2cVw</em> = 0</p>
<p>It turns out that the analogous calculation works for vectors.  (That there is a 2 in this formula is sort of why some people divide by 2 in the utility formula.)</p>
<h2>Sensibility</h2>
<p>How can we make sense of <em>V<strong>w</strong></em>?</p>
<p>First, note that if all the correlations are positive (not so far-fetched) and the portfolio is long-only, then all numbers are positive and hence all the implied alphas will be positive.</p>
<p>Consider the implied alpha for the first asset.  It is the weight of the first asset times the variance of the first asset plus the sum of the covariances of the first asset with all the other assets times the respective weights.</p>
<p>Implied alphas that are relatively big are those that have large weights on large variances and covariances.  That is, they are the riskiest positions.  If a position is risky, we must think that it has good return potential or we&#8217;d scale it back.</p>
<h2>Minimum variance</h2>
<p>The following computations use 250 daily returns ending on 2013 May 17 on 441 large cap US equities to estimate the variance.</p>
<p>Let&#8217;s examine how much a change of variance estimate makes.  We&#8217;ll use a <a href="http://www.portfolioprobe.com/2013/05/15/variance-matrix-differences/">statistical factor model and Ledoit-Wolf shrinkage</a> as competing estimates of the variance matrix.</p>
<p>We get the minimum variance portfolio (where the only constraint is that the portfolio is long-only) for each variance matrix.  The factor model optimization selected 36 assets to have positive weight while the Ledoit-Wolf optimization has 27 assets.  There are 24 assets in common, and the turnover (buys plus sells) to get from one to the other is 50%.</p>
<p>We then compute the implied alpha for each of these portfolios with each variance matrix.  <a href="http://www.portfolioprobe.com/2012/12/24/miles-of-iles/">Boxplots</a> of these implied alphas are in Figure 1.</p>
<p>Figure 1: Boxplots of implied alpha vectors when optimizing and calculating implied alpha using a factor model (fm) or Ledoit-Wolf shrinkage (lw). <a href="http://www.portfolioprobe.com/2013/05/20/implied-alpha-and-minimum-variance/impliedalphanc/" rel="attachment wp-att-10727"><img class="aligncenter size-full wp-image-10727" alt="impliedalphanc" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/impliedalphanc.png" width="512" height="480" /></a>The implied alphas computed with the same variance as was used in the optimization are all essentially equal.  That makes some sense &#8212; one way of getting the minimum variance portfolio is to do a mean-variance optimization where all the expected returns are equal.  In Portfolio Probe terminology the <a href="http://www.portfolioprobe.com/tag/risk-fraction/">risk fractions</a> are all equal.</p>
<p>When we mix the variance matrices, then the implied alphas spread out.  But it isn&#8217;t clear how significant the spread is.  To get a sense of that, three weight vectors were randomly generated.  For each vector 30 random uniforms were generated, scaled to sum to 1, and then random assets from the universe were assigned.</p>
<p>Figure 2: Boxplots of implied alpha from factor model optimization and Ledoit-Wolf calculation (fm-lw) plus implied alphas from three random weight vectors. <a href="http://www.portfolioprobe.com/2013/05/20/implied-alpha-and-minimum-variance/impliedalpharand/" rel="attachment wp-att-10728"><img class="aligncenter size-full wp-image-10728" alt="impliedalpharand" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/impliedalpharand.png" width="512" height="480" /></a>The answer seems to be that the spreads in Figure 1 are not entirely trivial.</p>
<p>But wait, there&#8217;s more.</p>
<p>Figure 1 only looks at the implied alphas for the assets that have positive weights.  We can also get implied alphas for assets that are not in the portfolio.  Figure 3 shows implied alphas (using the same variance as in the optimization) for assets that are in the portfolio (positive weight) and out of the portfolio (zero weight).</p>
<p>Figure 3: Implied alphas for minimum variance portfolios divided by assets in the portfolio and those out of the portfolio. <a href="http://www.portfolioprobe.com/2013/05/20/implied-alpha-and-minimum-variance/impliedalphainout/" rel="attachment wp-att-10735"><img class="aligncenter size-full wp-image-10735" alt="impliedalphainout" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/impliedalphainout.png" width="512" height="480" /></a>It appears that the &#8220;rule&#8221; is that the implied alphas for the assets in the minimum variance portfolio are all equal and the implied alphas for assets outside the portfolio are all larger.  This makes sense in that assets that are risky (have high implied alpha) are excluded.  However, it seems to foil the idea that doing a mean-variance optimization with the implied alphas would lead us back to the portfolio.</p>
<h2>Question</h2>
<p>How does the minimum variance portfolio &#8220;know&#8221; how many of the assets should be included?</p>
<h2>Summary</h2>
<p>Minimum variance portfolios have a strange but quite interesting set of implied alphas.</p>
<h2>Epilogue</h2>
<p style="padding-left: 30px;"><em>Did you ever have to finally decide?</em><br />
<em> And say yes to one and let the other one ride</em></p>
<p>from &#8220;Did you ever have to make up your mind?&#8221; by John Sebastian<br />
<object width="520" height="390" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/Qi1r_DjDr9w?version=3&amp;hl=en_GB" /><param name="allowfullscreen" value="true" /><embed width="520" height="390" type="application/x-shockwave-flash" src="http://www.youtube.com/v/Qi1r_DjDr9w?version=3&amp;hl=en_GB" allowFullScreen="true" allowscriptaccess="always" allowfullscreen="true" /></object></p>
<h2>Appendix R</h2>
<p><a href="http://www.portfolioprobe.com/user-area/some-hints-for-the-r-beginner/">Computations were in R.</a></p>
<h4>create variance estimates</h4>
<p>The variance estimates use functions in the <code>BurStFin</code> package:</p>
<pre>require(BurStFin)
fm1305 &lt;- factor.model.stat(diff(log(tail(
   univclose130518, 251))))
lw1305 &lt;- var.shrink.eqcor(diff(log(tail(
   univclose130518, 251))), tol=1e-5)</pre>
<h4>create price vector</h4>
<p>We want to use the most up-to-date prices &#8212; that is, the last row of the price object:</p>
<pre>price1305 &lt;- drop(tail(as.matrix(univclose130518), 1))
price1305 &lt;- price1305[!is.na(price1305)]</pre>
<p>In this case the object has class <code>xts</code>.  We need to coerce it to matrix otherwise we will end up with dates rather than tickers as the names.</p>
<p>There was also an asset with a missing value &#8212; we need to remove that.</p>
<h4>do optimization</h4>
<p>The optimization uses Portfolio Probe:</p>
<pre>require(PortfolioProbe)

mvlo.fm &lt;- trade.optimizer(price=price1305, 
   variance=fm1305, gross=1e6, long.only=TRUE, 
   utility="minimum variance")</pre>
<h4>compute implied alpha</h4>
<p>A function to compute implied alphas given a trade optimization object is:</p>
<pre>pp.impliedalpha.opt &lt;- function(opt, variance, c=1, 
   prices, all.assets=FALSE)
{
  # placed in the public domain 2013 by Burns Statistics

  # testing status: untested

  if(all.assets) {
    weights &lt;- valuation(opt, prices=prices, 
       all.assets=all.assets)$weight
  } else {
    weights &lt;- valuation(opt)$weight
  }
  wnam &lt;- names(weights)
  drop(variance[wnam, wnam] %*% weights) * c
}</pre>
<p>This is used like:</p>
<pre tabindex="0">mvlo.fmia &lt;- pp.impliedalpha.opt(mvlo.fm, 
   fm1305, 1e5)
mvlo.fmiaaa &lt;- pp.impliedalpha.opt(mvlo.fm, 
   fm1305, 1e5, prices=price1305, all.assets=TRUE)</pre>
<h4>generate random weight vectors</h4>
<pre>rw1 &lt;- runif(30)
rw1 &lt;- rw1 / sum(rw1)
names(rw1) &lt;- sample(names(price1305), 30)</pre>
<h4>plot</h4>
<p>Just the factor model part of Figure 3 (without spice) is:</p>
<pre>boxplot(list("fm - in"=mvlo.fmia, 
   "fm - out"=mvlo.fmiaaa[!(names(mvlo.fmiaaa) 
      %in% names(mvlo.fmia))]))</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.portfolioprobe.com/2013/05/20/implied-alpha-and-minimum-variance/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>US market portrait 2013 week 20</title>
		<link>http://www.portfolioprobe.com/2013/05/18/us-market-portrait-2013-week-20/</link>
		<comments>http://www.portfolioprobe.com/2013/05/18/us-market-portrait-2013-week-20/#comments</comments>
		<pubDate>Sat, 18 May 2013 10:05:02 +0000</pubDate>
		<dc:creator>Pat</dc:creator>
				<category><![CDATA[Market portrait]]></category>
		<category><![CDATA[S&P 500]]></category>

		<guid isPermaLink="false">http://www.portfolioprobe.com/?p=10708</guid>
		<description><![CDATA[US large cap market returns. Fine print The data are from Yahoo Almost all of the S&#38;P 500 stocks are used (as implied by Wikipedia on 2013 January 5 &#8212; see the R commands to scrape the data) The initial post was &#8220;Replacing market indices&#8221; The R code is in marketportrait_funs.R &#8212; you are free &#8230; <a href="http://www.portfolioprobe.com/2013/05/18/us-market-portrait-2013-week-20/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>US large cap market returns.</p>
<p><a href="http://www.portfolioprobe.com/2013/05/18/us-market-portrait-2013-week-20/2013-05-13/" rel="attachment wp-att-10709"><img class="aligncenter size-full wp-image-10709" alt="2013-05-13" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-05-13.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/18/us-market-portrait-2013-week-20/2013-05-14/" rel="attachment wp-att-10710"><img class="aligncenter size-full wp-image-10710" alt="2013-05-14" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-05-14.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/18/us-market-portrait-2013-week-20/2013-05-15/" rel="attachment wp-att-10711"><img class="aligncenter size-full wp-image-10711" alt="2013-05-15" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-05-15.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/18/us-market-portrait-2013-week-20/2013-05-16/" rel="attachment wp-att-10712"><img class="aligncenter size-full wp-image-10712" alt="2013-05-16" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-05-16.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/18/us-market-portrait-2013-week-20/2013-05-17/" rel="attachment wp-att-10713"><img class="aligncenter size-full wp-image-10713" alt="2013-05-17" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-05-17.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/18/us-market-portrait-2013-week-20/wk20-2/" rel="attachment wp-att-10714"><img class="aligncenter size-full wp-image-10714" alt="wk20" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/wk20.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/18/us-market-portrait-2013-week-20/ytdwk20-2/" rel="attachment wp-att-10715"><img class="aligncenter size-full wp-image-10715" alt="ytdwk20" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/ytdwk20.png" width="512" height="480" /></a></p>
<h4></h4>
<h4>Fine print</h4>
<ul>
<li>The data are from <a href="http://finance.yahoo.com/" target="_blank">Yahoo</a></li>
<li>Almost all of the S&amp;P 500 stocks are used (as <a href="http://en.wikipedia.org/wiki/List_of_S%26P_500_companies" target="_blank">implied by Wikipedia</a> on 2013 January 5 &#8212; see <a href="http://www.portfolioprobe.com/2013/01/05/us-market-portrait-2013-week-1/">the R commands to scrape the data</a>)</li>
<li>The initial post was <a href="http://www.portfolioprobe.com/2012/04/02/replacing-market-indices/">&#8220;Replacing market indices&#8221;</a></li>
<li>The R code is in <a href="http://www.portfolioprobe.com/R/blog/marketportrait_funs.R" target="_blank">marketportrait_funs.R</a> &#8212; you are free to use these functions however you like</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.portfolioprobe.com/2013/05/18/us-market-portrait-2013-week-20/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Variance matrix differences</title>
		<link>http://www.portfolioprobe.com/2013/05/15/variance-matrix-differences/</link>
		<comments>http://www.portfolioprobe.com/2013/05/15/variance-matrix-differences/#comments</comments>
		<pubDate>Wed, 15 May 2013 10:21:35 +0000</pubDate>
		<dc:creator>Pat</dc:creator>
				<category><![CDATA[Quant finance]]></category>
		<category><![CDATA[R language]]></category>
		<category><![CDATA[covariance matrix]]></category>
		<category><![CDATA[Ledoit-Wolf shrinkage]]></category>
		<category><![CDATA[risk model]]></category>
		<category><![CDATA[statistical factor model]]></category>
		<category><![CDATA[variance matrix]]></category>

		<guid isPermaLink="false">http://www.portfolioprobe.com/?p=10674</guid>
		<description><![CDATA[Torturing portfolios to give different volatilities between a factor model and Ledoit-Wolf shrinkage. Previously There have been posts on: &#8220;What the hell is a variance matrix?&#8221; factor models Ledoit-Wolf shrinkage Question Two of the several ways to produce an estimate of the variance matrix of asset returns is a statistical factor model and Ledoit-Wolf shrinkage.  &#8230; <a href="http://www.portfolioprobe.com/2013/05/15/variance-matrix-differences/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Torturing portfolios to give different volatilities between a factor model and Ledoit-Wolf shrinkage.</p>
<h2>Previously</h2>
<p>There have been posts on:</p>
<ul>
<li><a href="http://www.portfolioprobe.com/2010/08/25/what-the-hell-is-a-variance-matrix/">&#8220;What the hell is a variance matrix?&#8221;</a></li>
<li><a href="http://www.portfolioprobe.com/tag/factor-model/">factor models</a></li>
<li><a href="http://www.portfolioprobe.com/tag/ledoit-wolf-shrinkage/">Ledoit-Wolf shrinkage</a></li>
</ul>
<h2>Question</h2>
<p>Two of the several ways to produce an estimate of the variance matrix of asset returns is a statistical factor model and Ledoit-Wolf shrinkage.  Can we learn anything about what is happening when the two estimates give different answers for a portfolio?</p>
<p>We can manufacture such portfolios by generating random portfolios that satisfy some constraints including that the portfolio variances have some minimum difference.</p>
<h2>Data</h2>
<p>Daily returns during 2012 were used for 442 large cap US stocks.  The variance estimates were based on these returns.</p>
<p>The portfolios were generated as of the end of 2012.  All of the portfolios that were created had the constraints:</p>
<ul>
<li>long-only</li>
<li>exactly 10 assets in the portfolio</li>
<li>the minimum weight of assets in the portfolio is 0.5%</li>
</ul>
<p>Many of the portfolios had additional constraints on variance.</p>
<p>All sets of random portfolios consist of 1000 portfolios.</p>
<h2>Results</h2>
<p>Figure 1 shows the distribution of the volatility for portfolios that obey only the constraints given above.</p>
<p>Figure 1: Distribution of volatility of random portfolios with 10 assets, are long-only and meet the minimum weight constraint. <a href="http://www.portfolioprobe.com/2013/05/15/variance-matrix-differences/wild10vol/" rel="attachment wp-att-10677"><img class="aligncenter size-full wp-image-10677" alt="wild10vol" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/wild10vol.png" width="512" height="480" /></a>The volatility range of 14% to 15% was selected as an additional constraint.  Figure 2 shows the distribution of the difference in estimated portfolio variances for portfolios generated with the basic constraints plus the volatility range.</p>
<p>Figure 2: Distribution of variance differences for portfolios with Ledoit-Wolf volatility between 14% and 15%. <a href="http://www.portfolioprobe.com/2013/05/15/variance-matrix-differences/vardif-2/" rel="attachment wp-att-10691"><img class="aligncenter size-full wp-image-10691" alt="vardif" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/vardif1.png" width="512" height="480" /></a></p>
<p>We see that in this case the factor model is likely to give a smaller estimate of volatility than Ledoit-Wolf. Which one is more likely to have a larger value depends on the particular constraints.  The picture when the factor model is used to estimate volatility is very similar to Figure 2 &#8212; that is not always the case with other constraints.</p>
<p>The 10 and -10 on the x-axis is a difference of about 0.8% to 0.9% in volatility for the volatility range we are in.  That is the minimum difference that is imposed for the portfolios that have divergent volatility estimates.</p>
<p>Figure 3 shows the fraction of random portfolios with 14% to 15% Ledoit-Wolf volatility that each asset appears in versus the asset volatility.</p>
<p>Figure 3: Fraction of portfolios in which each asset appears versus the asset volatility for portfolios with 14% to 15% Ledoit-Wolf volatility. <a href="http://www.portfolioprobe.com/2013/05/15/variance-matrix-differences/acount/" rel="attachment wp-att-10692"><img class="aligncenter size-full wp-image-10692" alt="acount" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/acount.png" width="512" height="480" /></a></p>
<p>We see that the higher volatility assets are less likely to appear.  This is because the restriction to a volatility of 14% to 15% is below average.  The selection effect is quite mild though.</p>
<p>Figures 4 and 5 compare the volatility estimates for the portfolios that have a difference of variances imposed.</p>
<p>Figure 4: Ledoit-Wolf volatility versus factor model volatility for portfolios with larger Ledoit-Wolf volatility. <a href="http://www.portfolioprobe.com/2013/05/15/variance-matrix-differences/volsbiglw/" rel="attachment wp-att-10696"><img class="aligncenter size-full wp-image-10696" alt="volsbiglw" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/volsbiglw.png" width="512" height="480" /></a></p>
<p>Figure 5: Ledoit-Wolf volatility versus factor model volatility for portfolios with larger factor model volatility. <a href="http://www.portfolioprobe.com/2013/05/15/variance-matrix-differences/volsbigfm/" rel="attachment wp-att-10697"><img class="aligncenter size-full wp-image-10697" alt="volsbigfm" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/volsbigfm.png" width="512" height="480" /></a>In Figure 4 the full range of 14% to 15% volatility is represented with some of the portfolios having a substantially larger difference than the limit imposed.  There is a tendency for portfolios to have a larger volatility (but that is true without the difference constraint).</p>
<p>Figure 5 hints at the difficulty of imposing the difference in this direction.  Only the upper range of volatility is represented, almost all the portfolios are near 15% Ledoit-Wolf volatility, and the difference is never much larger than the minimum imposed.</p>
<p>Figures 6 and 7 show the occurrence of individual stocks in the portfolios with the variance differences imposed.</p>
<p>Figure 6: Fraction of portfolios in which each asset appears versus the asset volatility for portfolios with larger Ledoit-Wolf volatility. <a href="http://www.portfolioprobe.com/2013/05/15/variance-matrix-differences/acountbiglw/" rel="attachment wp-att-10699"><img class="aligncenter size-full wp-image-10699" alt="acountbiglw" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/acountbiglw.png" width="512" height="480" /></a></p>
<p>Figure 7: Fraction of portfolios in which each asset appears versus the asset volatility for portfolios with larger factor model volatility. <a href="http://www.portfolioprobe.com/2013/05/15/variance-matrix-differences/acountbigfm/" rel="attachment wp-att-10700"><img class="aligncenter size-full wp-image-10700" alt="acountbigfm" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/acountbigfm.png" width="512" height="480" /></a>There is quite strong selection for particular assets &#8212; especially for the larger factor model case.</p>
<p>Below we look at the five most popular assets as shown in Figures 6 and 7 in terms of the diferences in the variance matrix estimates.</p>
<h3>Big Ledoit-Wolf popular assets</h3>
<p>Ledoit-Wolf variance (for percent returns):</p>
<pre tabindex="0">        DF   BBY  NFLX  BIG  FDO
DF   10.20  1.73  0.21 0.85 0.52
BBY   1.73 11.37  2.58 1.47 0.57
NFLX  0.21  2.58 18.52 3.31 1.28
BIG   0.85  1.47  3.31 8.92 1.21
FDO   0.52  0.57  1.28 1.21 2.51</pre>
<p>Factor model minus Ledoit-Wolf variance (for percent returns):</p>
<pre tabindex="0">        DF   BBY  NFLX   BIG   FDO
DF   -0.04 -1.15  0.25 -0.74 -0.24
BBY  -1.15 -0.04 -1.09 -0.75 -0.21
NFLX  0.25 -1.09 -0.07 -2.12 -0.75
BIG  -0.74 -0.75 -2.12 -0.04 -0.80
FDO  -0.24 -0.21 -0.75 -0.80 -0.01</pre>
<p>Ledoit-Wolf correlation:</p>
<pre tabindex="0">       DF  BBY NFLX  BIG  FDO
DF   1.00 0.16 0.01 0.09 0.10
BBY  0.16 1.00 0.18 0.15 0.11
NFLX 0.01 0.18 1.00 0.26 0.19
BIG  0.09 0.15 0.26 1.00 0.26
FDO  0.10 0.11 0.19 0.26 1.00</pre>
<p>Factor model minus Ledoit-Wolf correlation:</p>
<pre tabindex="0">        DF   BBY  NFLX   BIG   FDO
DF    0.00 -0.11  0.02 -0.08 -0.05
BBY  -0.11  0.00 -0.07 -0.07 -0.04
NFLX  0.02 -0.07  0.00 -0.16 -0.11
BIG  -0.08 -0.07 -0.16  0.00 -0.17
FDO  -0.05 -0.04 -0.11 -0.17  0.00</pre>
<h3>Big factor model popular assets</h3>
<p>Ledoit-Wolf variance (for percent returns):</p>
<pre tabindex="0">       CA MOLX  EMN  AON  ADI
CA   2.05 0.82 0.54 0.30 0.72
MOLX 0.82 1.99 1.51 0.76 1.10
EMN  0.54 1.51 4.05 1.07 1.30
AON  0.30 0.76 1.07 1.08 0.66
ADI  0.72 1.10 1.30 0.66 1.50</pre>
<p>Factor model minus Ledoit-Wolf variance (for percent returns):</p>
<pre tabindex="0">        CA MOLX   EMN   AON  ADI
CA   -0.01 0.11  0.47  0.20 0.10
MOLX  0.11 0.11  0.21  0.07 0.15
EMN   0.47 0.21 -0.02 -0.03 0.13
AON   0.20 0.07 -0.03  0.00 0.02
ADI   0.10 0.15  0.13  0.02 0.09</pre>
<p>Ledoit-Wolf correlation:</p>
<pre tabindex="0">       CA MOLX  EMN  AON  ADI
CA   1.00 0.41 0.19 0.20 0.41
MOLX 0.41 1.00 0.53 0.52 0.64
EMN  0.19 0.53 1.00 0.51 0.53
AON  0.20 0.52 0.51 1.00 0.52
ADI  0.41 0.64 0.53 0.52 1.00</pre>
<p>Factor model minus Ledoit-Wolf correlation:</p>
<pre tabindex="0">       CA MOLX   EMN   AON  ADI
CA   0.00 0.04  0.16  0.14 0.05
MOLX 0.04 0.00  0.06  0.03 0.05
EMN  0.16 0.06  0.00 -0.01 0.04
AON  0.14 0.03 -0.01  0.00 0.00
ADI  0.05 0.05  0.04  0.00 0.00</pre>
<h2>Questions</h2>
<p>Anyone see any significance in the assets that are selected for in the portfolios with big differences?</p>
<h2>Summary</h2>
<p>The differences in correlation estimates seem to be driving the differences in portfolio volatility estimates.  Given that there are almost 100,000 correlations, the correlation differences that have the largest impact don&#8217;t seem all that big.</p>
<p>Portfolios with 10 assets are more likely to have large discrepancies than larger portfolios.  Hence it seems unlikely that volatility estimates for real portfolios will differ much between the two methods.</p>
<h2>Epilogue</h2>
<p style="padding-left: 30px;"><em>Both of us say there are laws to obey</em><br />
<em> But frankly I don’t like your tone</em></p>
<p>from &#8220;Different Sides&#8221; by Leonard Cohen<br />
<object width="520" height="293" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/kek9t89ri3Y?hl=en_GB&amp;version=3" /><param name="allowfullscreen" value="true" /><embed width="520" height="293" type="application/x-shockwave-flash" src="http://www.youtube.com/v/kek9t89ri3Y?hl=en_GB&amp;version=3" allowFullScreen="true" allowscriptaccess="always" allowfullscreen="true" /></object></p>
<h2>Appendix R</h2>
<p>Computations and plots were <a href="http://www.portfolioprobe.com/user-area/some-hints-for-the-r-beginner/">done in R</a>.</p>
<h4>variance estimation</h4>
<p>The two variance estimates use functions from the <code>BurStFin</code> package.</p>
<pre>require(BurStFin)

fm12 &lt;- factor.model.stat(initret12)
lw12b &lt;- var.shrink.eqcor(initret12, tol=1e-5)</pre>
<p>As <a href="http://www.portfolioprobe.com/2012/05/22/correlations-and-postive-definiteness/">&#8220;Correlations and positive-definiteness&#8221;</a> points out, the default value of the <code>tol</code> argument in the Ledoit-Wolf estimate is over zealous about making sure that there are no portfolios estimated to have very small variance.  (The default will be changed when the package is updated.)</p>
<h4>generate wild portfolios</h4>
<p>The generation and manipulation of the random portfolios depends on the Portfolio Probe package.  1000 portfolios with just the initial three constraints are generated with:</p>
<pre>require(PortfolioProbe)

rp10wild &lt;- random.portfolio(1000, priceEnd12, 
   port.size=c(10,10), gross=1e6, long.only=TRUE, 
   min.weight.thresh=.005)</pre>
<p>There is an additional constraint in the command that the gross value needs to be close to $1 million.  While a specification of the amount of money in the portfolios is mandatory, it has no effect on our results (unless the amount is tiny).</p>
<p>The <code>min.weight.thresh</code> argument is new in Portfolio Probe version 1.06.</p>
<h4>get volatility</h4>
<p>The volatility estimate for each of the portfolios is produced with:</p>
<pre>vol.rp10wild &lt;- sqrt(unlist(randport.eval(rp10wild, 
   keep="var.values",
   additional.args=list(variance=lw12b))) * 252) * 100</pre>
<p>This first produces a vector of the Ledoit-Wolf estimates of the variance of each portfolio, and then transforms that into volatility.</p>
<h4>generate volatility restricted portfolios</h4>
<p>We want to restrict volatility to the range of 14% to 15%.  However, the software thinks in terms of variance rather than volatility.  So we need to transform to the variance scale that we have.  We also need the bounds for the variance constraint to be a two-column matrix:</p>
<pre>vcmat1 &lt;- matrix(c(.14, .15)^2/252, 1, 2)</pre>
<p>Now we use this matrix:</p>
<pre>rp10vtest &lt;- random.portfolio(1000, priceEnd12, 
   port.size=c(10,10), gross=1e6, long.only=TRUE, 
   min.weight.thresh=.005, variance=lw12b, 
   var.constraint=vcmat1)</pre>
<h4>see variance differences</h4>
<p>Now we can see what the difference is between the two variance estimates for each of these portfolios:</p>
<pre>vardif.rp10vtest &lt;- unlist(randport.eval(rp10vtest, 
   keep="var.values",
   additional.args=list(variance=fm12-lw12b, 
      var.constraint=NULL)))</pre>
<p>We change what it thnks the problem is by putting in a different value for the variance matrix and removing the variance constraint.</p>
<p>You may be wondering if the difference of variance matrices really gives us the portfolio variance differences.  The portfolio variance is the double sum over assets of the (<em>i,j</em>) position in the variance matrix times the <em>i</em>-th weight times the <em>j</em>-th weight.  So it is linear in the variance matrix values.</p>
<h4>count assets in portfolios</h4>
<p>The command to count how many times each asset appears in a portfolio is:</p>
<pre>acount.rp10vtest &lt;- table(sapply(rp10vtest, names))</pre>
<h4>generate variance difference portfolios</h4>
<p>Now we know what variance differences are feasible.  We want to impose two different variance constraints:</p>
<ul>
<li>volatility is 14% to 15% (according to one of the variance matrices)</li>
<li>the difference of variances is at least 1e-5</li>
</ul>
<p>To do this we need to provide two variance matrices in the form of a three-dimensional array, where each slice of the third dimension is a variance matrix.  We also need a constraint on each of the variances.  So we need a 2 by 2 matrix: columns are minimum and maximum allowed, rows are for the different variances.</p>
<pre>vcmat2 &lt;- rbind(vcmat1, c(1e5, Inf))</pre>
<p>The random portfolios are generated with:</p>
<pre>rp10biglw &lt;- random.portfolio(1000, priceEnd12, 
   port.size=c(10,10), gross=1e6, long.only=TRUE, 
   min.weight.thresh=.005, 
   variance=threeDarr(fm12, lw12b-fm12), 
   var.constraint=vcmat2)</pre>
<p>The <code>threeDarr</code> function is in the <code>BurStFin</code> package and it stacks matrices into a three-dimensional array.</p>
<h4>difficult constraints</h4>
<p>Figure 2 shows that the variance difference where Ledoit-Wolf is bigger (what the command above is getting) is rare, but not exceedingly rare.  But we might think that the difference where the factor model is bigger could be impossible.  As Figure 5 shows, it isn&#8217;t impossible but barely.</p>
<p>When generating random portfolios, you want it to give up trying if it can&#8217;t find any within a reasonable amount of time &#8212; you don&#8217;t want to have to throw your computer away every time you ask it to do something impossible.  The default settings suggested that the factor-model-bigger problem was impossible.  Changing the settings so it worked harder on each try, and was less frustrated with failure allowed the generation to go ahead.</p>
<p>The time to generate random portfolios heavily depends on the constraints.  To get 1000 portfolios that satisfied the Ledoit-Wolf bigger constraint took 5 seconds.  To get the factor model bigger constraint it took just under 23 hours.</p>
<h4>selected variances and correlations</h4>
<p>To get the most selected names:</p>
<pre>acnam.biglw &lt;- rev(names(tail(sort(acount.rp10biglw),5)))</pre>
<p>Variance matrix selection was:</p>
<pre>round(lw12b[acnam.biglw, acnam.biglw] * 1e4, 2)</pre>
<p>Correlation matrix selection was:</p>
<pre>round(cov2cor(lw12b[acnam.biglw, acnam.biglw]), 2)</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.portfolioprobe.com/2013/05/15/variance-matrix-differences/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>US market portrait 2013 week 19</title>
		<link>http://www.portfolioprobe.com/2013/05/11/us-market-portrait-2013-week-19/</link>
		<comments>http://www.portfolioprobe.com/2013/05/11/us-market-portrait-2013-week-19/#comments</comments>
		<pubDate>Sat, 11 May 2013 08:45:43 +0000</pubDate>
		<dc:creator>Pat</dc:creator>
				<category><![CDATA[Market portrait]]></category>
		<category><![CDATA[S&P 500]]></category>

		<guid isPermaLink="false">http://www.portfolioprobe.com/?p=10661</guid>
		<description><![CDATA[US large cap market returns. Fine print The data are from Yahoo Almost all of the S&#38;P 500 stocks are used (as implied by Wikipedia on 2013 January 5 &#8212; see the R commands to scrape the data) The initial post was &#8220;Replacing market indices&#8221; The R code is in marketportrait_funs.R &#8212; you are free &#8230; <a href="http://www.portfolioprobe.com/2013/05/11/us-market-portrait-2013-week-19/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>US large cap market returns.</p>
<p><a href="http://www.portfolioprobe.com/2013/05/11/us-market-portrait-2013-week-19/2013-05-06/" rel="attachment wp-att-10662"><img class="aligncenter size-full wp-image-10662" alt="2013-05-06" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-05-06.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/11/us-market-portrait-2013-week-19/2013-05-07/" rel="attachment wp-att-10663"><img class="aligncenter size-full wp-image-10663" alt="2013-05-07" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-05-07.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/11/us-market-portrait-2013-week-19/2013-05-08/" rel="attachment wp-att-10664"><img class="aligncenter size-full wp-image-10664" alt="2013-05-08" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-05-08.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/11/us-market-portrait-2013-week-19/2013-05-09/" rel="attachment wp-att-10665"><img class="aligncenter size-full wp-image-10665" alt="2013-05-09" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-05-09.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/11/us-market-portrait-2013-week-19/2013-05-10/" rel="attachment wp-att-10666"><img class="aligncenter size-full wp-image-10666" alt="2013-05-10" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-05-10.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/11/us-market-portrait-2013-week-19/wk19-2/" rel="attachment wp-att-10667"><img class="aligncenter size-full wp-image-10667" alt="wk19" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/wk19.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/11/us-market-portrait-2013-week-19/ytdwk19-2/" rel="attachment wp-att-10668"><img class="aligncenter size-full wp-image-10668" alt="ytdwk19" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/ytdwk19.png" width="512" height="480" /></a></p>
<h4></h4>
<h4>Fine print</h4>
<ul>
<li>The data are from <a href="http://finance.yahoo.com/" target="_blank">Yahoo</a></li>
<li>Almost all of the S&amp;P 500 stocks are used (as <a href="http://en.wikipedia.org/wiki/List_of_S%26P_500_companies" target="_blank">implied by Wikipedia</a> on 2013 January 5 &#8212; see <a href="http://www.portfolioprobe.com/2013/01/05/us-market-portrait-2013-week-1/">the R commands to scrape the data</a>)</li>
<li>The initial post was <a href="http://www.portfolioprobe.com/2012/04/02/replacing-market-indices/">&#8220;Replacing market indices&#8221;</a></li>
<li>The R code is in <a href="http://www.portfolioprobe.com/R/blog/marketportrait_funs.R" target="_blank">marketportrait_funs.R</a> &#8212; you are free to use these functions however you like</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.portfolioprobe.com/2013/05/11/us-market-portrait-2013-week-19/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The half variance approximation for mean returns</title>
		<link>http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/</link>
		<comments>http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/#comments</comments>
		<pubDate>Mon, 06 May 2013 08:00:40 +0000</pubDate>
		<dc:creator>Pat</dc:creator>
				<category><![CDATA[Quant finance]]></category>
		<category><![CDATA[R language]]></category>
		<category><![CDATA[arithmetic return]]></category>
		<category><![CDATA[arithmetic return vs geometric return]]></category>
		<category><![CDATA[geometric return vs arithmetic return]]></category>

		<guid isPermaLink="false">http://www.portfolioprobe.com/?p=10615</guid>
		<description><![CDATA[What&#8217;s that thing about arithmetic and geometric returns and the variance? Previously An introduction to the difference between simple and log returns is: A tale of two returns Issue Suppose you are predicting the mean annual return of an asset for some number of years.  To simplify the discussion, let&#8217;s buy into the fantasy that &#8230; <a href="http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>What&#8217;s that thing about arithmetic and geometric returns and the variance?</p>
<h2>Previously</h2>
<p>An introduction to the difference between simple and log returns is:</p>
<ul>
<li><a href="http://www.portfolioprobe.com/2010/10/04/a-tale-of-two-returns/">A tale of two returns</a></li>
</ul>
<h2>Issue</h2>
<p>Suppose you are predicting the mean annual return of an asset for some number of years.  To simplify the discussion, let&#8217;s buy into the fantasy that the observed returns are a good (unbiased) estimate of future returns.  If you take the mean of the historical simple returns, you will be over-estimating the mean return &#8212; call this &#8220;Amean&#8221; (as in arithmetic mean).  Better is to take the mean of the log returns and then transform that mean into a simple return &#8212; call this &#8220;Gmean&#8221;.</p>
<p>The approximation of Gmean using only simple returns is Amean minus half the variance of the historical simple returns.</p>
<p>Perhaps others will disagree but I don&#8217;t think the issue is computational &#8212; if someone can compute a variance, they should just about be able to take a logarithm.  I think the issue is of how we think rather than how we compute.  It is easy to get optimistic.</p>
<p><a href="http://www.cdiadvisors.com/papers/CDIArithmeticVsGeometric.pdf" target="_blank">&#8220;On the relationship between Arithmetic and Geometric Returns&#8221;</a> explains where the approximation comes from, and discusses three more as well.</p>
<h2>Pictures</h2>
<p>We&#8217;ll investigate a world in which the true annual return each year is 5% and the volatility is 20%.</p>
<p>What varies is the distribution of returns and the length of the history available.</p>
<p>The other constant is that we always look at 1000 realizations of a simulation.</p>
<h4>normal decade</h4>
<p>Figures 1 through 3 show the simulations where the log returns have a normal distribution and we have a decade of data (that is, 10 annual returns).</p>
<p>Figure 1: Amean versus Gmean for a decade with the normal distribution. <a href="http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/normdecadegam/" rel="attachment wp-att-10617"><img class="aligncenter size-full wp-image-10617" alt="normdecadegam" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/normdecadegam.png" width="512" height="480" /></a></p>
<p>Figure 2: Amean minus Gmean versus Gmean for a decade with the normal distribution. <a href="http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/normdecaderam/" rel="attachment wp-att-10618"><img class="aligncenter size-full wp-image-10618" alt="normdecaderam" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/normdecaderam.png" width="512" height="480" /></a>The bias in Amean relative to Gmean is always non-trivial in this case and often quite significant.</p>
<p>Figure 3: The approximation minus Gmean versus Gmean for a decade with the normal distribution. <a href="http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/normdecaderap/" rel="attachment wp-att-10619"><img class="aligncenter size-full wp-image-10619" alt="normdecaderap" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/normdecaderap.png" width="512" height="480" /></a>The approximation is pretty much unbiased, but it can be substantially far from Gmean.</p>
<p>Remember that the true answer in all cases is 5 &#8212; it is just that Gmean is pretty much our best guide if we don&#8217;t get to know the secrets of the universe.</p>
<h4>t6 decade</h4>
<p>Figures 4 through 6 show the simulations from a decade of data where the distribution of daily returns is the t with 6 degrees of freedom.</p>
<p>Figure 4: Amean versus Gmean for a decade with the t6 distribution. <a href="http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/t6decadegam/" rel="attachment wp-att-10620"><img class="aligncenter size-full wp-image-10620" alt="t6decadegam" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/t6decadegam.png" width="512" height="480" /></a></p>
<p>Figure 5: Amean minus Gmean versus Gmean for a decade with the t6 distribution. <a href="http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/t6decaderam/" rel="attachment wp-att-10621"><img class="aligncenter size-full wp-image-10621" alt="t6decaderam" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/t6decaderam.png" width="512" height="480" /></a></p>
<p>Figure 6: The approximation minus Gmean versus Gmean for a decade with the t6 distribution. <a href="http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/t6decaderap/" rel="attachment wp-att-10622"><img class="aligncenter size-full wp-image-10622" alt="t6decaderap" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/t6decaderap.png" width="512" height="480" /></a>There are some differences between the normal and t6 cases, but they are fairly subtle.  A more realistic change in return distribution would be to put in <a href="http://www.portfolioprobe.com/tag/volatility-clustering/">volatility clustering</a>.  That probably would give significantly different results from the normal case.</p>
<h4>normal century</h4>
<p>Figures 7 through 9 show the simulations assuming a century of data and normally distributed returns.</p>
<p>Figure 7: Amean versus Gmean for a century with the normal distribution. <a href="http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/normcenturygam/" rel="attachment wp-att-10623"><img class="aligncenter size-full wp-image-10623" alt="normcenturygam" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/normcenturygam.png" width="512" height="480" /></a></p>
<p>Figure 8: Amean minus Gmean versus Gmean for a century with the normal distribution. <a href="http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/normcenturyram/" rel="attachment wp-att-10624"><img class="aligncenter size-full wp-image-10624" alt="normcenturyram" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/normcenturyram.png" width="512" height="480" /></a></p>
<p>Figure 9: The approximation minus Gmean versus Gmean for a century with the normal distribution. <a href="http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/normcenturyrap/" rel="attachment wp-att-10625"><img class="aligncenter size-full wp-image-10625" alt="normcenturyrap" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/normcenturyrap.png" width="512" height="480" /></a>Even though the true mean return is 5% there are a few centuries out of 1000 that experienced a negative return.  Awesome.</p>
<h4>normal millennium</h4>
<p>Figures 10 through 12 show simulations assuming a thousand years of data and normally distributed returns.</p>
<p>Figure 10: Amean versus Gmean for a decade with the millennium distribution. <a href="http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/normmillenniumgam/" rel="attachment wp-att-10626"><img class="aligncenter size-full wp-image-10626" alt="normmillenniumgam" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/normmillenniumgam.png" width="512" height="480" /></a></p>
<p>Figure 11: Amean minus Gmean versus Gmean for a millennium with the normal distribution. <a href="http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/normmillenniumram/" rel="attachment wp-att-10627"><img class="aligncenter size-full wp-image-10627" alt="normmillenniumram" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/normmillenniumram.png" width="512" height="480" /></a></p>
<p>Figure 12: The approximation minus Gmean versus Gmean for a millennium with the normal distribution. <a href="http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/normmillenniumrap/" rel="attachment wp-att-10628"><img class="aligncenter size-full wp-image-10628" alt="normmillenniumrap" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/normmillenniumrap.png" width="512" height="480" /></a></p>
<h2>Summary</h2>
<p>Be careful when averaging returns.</p>
<p>We have no claim to know what&#8217;s right.  That is, we don&#8217;t have a chance in hell of knowing the true expected return of equities.</p>
<h2>Epilogue</h2>
<p style="padding-left: 30px;"><em>Oh my fair North Star</em><br />
<em> I have held to you dearly</em><br />
<em> I have asked you to steer me</em></p>
<p>from &#8220;Mercy of the Fallen&#8221; by Dar Williams</p>
<p><object width="520" height="390" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/trfowtB5Hmk?hl=en_GB&amp;version=3" /><param name="allowfullscreen" value="true" /><embed width="520" height="390" type="application/x-shockwave-flash" src="http://www.youtube.com/v/trfowtB5Hmk?hl=en_GB&amp;version=3" allowFullScreen="true" allowscriptaccess="always" allowfullscreen="true" /></object></p>
<h2>Appendix R</h2>
<p>The simulations were <a href="http://www.portfolioprobe.com/user-area/some-hints-for-the-r-beginner/">performed in R</a>.</p>
<h4>simulation function</h4>
<p>The function that produced the simulations was:</p>
<pre>pp.simulret &lt;- function(years, meanann, vol, 
   distribution="normal", trials=1000, ...)
{
  # simulate years of returns based on daily returns

  # placed in the public domain 2013 by Burns Statistics

  # testing status: untested

  dots &lt;- list(...)
  if(length(dots)) {
    df &lt;- dots$df
  }

  ans &lt;- array(NA, c(trials, 4), list(NULL, 
            c("Amean", "Gmean", "Var", "approx")))
  for(i in 1:trials) {
    switch(distribution, 
           normal={
             logret &lt;- rnorm(years * 252, meanann/25200,
                             vol/100/sqrt(252))
           },
           t={
             logret &lt;- rt(years * 252, df=df) * 
               sqrt((df-2)/df) * vol/100/sqrt(252) +
               meanann/25200
           })
    logret
    annlret &lt;- colSums(matrix(logret, nrow=252))
    annsret &lt;- (exp(annlret) - 1)
    ans[i,-4] &lt;- c(mean(annsret), mean(annlret), 
        var(annsret))
  }
  ans[,4] &lt;- ans[,1] - ans[,3]/2
  ans[, -3] &lt;- ans[,-3] * 100
  ans
}</pre>
<p>It is used like:</p>
<pre>sim.norm.decade20 &lt;- pp.simulret(10, 5, 20, 
   dist="normal")</pre>
<h4>plot function</h4>
<p>The function to do the plots was:</p>
<pre>pp.simulretplot &lt;- function(x, type, ...)
{
  # plots for simulated returns

  # placed in the public domain 2013 by Burns Statistics

  # testing status: untested
  switch(type,
         gam={
           plot(x[, "Gmean"], x[, "Amean"], 
              col="steelblue", xlab="Gmean", 
              ylab="Amean", ...)
           abline(0, 1, col="gold")
         },
         ram={
           plot(x[, "Gmean"], x[, "Amean"]-x[, "Gmean"],
              col="steelblue", xlab="Gmean", 
              ylab="Amean - Gmean", ...)
           abline(h=0, col="gold")
         },
         gap={
           plot(x[, "Gmean"], x[, "approx"], 
              col="steelblue", xlab="Gmean", 
              ylab="Approximation", ...)
           abline(0, 1, col="gold")
         },
         rap={
           plot(x[, "Gmean"], x[, "approx"]-x[, "Gmean"],
              col="steelblue", xlab="Gmean", 
              ylab="Approximation - Gmean", ...)
           abline(h=0, col="gold")
         })
}</pre>
<p>Figures 1, 2 and 3 were produced with:</p>
<pre>pp.simulretplot(sim.norm.decade20, 'gam')
pp.simulretplot(sim.norm.decade20, 'ram')
pp.simulretplot(sim.norm.decade20, 'rap')</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.portfolioprobe.com/2013/05/06/the-half-variance-approximation-for-mean-returns/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>US market portrait 2013 week 18</title>
		<link>http://www.portfolioprobe.com/2013/05/04/us-market-portrait-2013-week-18/</link>
		<comments>http://www.portfolioprobe.com/2013/05/04/us-market-portrait-2013-week-18/#comments</comments>
		<pubDate>Sat, 04 May 2013 16:12:57 +0000</pubDate>
		<dc:creator>Pat</dc:creator>
				<category><![CDATA[Market portrait]]></category>
		<category><![CDATA[S&P 500]]></category>

		<guid isPermaLink="false">http://www.portfolioprobe.com/?p=10602</guid>
		<description><![CDATA[US large cap market returns. Fine print The data are from Yahoo Almost all of the S&#38;P 500 stocks are used (as implied by Wikipedia on 2013 January 5 &#8212; see the R commands to scrape the data) The initial post was &#8220;Replacing market indices&#8221; The R code is in marketportrait_funs.R &#8212; you are free &#8230; <a href="http://www.portfolioprobe.com/2013/05/04/us-market-portrait-2013-week-18/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>US large cap market returns.</p>
<p><a href="http://www.portfolioprobe.com/2013/05/04/us-market-portrait-2013-week-18/2013-04-29/" rel="attachment wp-att-10603"><img class="aligncenter size-full wp-image-10603" alt="2013-04-29" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-04-29.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/04/us-market-portrait-2013-week-18/2013-04-30/" rel="attachment wp-att-10604"><img class="aligncenter size-full wp-image-10604" alt="2013-04-30" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-04-30.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/04/us-market-portrait-2013-week-18/2013-05-01/" rel="attachment wp-att-10605"><img class="aligncenter size-full wp-image-10605" alt="2013-05-01" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-05-01.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/04/us-market-portrait-2013-week-18/2013-05-02/" rel="attachment wp-att-10606"><img class="aligncenter size-full wp-image-10606" alt="2013-05-02" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-05-02.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/04/us-market-portrait-2013-week-18/2013-05-03/" rel="attachment wp-att-10607"><img class="aligncenter size-full wp-image-10607" alt="2013-05-03" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/2013-05-03.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/04/us-market-portrait-2013-week-18/wk18-2/" rel="attachment wp-att-10608"><img class="aligncenter size-full wp-image-10608" alt="wk18" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/wk18.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/05/04/us-market-portrait-2013-week-18/ytdwk18-3/" rel="attachment wp-att-10609"><img class="aligncenter size-full wp-image-10609" alt="ytdwk18" src="http://www.portfolioprobe.com/wp-content/uploads/2013/05/ytdwk18.png" width="512" height="480" /></a></p>
<h4></h4>
<h4>Fine print</h4>
<ul>
<li>The data are from <a href="http://finance.yahoo.com/" target="_blank">Yahoo</a></li>
<li>Almost all of the S&amp;P 500 stocks are used (as <a href="http://en.wikipedia.org/wiki/List_of_S%26P_500_companies" target="_blank">implied by Wikipedia</a> on 2013 January 5 &#8212; see <a href="http://www.portfolioprobe.com/2013/01/05/us-market-portrait-2013-week-1/">the R commands to scrape the data</a>)</li>
<li>The initial post was <a href="http://www.portfolioprobe.com/2012/04/02/replacing-market-indices/">&#8220;Replacing market indices&#8221;</a></li>
<li>The R code is in <a href="http://www.portfolioprobe.com/R/blog/marketportrait_funs.R" target="_blank">marketportrait_funs.R</a> &#8212; you are free to use these functions however you like</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.portfolioprobe.com/2013/05/04/us-market-portrait-2013-week-18/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Popular posts 2013 April</title>
		<link>http://www.portfolioprobe.com/2013/05/01/popular-posts-2013-april/</link>
		<comments>http://www.portfolioprobe.com/2013/05/01/popular-posts-2013-april/#comments</comments>
		<pubDate>Wed, 01 May 2013 09:43:03 +0000</pubDate>
		<dc:creator>Pat</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[most popular posts]]></category>

		<guid isPermaLink="false">http://www.portfolioprobe.com/?p=10541</guid>
		<description><![CDATA[Most popular posts in 2013 April A practical introduction to garch modeling (posted in 2012) A tale of two returns (posted in 2010) Stock-picking opportunity and the ratio of variabilities A pictorial history of US large cap correlation The top 7 portfolio optimization problems (posted in 2012) garch and the distribution of returns Alternative equity &#8230; <a href="http://www.portfolioprobe.com/2013/05/01/popular-posts-2013-april/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<h2>Most popular posts in 2013 April</h2>
<ol>
<li><a href="http://www.portfolioprobe.com/2012/07/06/a-practical-introduction-to-garch-modeling/">A practical introduction to garch modeling</a> (posted in 2012)</li>
<li><a href="http://www.portfolioprobe.com/2010/10/04/a-tale-of-two-returns/">A tale of two returns</a> (posted in 2010)</li>
<li><a href="http://www.portfolioprobe.com/2013/04/15/stock-picking-opportunity-and-the-ratio-of-variabilities/">Stock-picking opportunity and the ratio of variabilities</a></li>
<li><a href="http://www.portfolioprobe.com/2013/04/01/a-pictorial-history-of-us-large-cap-correlation/">A pictorial history of US large cap correlation</a></li>
<li><a href="http://www.portfolioprobe.com/2012/01/05/the-top-7-portfolio-optimization-problems/">The top 7 portfolio optimization problems</a> (posted in 2012)</li>
<li><a href="http://www.portfolioprobe.com/2013/04/22/garch-and-the-distribution-of-returns/">garch and the distribution of returns</a></li>
<li><a href="http://www.portfolioprobe.com/2013/04/05/alternative-equity-indices-and-random-portfolios/">Alternative equity indices and random portfolios</a></li>
<li><a href="http://www.portfolioprobe.com/2013/03/05/predicted-correlations-and-portfolio-optimization/">Predicted correlations and portfolio optimization</a></li>
<li><a href="http://www.portfolioprobe.com/2012/01/23/the-distribution-of-financial-returns-made-simple/">The distribution of financial returns made simple</a> (posted in 2012)</li>
<li><a href="http://www.portfolioprobe.com/2013/04/29/slouching-towards-simulating-investment-skill/">Slouching towards simulating investment skill</a></li>
<li><a href="http://www.portfolioprobe.com/2011/01/12/the-number-1-novice-quant-mistake/">The number 1 novice quant mistake</a> (posted in 2011)</li>
</ol>
<h2>Most popular posts in 2013</h2>
<p>As of 2013 April 30.</p>
<ol>
<li><a href="http://www.portfolioprobe.com/2012/07/06/a-practical-introduction-to-garch-modeling/">A practical introduction to garch modeling</a> (posted in 2012)</li>
<li><a href="http://www.portfolioprobe.com/2010/10/04/a-tale-of-two-returns/">A tale of two returns</a> (posted in 2010)</li>
<li><a href="http://www.portfolioprobe.com/2012/01/05/the-top-7-portfolio-optimization-problems/">The top 7 portfolio optimization problems</a> (posted in 2012)</li>
<li><a href="http://www.portfolioprobe.com/2013/03/05/predicted-correlations-and-portfolio-optimization/">Predicted correlations and portfolio optimization</a></li>
<li><a href="&quot;http://www.portfolioprobe.com/2011/11/08/the-mystery-of-volatility-estimates-from-daily-versus-monthly-returns/">The mystery of volatility estimates from daily versus monthly returns</a> (posted in 2011)</li>
<li><a href="http://www.portfolioprobe.com/2011/01/12/the-number-1-novice-quant-mistake/">The number 1 novice quant mistake</a> (posted in 2011)</li>
<li><a href="http://www.portfolioprobe.com/2012/01/23/the-distribution-of-financial-returns-made-simple/">The distribution of financial returns made simple</a> (posted in 2012)</li>
<li><a href="http://www.portfolioprobe.com/2013/02/18/simple-tests-of-predicted-returns/">Simple tests of predicted returns</a></li>
<li><a href="http://www.portfolioprobe.com/2013/01/07/market-predictions-for-year-2013/">Market predictions for year 2013</a></li>
<li><a href="http://www.portfolioprobe.com/2012/07/23/a-comparison-of-some-heuristic-optimization-methods/">A comparison of some heuristic optimization methods</a></li>
<li><a href="http://www.portfolioprobe.com/2013/01/21/clustering-and-sector-strength/">Clustering and sector strength</a></li>
<li><a href="http://www.portfolioprobe.com/2013/01/28/the-components-garch-model-in-the-rugarch-package/">The components garch model in the rugarch package</a></li>
<li><a href="http://www.portfolioprobe.com/2013/02/11/variability-of-predicted-portfolio-volatility/">Variability of predicted portfolio volatility</a></li>
</ol>
<h2>See also</h2>
<ul>
<li><a href="http://www.portfolioprobe.com/2012/12/31/blog-year-2012-in-review/">Blog year 2012 in review</a></li>
<li><a href="http://www.portfolioprobe.com/2011/12/28/blog-year-2011-in-review/">Blog year 2011 in review</a></li>
<li><a href="http://www.portfolioprobe.com/2010/12/30/blog-year-2010-in-review/">Blog year 2010 in review</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.portfolioprobe.com/2013/05/01/popular-posts-2013-april/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slouching towards simulating investment skill</title>
		<link>http://www.portfolioprobe.com/2013/04/29/slouching-towards-simulating-investment-skill/</link>
		<comments>http://www.portfolioprobe.com/2013/04/29/slouching-towards-simulating-investment-skill/#comments</comments>
		<pubDate>Mon, 29 Apr 2013 08:06:39 +0000</pubDate>
		<dc:creator>Pat</dc:creator>
				<category><![CDATA[Quant finance]]></category>
		<category><![CDATA[R language]]></category>
		<category><![CDATA[alpha generation]]></category>
		<category><![CDATA[simulate investment skill]]></category>

		<guid isPermaLink="false">http://www.portfolioprobe.com/?p=10496</guid>
		<description><![CDATA[When investment skill is simulated, it is often presented as if it is obvious how to do it.  Maybe I&#8217;m wrong, but I don&#8217;t think it&#8217;s obvious. Previously In &#8220;Simple tests of predicted returns&#8221; we saw that prediction quality need not look like what you would find in a textbook.  For example, there was a &#8230; <a href="http://www.portfolioprobe.com/2013/04/29/slouching-towards-simulating-investment-skill/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>When investment skill is simulated, it is often presented as if it is obvious how to do it.  Maybe I&#8217;m wrong, but I don&#8217;t think it&#8217;s obvious.</p>
<h2>Previously</h2>
<p>In <a href="http://www.portfolioprobe.com/2013/02/18/simple-tests-of-predicted-returns/">&#8220;Simple tests of predicted returns&#8221;</a> we saw that prediction quality need not look like what you would find in a textbook.  For example, there was a case where there was no predictive power on the low values, but good prediction for high values.</p>
<h2>Data</h2>
<p>443 large cap US equities are used.  The variance matrix is estimated using the daily returns during 2011 (via a <a href="http://www.portfolioprobe.com/tag/ledoit-wolf-shrinkage/">Ledoit-Wolf shrinkage model</a>).</p>
<p>Both long-only and long-short portfolios are created.  The constraints for the long-only portfolios are:</p>
<ul>
<li>no more than 60 names in the portfolio</li>
<li>predicted volatility is no more than 20%</li>
</ul>
<p>The constraints for the long-short portfolios are:</p>
<ul>
<li>dollar neutral (net value of zero)</li>
<li>no more than 60 names in the portfolio</li>
<li>predicted volatility is no more than 10%</li>
</ul>
<p>&nbsp;</p>
<h2>Simulating</h2>
<p>There are unlimited ways of simulating skill.  Here we take a brief look at two.</p>
<h3>Wilma</h3>
<p>Wilma gets the correlation right (or wrong) separately for the halves of the data above and below the median of the realized values.  Three cases were created:</p>
<ul>
<li>the correlation is 10% for both halves (blue)</li>
<li>the correlation is zero for the low half and 10% for the high half (gold)</li>
<li>the correlation is -10% for the low half and 10% for the high half (black)</li>
</ul>
<p>The colors indicate how the cases appear in the figures.  Figures 1 and 2 show the distributions of random portfolios generated using the three predictions plus a set that uses no predictions (colored green).</p>
<p>The sets of random portfolios use the predictions by having an extra constraint that the predicted return must be at least 90% of the way to the maximum predicted return.  In practice a fund manager is constrained by turnover considerations from moving to the best portfolio &#8212; the random portfolios are imitating this.</p>
<p>Figure 1: Distributions of 2012 Q1 returns for long-only portfolios: no prediction (green), Wilma 10,10 (blue), 0,10 (gold), -10,10 (black). <a href="http://www.portfolioprobe.com/2013/04/29/slouching-towards-simulating-investment-skill/wilmaloall/" rel="attachment wp-att-10501"><img class="aligncenter size-full wp-image-10501" alt="wilmaloall" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/wilmaloall.png" width="512" height="480" /></a></p>
<p>Figure 2: Distributions of 2012 Q1 returns for dollar-neutral portfolios: no prediction (green), Wilma 10,10 (blue), 0,10 (gold), -10,10 (black). <a href="http://www.portfolioprobe.com/2013/04/29/slouching-towards-simulating-investment-skill/wilmalsall/" rel="attachment wp-att-10502"><img class="aligncenter size-full wp-image-10502" alt="wilmalsall" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/wilmalsall.png" width="512" height="480" /></a>Let&#8217;s focus on the blue distribution in Figures 1 and 2.  This is using one specific vector of predictions.  The variability is due to using that one prediction differently.  Think of it as Wilma having lots of different portfolios and using this one prediction vector to rebalance each of them.</p>
<p>But different prediction vectors with the same correlations may be more or less effective.  In fact, they can have significantly different correlations over the whole universe, as Figure 3 shows.</p>
<p>Figure 3: Correlation between realized and Wilma predictions where both halves have correlation 10%, with the correlation of the prediction used (blue). <a href="http://www.portfolioprobe.com/2013/04/29/slouching-towards-simulating-investment-skill/wilmacor/" rel="attachment wp-att-10503"><img class="aligncenter size-full wp-image-10503" alt="wilmacor" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/wilmacor.png" width="512" height="480" /></a>The overall correlation is generally higher than 10% because the relationship is seen over a wider range.  But the overall correlation can be less than 10% as well by the lines having different slopes in the two halves.</p>
<h3>Barney</h3>
<p>Barney&#8217;s skill is different than Wilma&#8217;s.  Barney knows that a certain fraction of predictions and realized values match (or don&#8217;t match) in terms of being above or below their respective medians.  (This description is not quite accurate, and is probably hard to follow anyway &#8212; see the code in Appendix R  below for the real story.)</p>
<p>Again three predictions are used:</p>
<ul>
<li>20% in each half are quaranteed to match (blue)</li>
<li>20% guaranteed to match in the high half (gold)</li>
<li>20% guaranteed not to match in the low half and 20% guaranteed to match in the high half (black)</li>
</ul>
<p>Figures 4 and 5 show the returns of the random portfolios  using the same scheme of constraining the expected returns.</p>
<p>Figure 4: Distributions of 2012 Q1 returns for long-only portfolios: no prediction (green), Barney 20,20 (blue), 0,20 (gold), -20,20 (black). <a href="http://www.portfolioprobe.com/2013/04/29/slouching-towards-simulating-investment-skill/barneyloall-2/" rel="attachment wp-att-10512"><img class="aligncenter size-full wp-image-10512" alt="barneyloall" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/barneyloall1.png" width="512" height="480" /></a></p>
<p>Figure 5: Distributions of 2012 Q1 returns for dollar neutral portfolios: no prediction (green), Barney 20,20 (blue), 0,20 (gold), -20,20 (black). <a href="http://www.portfolioprobe.com/2013/04/29/slouching-towards-simulating-investment-skill/barneylsall-2/" rel="attachment wp-att-10513"><img class="aligncenter size-full wp-image-10513" alt="barneylsall" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/barneylsall1.png" width="512" height="480" /></a></p>
<p>Figure 5 is a mess in the sense that the differences between the distributions are subtle.  This is probably realistic.  The scheme from here would be to try to condition out more noise so that the effect of the prediction quality is more visible.</p>
<p>Figure 4 is a mess in the sense that it violates our expectations.  The supposedly best prediction does worst, and the supposedly mediocre prediction does very well.  One possibility is that there is a bug in the computations.  That shouldn&#8217;t be entirely ruled out, but there is a reasonable explanation for what we are seeing.</p>
<p>Figures 6 and 7 show the two predictions in question versus the realized returns.</p>
<p>Figure 6: Realized returns versus Barney predictions with 20% guarantee on the top half. <a href="http://www.portfolioprobe.com/2013/04/29/slouching-towards-simulating-investment-skill/barneyzeroscat-2/" rel="attachment wp-att-10515"><img class="aligncenter size-full wp-image-10515" alt="barneyzeroscat" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/barneyzeroscat1.png" width="512" height="480" /></a></p>
<p>Figure 7: Realized returns versus Barney predictions with 20% guarantee on both halves. <a href="http://www.portfolioprobe.com/2013/04/29/slouching-towards-simulating-investment-skill/barney2020scat/" rel="attachment wp-att-10516"><img class="aligncenter size-full wp-image-10516" alt="barney2020scat" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/barney2020scat.png" width="512" height="480" /></a>Note in particular the highlighted points in Figures 6 and 7.  The most positive predictions are going to be the most important in long-only portfolios.  The center does not hold.  The 0-20 prediction has relatively good predictions in the tail, while the 20-20 has rather poor predictions in the tail.</p>
<p>Notice that a bound on position size is not one of the constraints.  The two most extreme points in Figures 6 and 7 are likely to be driving a lot of the returns.</p>
<h2>Summary</h2>
<p>Simulating investment skill is feasible and probably quite useful when done well.  Doing it well is unlikely to be done in an afternoon.</p>
<p>The textbook measures of the quality of prediction are going to be inadequate.</p>
<p>Be careful of the most extreme predictions.</p>
<h2>Epilogue</h2>
<p style="padding-left: 30px;"><em>Surely some revelation is at hand</em></p>
<p>from <a href="http://www.potw.org/archive/potw351.html" target="_blank">&#8220;The Second Coming&#8221;</a> by W. B. Yeats</p>
<p><a href="http://www.youtube.com/watch?v=D9hVOsuKuMY" target="_blank">Joni Mitchell&#8217;s version</a>.</p>
<h2>Appendix R</h2>
<p>The computations were <a href="http://www.portfolioprobe.com/user-area/some-hints-for-the-r-beginner/">done with R</a>.</p>
<h4>Wilma</h4>
<p>The function to do the Wilma prediction:</p>
<pre>pp.wilma &lt;- function(realized, predicted=NULL, 
   cors=c(.1, .1), tol=.01)
{
  # simulate investment skill by adjusting correlation

  # Placed in the public domain 2013 by Burns Statistics

  # Testing status: untested

  if(length(predicted)) {
    if(length(predicted) != length(realized)) {
      stop("'realized' and 'predicted' need to be the same length")
    }
    if(length(intersect(names(realized), names(predicted)))) {
      stop("'realized' and 'predicted' need to for the same assets")
    }
    predicted &lt;- predicted[names(realized)]
  } else {
    predicted &lt;- realized
    predicted[] &lt;- sample(predicted)
  }
  rmed &lt;- median(realized)
  low &lt;- realized &lt;= rmed

  sfun.cor &lt;- function(w, real, pred, targetCor) {
    cor(real, w * real + (1 - w) * pred) - targetCor
  }

  wlow &lt;- uniroot(sfun.cor, c(-1,1), tol=tol, 
     real=realized[low], pred=predicted[low], 
     targetCor=cors[1])$root
  predicted[low] &lt;- wlow * realized[low] + (1 - wlow) * 
     predicted[low]
  whi &lt;- uniroot(sfun.cor, c(-1,1), tol=tol, 
     real=realized[!low], pred=predicted[!low], 
     targetCor=cors[2])$root
  predicted[!low] &lt;- whi * realized[!low] + (1 - whi) * 
     predicted[!low]

  predicted
}</pre>
<p>The three predictions were created (the rough beast is born) with:</p>
<pre>pw12q1.1010 &lt;- pp.wilma(real12q1, cors=c(.1, .1))
pw12q1.0010 &lt;- pp.wilma(real12q1, cors=c(0, .1))
pw12q1.n1010 &lt;- pp.wilma(real12q1, cors=c(-.1, .1))</pre>
<h4>Barney</h4>
<p>The function to do the Barney prediction:</p>
<pre>pp.barney &lt;- function(realized, predicted=NULL, 
   fraction=c(.1, .1))
{
  # simulate investment skill by adjusting signs of predictions

  # Placed in the public domain 2013 by Burns Statistics

  # Testing status: untested

  if(length(predicted)) {
    if(length(predicted) != length(realized)) {
      stop("'realized' and 'predicted' need to be the same length")
    }
    if(length(intersect(names(realized), names(predicted)))) {
      stop("'realized' and 'predicted' need to for the same assets")
    }
    predicted &lt;- predicted[names(realized)]
  } else {
    predicted &lt;- realized
    predicted[] &lt;- sample(predicted)
  }

  srmed &lt;- sign(realized - median(realized))
  predicted &lt;- predicted - median(predicted)
  lowi &lt;- which(predicted &lt; 0)
  hii &lt;- which(predicted &gt;= 0)
  changelow &lt;- sample(lowi, round(abs(fraction[1]) * 
     length(lowi)),replace=FALSE)
  if(fraction[1] &lt; 0) {
    predicted[changelow] &lt;- -srmed[changelow] * 
      abs(predicted[changelow])
  } else if(fraction[1] &gt; 0) {
    predicted[changelow] &lt;- srmed[changelow] * 
      abs(predicted[changelow])
  }
  changehi &lt;- sample(hii, round(abs(fraction[2]) * 
     length(hii)), replace=FALSE)
  if(fraction[2] &lt; 0) {
    predicted[changehi] &lt;- -srmed[changehi] * 
      abs(predicted[changehi])
  } else if(fraction[2] &gt; 0) {
    predicted[changehi] &lt;- srmed[changehi] * 
      abs(predicted[changehi])
  }

  predicted
}</pre>
<p>The three predictions were created with:</p>
<pre>pb12q1.2020 &lt;- pp.barney(real12q1, fraction=c(.2, .2))
pb12q1.0020 &lt;- pp.barney(real12q1, fraction=c(0, .2))
pb12q1.n2020 &lt;- pp.barney(real12q1, fraction=c(-.2, .2))</pre>
<h4>estimate variance matrix</h4>
<p>The variance estimate uses 250 daily returns in 2011:</p>
<pre>require(BurStFin)
lwvar11 &lt;- var.shrink.eqcor(initret[seq(to=2014,
   length=250), ])</pre>
<h4>allowable volatility</h4>
<p>The rest of the computations depend on Portfolio Probe:</p>
<pre>require(PortfolioProbe)</pre>
<p>The first thing to do is to get the minimum variance portfolio with the constraints that we are using so that we will know how much volatility we need to allow for:</p>
<pre>op.minvar.lo &lt;- trade.optimizer(prices=initclose[2015,],
   variance=lwvar11, gross=1e7, long.only=TRUE, 
   port.size=60)</pre>
<p>The predicted volatility of the minimum variance portfolio is:</p>
<pre>&gt; sqrt(252 * op.minvar.lo$var.value) 
[1] 0.133833</pre>
<p>We can comfortably have 20% volatility in our portfolios.</p>
<h4>allowable predicted return</h4>
<p>The next step is to see what the best predicted expected return is given the constraints by doing another optimization:</p>
<pre>op.pw1010.lo &lt;- trade.optimizer(prices=initclose[2015,],
   variance=lwvar11, expected.return=pw12q1.1010, 
   gross=1e7, long.only=TRUE, port.size=60,
   var.constraint=.2^2/252)</pre>
<p>The expected return of the optimal portfolio is in the <code>alpha.value</code> component of the resulting object, but we don&#8217;t really need to look at it in this case.  Optimizations were also done with the other prediction vectors.</p>
<p>We also do this for a dollar neutral portfolio where we limit volatility to 10%:</p>
<pre>op.pw1010.ls &lt;- trade.optimizer(prices=initclose[2015,], 
   variance=lwvar11, expected.return=pw12q1.1010, 
   gross=1e7, net=0, port.size=60,
   var.constraint=.1^2/252)</pre>
<h4>generate random portfolios</h4>
<p>We start by generating random portfolios (10,000 in each go) with the same constraints as the optimizations:</p>
<pre>rpvclo &lt;- random.portfolio(number.rand=1e4, 
   prices=initclose[2015,], variance=lwvar11,
   gross=1e7, long.only=TRUE, port.size=60,
   var.constraint=.2^2/252)
rpvcls &lt;- random.portfolio(number.rand=1e4, 
   prices=initclose[2015,], variance=lwvar11,
   gross=1e7, net=0, port.size=60,
   var.constraint=.1^2/252)</pre>
<p>Now we generate random portfolios with these constraints plus a constraint on the expected return:</p>
<pre>rp.pw1010.lo &lt;- random.portfolio(number.rand=1e4, 
   prices=initclose[2015,], variance=lwvar11,
   expected.return=pw12q1.1010, 
   gross=1e7, long.only=TRUE, port.size=60,
   var.constraint=.2^2/252,
   alpha.constraint=unname(mean(pw12q1.1010) + .9 *
      (op.pw1010.lo$alpha.value - mean(pw12q1.1010))))</pre>
<p>The alpha constraint is simpler in the dollar neutral case because we know that we expect zero when no prediction is used.</p>
<h4>get returns</h4>
<p>The only other operation of note is getting the returns of the random portfolios over the quarter of interest.  Really only the density of the returns is used:</p>
<pre>density(100 * valuation(rp.pw1010.lo, 
   prices=initclose[c(2015, 2078),], returns='simple'))</pre>
<p>This uses the <code>valuation</code> function from Portfolio Probe where the prices at the start and finish of the quarter are given and simple returns are asked for.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.portfolioprobe.com/2013/04/29/slouching-towards-simulating-investment-skill/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>US market portrait 2013 week 17</title>
		<link>http://www.portfolioprobe.com/2013/04/27/us-market-portrait-2013-week-17/</link>
		<comments>http://www.portfolioprobe.com/2013/04/27/us-market-portrait-2013-week-17/#comments</comments>
		<pubDate>Sat, 27 Apr 2013 08:54:33 +0000</pubDate>
		<dc:creator>Pat</dc:creator>
				<category><![CDATA[Market portrait]]></category>
		<category><![CDATA[S&P 500]]></category>

		<guid isPermaLink="false">http://www.portfolioprobe.com/?p=10483</guid>
		<description><![CDATA[US large cap market returns. Fine print The data are from Yahoo Almost all of the S&#38;P 500 stocks are used (as implied by Wikipedia on 2013 January 5 &#8212; see the R commands to scrape the data) The initial post was &#8220;Replacing market indices&#8221; The R code is in marketportrait_funs.R &#8212; you are free &#8230; <a href="http://www.portfolioprobe.com/2013/04/27/us-market-portrait-2013-week-17/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>US large cap market returns.</p>
<p><a href="http://www.portfolioprobe.com/2013/04/27/us-market-portrait-2013-week-17/2013-04-22/" rel="attachment wp-att-10484"><img class="aligncenter size-full wp-image-10484" alt="2013-04-22" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/2013-04-22.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/04/27/us-market-portrait-2013-week-17/2013-04-23/" rel="attachment wp-att-10485"><img class="aligncenter size-full wp-image-10485" alt="2013-04-23" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/2013-04-23.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/04/27/us-market-portrait-2013-week-17/2013-04-24/" rel="attachment wp-att-10486"><img class="aligncenter size-full wp-image-10486" alt="2013-04-24" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/2013-04-24.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/04/27/us-market-portrait-2013-week-17/2013-04-25/" rel="attachment wp-att-10487"><img class="aligncenter size-full wp-image-10487" alt="2013-04-25" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/2013-04-25.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/04/27/us-market-portrait-2013-week-17/2013-04-26/" rel="attachment wp-att-10488"><img class="aligncenter size-full wp-image-10488" alt="2013-04-26" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/2013-04-26.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/04/27/us-market-portrait-2013-week-17/wk17-2/" rel="attachment wp-att-10489"><img class="aligncenter size-full wp-image-10489" alt="wk17" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/wk17.png" width="512" height="480" /></a><a href="http://www.portfolioprobe.com/2013/04/27/us-market-portrait-2013-week-17/ytdwk17-2/" rel="attachment wp-att-10490"><img class="aligncenter size-full wp-image-10490" alt="ytdwk17" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/ytdwk17.png" width="512" height="480" /></a></p>
<h4></h4>
<h4>Fine print</h4>
<ul>
<li>The data are from <a href="http://finance.yahoo.com/" target="_blank">Yahoo</a></li>
<li>Almost all of the S&amp;P 500 stocks are used (as <a href="http://en.wikipedia.org/wiki/List_of_S%26P_500_companies" target="_blank">implied by Wikipedia</a> on 2013 January 5 &#8212; see <a href="http://www.portfolioprobe.com/2013/01/05/us-market-portrait-2013-week-1/">the R commands to scrape the data</a>)</li>
<li>The initial post was <a href="http://www.portfolioprobe.com/2012/04/02/replacing-market-indices/">&#8220;Replacing market indices&#8221;</a></li>
<li>The R code is in <a href="http://www.portfolioprobe.com/R/blog/marketportrait_funs.R" target="_blank">marketportrait_funs.R</a> &#8212; you are free to use these functions however you like</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.portfolioprobe.com/2013/04/27/us-market-portrait-2013-week-17/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>garch and the distribution of returns</title>
		<link>http://www.portfolioprobe.com/2013/04/22/garch-and-the-distribution-of-returns/</link>
		<comments>http://www.portfolioprobe.com/2013/04/22/garch-and-the-distribution-of-returns/#comments</comments>
		<pubDate>Mon, 22 Apr 2013 09:14:58 +0000</pubDate>
		<dc:creator>Pat</dc:creator>
				<category><![CDATA[Quant finance]]></category>
		<category><![CDATA[R language]]></category>
		<category><![CDATA[garch]]></category>
		<category><![CDATA[garch simulation]]></category>

		<guid isPermaLink="false">http://www.portfolioprobe.com/?p=10448</guid>
		<description><![CDATA[Using garch to learn a little about the distribution of returns. Previously There are posts on garch &#8212; in particular: A practical introduction to garch modeling The components garch model in the rugarch package garch and long tails There has also been discussion of the distribution of returns, including a satire called &#8220;The distribution of &#8230; <a href="http://www.portfolioprobe.com/2013/04/22/garch-and-the-distribution-of-returns/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Using garch to learn a little about the distribution of returns.</p>
<h2>Previously</h2>
<p>There are <a href="http://www.portfolioprobe.com/tag/garch/">posts on garch</a> &#8212; in particular:</p>
<ul>
<li><a href="http://www.portfolioprobe.com/2012/07/06/a-practical-introduction-to-garch-modeling/">A practical introduction to garch modeling</a></li>
<li><a href="http://www.portfolioprobe.com/2013/01/28/the-components-garch-model-in-the-rugarch-package/">The components garch model in the rugarch package</a></li>
<li><a href="http://www.portfolioprobe.com/2012/08/27/garch-and-long-tails/">garch and long tails</a></li>
</ul>
<p>There has also been discussion of the distribution of returns, including a satire called <a href="http://www.portfolioprobe.com/2012/01/23/the-distribution-of-financial-returns-made-simple/">&#8220;The distribution of financial returns made simple&#8221;</a>.</p>
<h2>Question</h2>
<p>Volatility clustering affects the distribution of returns &#8212; the high volatility periods make the returns look longer tailed than if we take the volatility clustering into account.</p>
<p>The question we try to sneak up on is: What is the distribution of returns when volatility clustering is accounted for?  More specifically, what is the distribution using a reasonable garch model?</p>
<h2>Data</h2>
<p>Daily <a href="http://www.portfolioprobe.com/2010/10/04/a-tale-of-two-returns/">log returns</a> of 443 large cap US stocks with histories from the start of 2004 into the first few days of 2013 were used.  There were 2267 days of returns for each stock.</p>
<p>The components garch model assuming a t distribution was fit to each stock.</p>
<h2>Results</h2>
<h3>Actual results</h3>
<p>The estimated degrees of freedom for the stocks is shown in Figure 1.  Estimation failed for one stock.</p>
<p>Figure 1: Estimated degrees of freedom for the t in the components garch model for the US large cap stocks. <a href="http://www.portfolioprobe.com/2013/04/22/garch-and-the-distribution-of-returns/empiricaldof/" rel="attachment wp-att-10454"><img class="aligncenter size-full wp-image-10454" alt="empiricaldof" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/empiricaldof.png" width="512" height="480" /></a>A lot of the estimates are close to 6 and hardly any (about 5%) are greater than 10.</p>
<h3>Normal distribution</h3>
<p>Next was to see what degrees of freedom are estimated if the residuals are normally distributed.  The fits from the first three stocks were used &#8212; separately &#8212; to simulate series (200 each) and then fit the model to those simulated series.</p>
<p>Figure 2 shows the distributions of the estimated degrees of freedom from the three fits.</p>
<p>Figure 2: Distributions of estimated degrees of freedom using the initial simulated series from three fits. <a href="http://www.portfolioprobe.com/2013/04/22/garch-and-the-distribution-of-returns/normaldofinit/" rel="attachment wp-att-10455"><img class="aligncenter size-full wp-image-10455" alt="normaldofinit" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/normaldofinit.png" width="512" height="480" /></a>I&#8217;m hoping that we can all agree that the normal distribution can be ruled out as the actual distribution.  There is virtually no overlap between the distribution in Figure 1 and those in Figure 2.</p>
<p>It appears that the black distribution in Figure 2 is different from the other two &#8212; that it has a much higher probability of being less than 80.  But the distributions are based on only 200 series each; there will be noise.  A further 1000 series were generated for each fit to see if the pattern persists with new, more extensive data.  Figure 3 shows the results.</p>
<p>Figure 3: Distributions of estimated degrees of freedom using the confirmatory simulated series from three fits. <a href="http://www.portfolioprobe.com/2013/04/22/garch-and-the-distribution-of-returns/normaldofconfirm/" rel="attachment wp-att-10456"><img class="aligncenter size-full wp-image-10456" alt="normaldofconfirm" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/normaldofconfirm.png" width="512" height="480" /></a>The distributions do indeed appear to be different &#8212; the black one has just over 50% probability of being less than 80 while the other two have less than 40%.</p>
<p>This means that we can&#8217;t assume that the estimate of the degrees of freedom is independent of the other parameters.</p>
<h3>t distribution</h3>
<p>The next test was &#8212; for each stock &#8212; simulate a series using the coefficients estimated for the stock but with residuals following a t distribution with 6 degrees of freedom.  The distribution of estimated degrees of freedom from fitting the simulated series is shown in Figure 4.</p>
<p>Figure 4: Distribution of estimated degrees of freedom for series created with a t with 6 degrees of freedom and coefficients specific to each stock. <a href="http://www.portfolioprobe.com/2013/04/22/garch-and-the-distribution-of-returns/t6specificdof/" rel="attachment wp-att-10465"><img class="aligncenter size-full wp-image-10465" alt="t6specificdof" src="http://www.portfolioprobe.com/wp-content/uploads/2013/04/t6specificdof.png" width="512" height="480" /></a>This is much too centered near 6 compared to Figure 1. About 20% of the real estimated degrees of freedom are smaller than the smallest degree of freedom estimated from the t6 simulations.  Likewise, about 10% of the real degrees of freedom are bigger than the biggest from the t6 simulations.</p>
<p>I propose two (not necessarily mutually exclusive) possibilities:</p>
<ul>
<li>Different stocks have different distributions</li>
<li>The real distribution is not t and the degrees of freedom are not a good approximation</li>
</ul>
<h2>Summary</h2>
<p>We&#8217;ve shown &#8212; once again &#8212; that the normal distribution is not believable.</p>
<p>We&#8217;ve also highlighted our ignorance about the true situation.</p>
<h2>Appendix R</h2>
<p><a href="http://www.portfolioprobe.com/user-area/some-hints-for-the-r-beginner/">The R language</a> was used to do the computing.</p>
<h4>collect coefficients from the model on stocks</h4>
<p>We start by making sure the <code>rugarch</code> package is loaded in the session, create the specification object that we want, and fit garch models to the first three stocks:</p>
<pre>require(rugarch)

comtspec &lt;- ugarchspec(mean.model=list(
  armaOrder=c(0,0)), distribution="std",
  variance.model=list(model="csGARCH"))
fit1 &lt;- ugarchfit(spec=comtspec, initret[,1])
fit2 &lt;- ugarchfit(spec=comtspec, initret[,2])
fit3 &lt;- ugarchfit(spec=comtspec, initret[,3])</pre>
<p>The <code>initret</code> object is the matrix of returns.  Next we create a matrix to hold the coefficients for all of the stocks:</p>
<pre>gcoefmat &lt;- array(NA, c(443, length(coef(fit1))), 
   list(colnames(initret),names(coef(fit1))))</pre>
<p>That the matrix is initialized with missing values is not accidental.  We&#8217;re not guaranteed that the default estimation will work.  Now we&#8217;re ready to collect the coefficients:</p>
<pre>for(i in 1:443) {
  thiscoef &lt;- try(coef(ugarchfit(spec=comtspec, initret[,i])))
  if(!inherits(thiscoef, "try-error") &amp;&amp; length(thiscoef) == 7) {
    gcoefmat[i,] &lt;- thiscoef
  }
  cat("."); if(i %% 50 == 0) cat("\n")
} 
cat("\n")</pre>
<p>This takes evasive action in case we don&#8217;t get a vector of coefficients like we expect &#8212; it uses the <code>try</code> function to continue going even if there is an error.  It also gives an indication of how far along the loop is (since fitting over 400 garch models is not especially instantaneous).</p>
<h4>simulate garch from a specific distribution</h4>
<p>Here is a function that will take a garch fit object and simulate a number of series using residuals from a particular distribution:</p>
<pre>pp.garchDistSim &lt;- function(gfit, FUN, trials=200, 
   burnIn=100, ...)
{
  # simulate a garch model given a fit

  # placed in the public domain 2013 by Burns Statistics

  # testing status: untested

  ntimes &lt;- gfit@model$modeldata$T
  FUN &lt;- match.fun(FUN)
  inresid &lt;- scale(matrix(FUN((ntimes+burnIn) * trials, 
       ...), ntimes+burnIn, trials))
  simseries &lt;- ugarchsim(gfit, n.sim=ntimes, 
       n.start=burnIn, m.sim=trials, 
       startMethod="sample", custom.dist=list(name="sample",
       distfit = inresid))@simulation$seriesSim
  simseries        
}</pre>
<p>The residuals that are given to the simulation function are scaled (with the <code>scale</code> function) to have zero mean and variance 1 because the routine expects the residuals to be distributed like that.  It can get grumpy if that is obviously not the case.</p>
<h4>simulate with normals</h4>
<p>The function above is used like:</p>
<pre>gsnorm1 &lt;- pp.garchDistSim(fit1, rnorm, trials=200)
gsnorm2 &lt;- pp.garchDistSim(fit2, rnorm, trials=200)
gsnorm3 &lt;- pp.garchDistSim(fit3, rnorm, trials=200)</pre>
<p>Once we have these series, we can fit the garch model to them and save the coefficients:</p>
<pre>gsnorm1.coefmat &lt;- array(NA, c(200, 7), 
   list(NULL, names(coef(fit1))))
gsnorm2.coefmat &lt;- gsnorm3.coefmat &lt;- gsnorm1.coefmat

for(i in 1:200) {
  thiscoef &lt;- try(coef(ugarchfit(spec=comtspec, gsnorm1[,i])))
  if(!inherits(thiscoef, "try-error") &amp;&amp; length(thiscoef) == 7) {
    gsnorm1.coefmat[i,] &lt;- thiscoef
  }
  cat("."); if(i %% 50 == 0) cat("\n")
} 
cat("\n")</pre>
<h4>difference of distributions from normal</h4>
<p>We can get the confidence interval for the proportion of the black distribution from the confirmatory normal estimates being less than 80 by using the <code>binom.test</code> function:</p>
<pre tabindex="0">&gt; binom.test(sum(gsnorm2M.coefmat[,7] &lt; 80, na.rm=TRUE),
+            sum(!is.na(gsnorm2M.coefmat[,7])))

	Exact binomial test

data:  sum(gsnorm2M.coefmat[, 7] &lt; 80, na.rm = TRUE)
  and sum(!is.na(gsnorm2M.coefmat[, 7]))
number of successes = 489, number of trials = 963, 
  p-value = 0.6519
alternative hypothesis: true probability of success is
  not equal to 0.5
95 percent confidence interval:
 0.4757106 0.5398179
sample estimates:
probability of success 
             0.5077882</pre>
<p>That the binomial test sees 963 observations means that 37 of the 1000 series didn&#8217;t produce an appropriate vector of coefficients using the default fitting settings.</p>
<p>The stock that is the odd one out (the black one) is ABT.  The other two are MMM and ANF.  The fit for ABT is significantly more persistent than for the other two (but experimentation is needed to understand what is happening).</p>
<h4>simulate given a garch specification</h4>
<p>Here is a function that simulates series given a garch specification:</p>
<pre>pp.gspecDistSim &lt;- function(spec, FUN, ntimes, trials=1, 
 burnIn=100, ...)
{
  # simulate a garch model given a specification

  # placed in the public domain 2013 by Burns Statistics

  # testing status: untested

  FUN &lt;- match.fun(FUN)
  inresid &lt;- scale(matrix(FUN((ntimes+burnIn) * trials, ...),
     ntimes+burnIn, trials))
  simseries &lt;- ugarchpath(spec, n.sim=ntimes, 
     n.start=burnIn, m.sim=trials, startMethod="sample", 
 custom.dist=list(name="sample",
     distfit = inresid))@path$seriesSim
  simseries        
}</pre>
<h4>paired simulation with a t</h4>
<p>The function immediately above was used like:</p>
<pre>gst6specific.coefmat &lt;- array(NA, c(443, 7), 
   dimnames(gcoefmat))
for(i in 1:443) {
  thisspec &lt;- comtspec
  stockcoef &lt;- gcoefmat[i,]
  if(any(is.na(stockcoef))) next
  setfixed(thisspec) &lt;- as.list(stockcoef) 
  simser &lt;- pp.gspecDistSim(thisspec, rt, ntimes=2267, 
     trials=1, df=6)
  thiscoef &lt;- try(coef(ugarchfit(spec=comtspec, simser)))
  if(!inherits(thiscoef, "try-error") &amp;&amp; length(thiscoef) == 7) {
    gst6specific.coefmat[i,] &lt;- thiscoef
  }
  cat("."); if(i %% 50 == 0) cat("\n")
} 
cat("\n")</pre>
<p>Note that the call to <code>pp.gspecDistSim</code> in this loop is using <a href="http://www.burns-stat.com/the-three-dots-construct-in-r/" target="_blank">R&#8217;s dot-dot-dot mechanism</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.portfolioprobe.com/2013/04/22/garch-and-the-distribution-of-returns/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
