In Section 6.2, the statistical properties of some simple estimators were con- sidered, such as the mean and standard deviation of the sampling distribution of the sample mean return on an asset. However, such properties are difficult to derive for more complicated estimators, such as shrinkage estimators or estimators of portfolio weights.
In such cases, an alternative approach to studying the behavior of esti- mators is to useMonte Carlo simulation, in which observations are simulated from a known distribution, estimates of interest are calculated, and those sim- ulated values of the estimates are used to assess the sampling distributions of the estimators. In this section, the Monte Carlo method is used to estimate properties of the sampling distributions of a number of estimators.
The basic approach is illustrated on the following example.
Example 6.15 In Example 6.3, we considered the properties of the sample mean return based on the observation of 60 returns, independently distributed
according to a distribution with mean 0.01 and standard deviation 0.05. In this example, we perform a similar analysis, using Monte Carlo simulation in place of the theoretical properties discussed in Section 6.2.
To simulate a sequence of 60 such returns, we may use the commandrnorm.
Specifically,
> ret<-rnorm(60, mean=0.01, sd=0.05)
draws 60 random variables independently from a normal distribution with mean 0.01 and standard deviation 0.05 and places the result in the variable ret, a vector of length 60. The sample mean of this vector,
> mean(ret) [1] 0.0178
represents a sample of size one from the distribution of the random variable R¯j =T
t=1Rj,t/60, whereRj,1, Rj,2, . . . , Rj,60have the distribution described previously.
Of course, a sample of size one does not provide much information. Hence, we are generally interested in a large sample of such simulated sample means.
To simulate many sample means at one time, we may use the following proce- dure. We begin by simulating a matrix of returns, where each row corresponds to a vector of 60 returns.
> ret_mat<-matrix(rnorm(60*10000, mean=0.01, sd=0.05), 10000, 60) Here the functionrnormsimulates 600,000 independent returns, each normally distributed with mean 0.01 and standard deviation 0.05, and the function matrixarranges these in a 10,000×60 matrix.
Usingapply, we may now calculate the sample mean of each row:
> ret_mean<-apply(ret_mat, 1, mean)
The variable ret_mean now contains a sample of size 10,000 from the dis- tribution of ¯Rj. We may now analyze ret_meanas we would any sample of observations. For instance,
> mean(ret_mean) [1] 0.01002
> sd(ret_mean) [1] 0.00642
are estimates of the mean and standard deviation, respectively, of the sampling distribution of ¯Rj.
Recall that, in this scenario, the mean and standard deviation of this sam- pling distribution may be calculated exactly and, in Example 6.3, they were shown to be 0.01 and 0.00645, respectively. Thus, the Monte Carlo estimates closely match the true values; generally speaking, even closer agreement could be obtained by increasing the number of Monte Carlo replications. That is, we
can achieve closer agreement by increasing the number of rows in the matrix ret_mean.
Other properties of the sampling distribution of ¯Rj may be found in the same way. For instance,
> summary(ret_mean)
Min. 1st Qu. Median Mean 3rd Qu. Max.
-0.01260 0.00571 0.01003 0.01002 0.01440 0.03110
Thus, estimates of the upper and lower quartiles of the sampling distribution of R¯j are given by 0.00571 and 0.0144, respectively. Recall that, in Example 6.3, we approximated these by 0.00570 and 0.0143, respectively. The advantage of the Monte Carlo method is that these values were obtained using only numer- ical methods, without using any analytical approximations. One drawback of the Monte Carlo method is that, if the analysis is repeated, different results will be obtained, although if a large Monte Carlo sample size is used, such as the 10,000 used here, the differences are generally slight. For instance, if the calculations described previously are repeated, the sample mean and stan- dard deviation of the simulated return sample means are 0.01009 and 0.00643, respectively.
A histogram of the simulated mean returns gives some information about the shape of the sampling distribution; such a plot can be produced by the commandhist(ret_mean). The result is given in Figure 6.2, and it supports the conclusion of the CLT that the sampling distribution of ¯Rj is approxi- mately normal. A normal probability plot, as discussed in Section 2.5, could
also be considered.
Histogram of ret_mean
ret_mean
Frequency
−0.01 0 0.01 0.02 0.03
0 500 1000 1500 2000 2500
FIGURE 6.2
Histogram of simulated sample mean returns.
Given the form of the estimator—a sample mean—along with the distri- bution of the returns, which are assumed to be independent and normally distributed, it is not surprising that the distribution of ¯Rj is approximately normal; of course, in this case, it is well-known that the distribution of ¯Rj is exactly normal. A more extensive study of this type would likely change the assumed distribution of the returns in order to study the effect of distri- butional assumptions on the properties of the estimator. With Monte Carlo simulation, such changes are generally easy to implement.
Example 6.16 Consider the Monte Carlo simulation described in Example 6.15, which analyzed the properties of the sample mean return based on the observation of 60 returns, independently distributed according to a distri- bution with mean 0.01 and standard deviation 0.05, but now suppose that the observations are not normally distributed. Empirical studies have shown that thet-distribution is often useful for modeling return data; thus, here we assume that the returns follow a t-distribution with six degrees of freedom, with location and scale parameters chosen to achieve the desired mean and standard deviation.
Changing the distribution used in the Monte Carlo simulation from the normal distribution to the t-distribution focuses on changing the function rnormused in Example 6.15 to the functionrt, which simulates observations from a t-distribution. However, the properties of the t-distribution are such that some care is needed in order to achieve the required results.
The degrees of freedom inrtis specified by the argumentdf; for example, rt(1, df=6)returns one observation from a t-distribution with six degrees of freedom. The complications arise when specifying the mean and standard deviation of the distribution. A random variable with at-distribution withν degrees of freedom has mean 0 and varianceν/(ν−2), provided that ν>2;
thus, a random variable with at-distribution with six degrees of freedom has mean 0 and standard deviation√
1.5. It follows that to draw a random sample of sizen from a t-distribution with mean 0.01, standard deviation 0.05, and six degrees of freedom, we use the command
rt(n, df=6)*(0.05/(1.5^.5))+0.01
Therefore, to repeat the Monte Carlo study described in Example 6.15, but with a t-distribution with six degrees of freedom replacing the standard normal distribution, we use the commands
> ret_mat_t<-matrix(rt(60*10000, df=6)*(0.05/(1.5^.5))+0.01, + 10000, 60)
> ret_mean_t<-apply(ret_mat_t, 1, mean)
> mean(ret_mean_t) [1] 0.00999
> sd(ret_mean_t) [1] 0.00641
> summary(ret_mean_t)
Min. 1st Qu. Median Mean 3rd Qu. Max.
-0.01340 0.00566 0.01000 0.00999 0.01430 0.03450
Note that the results are generally similar to those obtained in Example 6.15, suggesting that the sampling distribution of the sample mean is close to normal even if the returns follow at-distribution. This is not surprising given that each sample mean is based on 60 observations; the approximation given by the CLT tends to be accurate for that sample size.
In the examples considered thus far in this section, Monte Carlo simulation was applied to an estimator whose properties may be determined using ana- lytic methods. However, the Monte Carlo method is most useful when such analytic results are not readily available. Many such cases occur when the estimator under consideration is a function of the returns on several assets, so that the correlation structure of the returns plays a role in the sampling distribution.
Simulating a Return Vector
To handle such cases using Monte Carlo simulation, we need a method of simulating a random vector in which the component random variables are correlated. For instance, let R1,R2, . . . ,RT denote N-dimensional random vectors, with Rt representing the vector of asset returns at time t. These random vectors may be viewed as the multivariate analogues of the returns Rj,1, Rj,2, . . . , Rj,60analyzed in Example 6.15. Note that although it is often reasonable to assume thatRt andRs are uncorrelated or even independent, fort=s, the components ofRt, which represent the returns on different assets at timet, cannot realistically be modeled as uncorrelated random variables.
Consider simulation ofRtunder the assumption that this random vector has mean vectorμand covariance matrixΣ for given values ofμ andΣ. For the distribution ofRt, we first use the multivariate normal distribution; we then will consider a multivariate version of at-distribution.
A random vector Y = (Y1, Y2, . . . , YN)T has a multivariate normal distri- bution if any linear function ofY, that is, any function of the formN
j=1ajYj for constantsa1, a2, . . . , aN, has a univariate normal distribution. The param- eters of the multivariate normal distribution are its mean vector and its covariance matrix.
To simulate random variates with a multivariate normal distribution in R, we use the function mvrnorm, which is available in the package MASS (Venables and Ripley 2002); the following example illustrates how mvrnorm may be used to conduct a simulation study similar to the one conducted in Example 6.15. The arguments of mvrnorm are n, the number of samples requested, mu, the mean vector of the distribution, and Sig, the covariance matrix of the distribution.
Example 6.17 Consider a three-dimensional multivariate normal distribu- tion with mean vector (0.1,0.2,0.3)T and covariance matrix
⎛
⎝0.2 0.1 0.1 0.1 0.2 0.1 0.1 0.1 0.2
⎞
⎠. (6.9)
Thus, each of the three component random variables in the random vector has variance 0.2 and the correlation between any two such random variables is 0.5.
The following command generates one sample from this distribution.
> library(MASS)
> mu0<-c(0.1,0.2,0.3)
> Sig0<-matrix(c(0.2,0.1,0.1,0.1,0.2,0.1,0.1,0.1,0.2), 3, 3)
> Sig0
[,1] [,2] [,3]
[1,] 0.2 0.1 0.1 [2,] 0.1 0.2 0.1 [3,] 0.1 0.1 0.2
> mvrnorm(n=1, mu=mu0, Sig=Sig0) [1] -0.3335 0.0529 0.0982
Forn= 1, the result of the function is a vector; for n >1, the result is a matrix, with each row corresponding to a simulated random vector. For exam- ple, to draw four random vectors from the multivariate normal distribution with mean vectormu0and covariance matrixSig0, we use the command
> mvrnorm(4, mu=mu0, Sig=Sig0) [,1] [,2] [,3]
[1,] -0.193 0.1644 -0.273 [2,] 0.297 0.3012 -0.148 [3,] 0.603 -0.0955 1.085 [4,] -0.149 0.2805 -0.331
Therefore, if the returns on a set of three assets are modeled as random vectors with meanmu0and covariance matrixSig0, and the return vectors in different time periods are independent, then the matrixret.simrepresents the returns on the three assets over four time periods, with each row representing a time period. Hence, ret.simis a simulated data matrix of the type described in Section 6.3 and is similar to the observed data matrixbig8.
Simulated values of functions of these returns may be calculated in the usual way. For instance, simulated return sample means for the three assets are given by
> apply(ret.sim, 2, mean) [1] 0.1393 0.1627 0.0833
Now consider replications of this procedure. For the case of a single asset, in which the returns are given in a vector, independent replications of the returns may be stored in a matrix, with each row corresponding to a series of asset returns. When simulating a vector of returns, one replication of the simulation is already a matrix. Although it is possible to handle the replications using a three-dimensional array, a generalization of a matrix (an interesting exercise, for those so inclined), the simplest approach is to use a loop.
For instance, to obtain 10,000 simulated values of the return sample means for the three assets in the example, we can use the following commands:
ret_means<-matrix(0, 10000, 3) for (j in 1:10000){
+ ret_sim<-mvrnorm(4, mu=mu0, Sig=Sig0) + ret_means[j, ]<-apply(ret_sim, 2, mean)
+ }
The commandret_means<-matrix(0, 10000, 3)creates a matrix that will store the results. Each iteration of the loop simulates a vector of sample means of the asset returns and stores them in a row ofret_means.
The results inret_meansmay now be used to estimate properties of the sampling distribution. For instance, the mean of the sampling distribution of Rtis estimated by
> apply(ret_means, 2, mean) [1] 0.0967 0.2007 0.2991
which is close to the known mean vector (0.1,0.2,0.3)T. Many statistical methods tend to work particularly well for normally dis- tributed data. Thus, in conducting a Monte Carlo study, it is often of interest to consider other distributions in addition to the multivariate normal.
The multivariate t-distribution is a multivariate generalization of the t- distribution; its relationship to the univariatet-distribution is similar to the relationship the multivariate normal distribution has to the univariate normal distribution.
To simulate random variates with a multivariate t-distribution in R, we use the functionrmvt, which is available in the packagemvtnorm(Genz et al.
2016). In the function rmvt, we may specify the number of samples (the argumentn), the degrees of freedom (the argumentdf), and the “scale” matrix (the argument sigma). Let A denote the scale matrix; then the covariance matrix of the distribution is given byΣ=A(ν/(ν−2)), whereν denotes the degrees of freedom of the distribution. The following example illustrates the use ofrmvt.
Example 6.18 Consider a three-dimensional random vector with the mean vector and covariance matrix given in Example 6.17 and stored in the R variablesmu0 and Sig0, respectively. Furthermore, assume that the random vector has a multivariatet-distribution.
To generate one sample from the multivariate t-distribution with six degrees of freedom, mean vector mu0, and covariance matrix Sig0, we use the following command.
> library(mvtnorm)
> rmvt(n=1, df=6, sigma=Sig0)/(1.5^.5) + mu0 [,1] [,2] [,3]
[1,] 0.172 0.677 0.0995
Note thatrmvtdraws a random vector from a multivariate distribution with mean vector0; adding the vectormu0to the result modifies the mean vector tomu0.
To simulate several random vectors, we can increase the value ofn. How- ever, in order to add the mean vector to the simulated random vectors, we must construct a matrix of mean vectors. For instance, suppose that we wish to simulate four random vectors. Then
> rmvt(n=4, df=6, sigma=Sig0)/(1.5^.5) [,1] [,2] [,3]
[1,] 1.2761 -0.2582 -0.367 [2,] -0.0084 0.0747 -0.676 [3,] 0.7659 0.3709 0.588 [4,] 0.4114 0.1233 0.324
returns a data matrix with the correct covariance matrix but each value is simulated from a distribution with mean zero.
To add the mean vector to the result of rmvt, note that matrix(mu0, 4, 3, byrow=T)returns a matrix with each row equal tomu0:
> matrix(mu0, 4, 3, byrow=T) [,1] [,2] [,3]
[1,] 0.1 0.2 0.3 [2,] 0.1 0.2 0.3 [3,] 0.1 0.2 0.3 [4,] 0.1 0.2 0.3 Thus, the command
> rmvt(n=4, df=6, sigma=Sig0)/(1.5^.5)+matrix(mu0, 4, 3, byrow=T) [,1] [,2] [,3]
[1,] -0.0498 0.4837 -0.2124 [2,] -0.4936 0.7804 0.0633 [3,] 0.2842 0.0878 0.3022 [4,] -0.0518 -0.0329 -0.1120
returns random variates simulated from the correct distribution.
To verify that the command is working as desired, we may simulate a data matrix with 1000 observations on the random vector,
> x<-rmvt(n=1000, df=6, sigma=Sig0)/(1.5^.5)+matrix(mu0, 1000, 3, + byrow=T)
and verify that the sample mean vector and sample covariance matrix are close tomu0andSig0, respectively.
> apply(x, 2, mean) [1] 0.110 0.203 0.293
> cov(x)
[,1] [,2] [,3]
[1,] 0.220 0.1116 0.1063 [2,] 0.112 0.2055 0.0956 [3,] 0.106 0.0956 0.2043
We now consider two examples illustrating how Monte Carlo simulation may be used to better understand the properties of statistical methods used to analyze financial data.
Using Monte Carlo Simulation to Describe the Sampling Distribution of a Statistic
In Chapters 4 and 5, a number of different approaches to constructing portfolio weights were discussed; these methods are based on the means, standard deviations, and correlations of the returns on the assets under consideration, along with some criteria for choosing the weights. Here we use Monte Carlo simulation to assess the variability in the estimated weights for the tangency portfolio of two assets.
Let μj and σj denote the mean and standard deviation, respectively, of the return on assetj,j= 1,2 and let ρdenote the correlation of the returns on the two assets. Then, according to the analysis in Section 4.6, the tangency portfolio places weight
wT = (μ1−μf)σ21−(μ2−μf)ρ12σ1σ2
(μ2−μf)σ21+ (μ1−μf)σ22−[(μ1−μf) + (μ2−μf)]ρ12σ1σ2
(6.10) on asset 1, whereμf denotes the return on the risk-free asset. Alternatively, we may use the formula for the tangency weights for a vector of assets,
Σ−1(μ−μf1) 1TΣ−1(μ−μf1),
which is easier to evaluate numerically. It is straightforward to show that this formula reduces to (6.10) forN = 2.
Example 6.19 Consider two assets such that the excess return on the first asset has mean 0.025 and variance 0.0055 and the excess return on the second asset has mean 0.010 and variance 0.0017; take the covariance of the returns to be 0.0008. These are the observed values (slightly rounded) for Apple stock and Coca-Cola stock based on the big8data. Define variablesmu1andSig1 to represent the mean vector and covariance matrix of the excess returns:
> mu1<-c(0.025, 0.010)
> Sig1<-matrix(c(0.0055, 0.0008, 0.0008, 0.0017), 2, 2) Thus, the tangency portfolio has weights
> solve(Sig1, mu1)/sum(solve(Sig1, mu1)) [1] 0.496 0.504
so that this portfolio places roughly half its investment on each asset.
Simulating the data according to a multivariate normal distribution, as described previously in this section, we may draw a sample from the sampling distribution of the weight on Apple stock (note that, since the weights sum to 1, we only need to consider one of the weights).
> wgts<-rep(0, 10000)
> sharpe<-rep(0, 10000)
> for (j in 1:10000){
+ ret_sim<-mvrnorm(60, mu=mu1, Sig=Sig1) + mean_sim<-apply(ret_sim, 2, mean) + sig_sim<-cov(ret_sim)
+ wgt_sim<-solve(sig_sim, mean_sim)/sum(solve(sig_sim, + mean_sim))
+ wgts[j]<-wgt_sim[1]
+ sharpe[j]<-sum(mean_sim*wgt_sim)/((wgt_sim%*%sig_sim%*%
+ wgt_sim)^.5) + }
The vectorwgtscontains a sample of size 10,000 from the sampling distribu- tion ofwT, the weight on Apple stock in the tangency portfolio of Apple and Coca-Cola stocks, each based on 60 observations; the vectorsharpecontains the estimated Sharpe ratio corresponding to the estimated tangency portfolio.
The sampling distribution ofwT can be summarized using the usual functions;
for example,
> mean(wgts) [1] 0.64
> median(wgts) [1] 0.487
Hence, although the median weight of 0.487 is close to the true weight of 0.496, the mean weight is considerably larger than the true weight, suggesting a skewed distribution.
The quantiles of the sampling distribution are a useful summary of the distribution; these may be calculated using thequantilefunction.
>probvec<-c(0.01, 0.05, 0.10, 0.25, 0.50, 0.75, 0.90, 0.95, 0.99)
> quantile(wgts, prob=probvec)
1% 5% 10% 25% 50% 75% 90% 95% 99%
-0.439 0.095 0.190 0.324 0.487 0.713 1.057 1.476 3.565 These results show that there is considerable variability in the estimated weights. For instance, in more than 10% of the Monte Carlo simulations the weight for Apple stock is greater than one and, hence, the weight for Coca-Cola is negative.
The maximum Sharpe ratios also exhibit a high degree of variability:
> quantile(sharpe, prob=probvec)
1% 5% 10% 25% 50% 75% 90% 95% 99%
0.018 0.189 0.235 0.311 0.399 0.491 0.575 0.629 0.737
These values may be compared to the Sharpe ratio of the tangency portfolio
based on the true distribution, which is 0.373.
The analysis in Example 6.19 is based on the assumption that the returns in a given period have a multivariate normal distribution; we may repeat the analysis using the assumption that the returns have a multivariate t- distribution with six degrees of freedom.
Example 6.20 Consider the two assets described in Example 6.19, with mean excess return vector given inmu1and return covariance matrix given inSig1. Simulating the data according to a multivariate t-distribution with six degrees of freedom, as described previously in this section, we may draw a sample from the sampling distribution of the weight on Apple stock using the following commands.
> wgts.t<-rep(0, 10000)
> sharpe.t<-rep(0, 10000)
> for (j in 1:10000){
+ ret_sim<-rmvt(60, df=6, sigma=Sig1)/(1.5^.5) + matrix(mu1, + 60, 2, byrow=T)
+ mean_sim<-apply(ret_sim, 2, mean) + sig_sim<-cov(ret_sim)
+ wgt_sim<-solve(sig_sim, mean_sim)/sum(solve(sig_sim, + mean_sim))
+ wgts.t[j]<-wgt_sim[1]
+ sharpe.t[j]<-sum(mean_sim*wgt_sim)/((wgt_sim%*%sig_sim%*%
+ wgt_sim)^.5) + }
The vectorwgts.tcontains a sample of size 10,000 from the sampling dis- tribution of the weight on Apple stock in the tangency portfolio of Apple and