Code covered by the BSD License
 ...
 Addition(x,y);
 Adendotd(dense, d, sparAd...
 Amul(At,dense,x,transp)
 BivStandardTPDF(x,y,r,nu)
 ChoiceGeneric(Market,Inve...little perturbation to the right of the frontier
 ChoiceOptimal(Market,Inve...
 ChoiceOptimal(Market,Inve...
 ChoiceOptimal(Market,Inve...
 ChoiceOptimal(Market,Inve...
 ChoiceOptimal(Market,Inve...
 ChoiceSubOptimal(Market,I...this is the equally weighted allocation ....
 Constraints(x,P)
 Cost(Allocation,Market,In...
 Cost(Allocation,Market,In...
 Cost(Allocation,Market,In...
 Cost(Allocation,Market,In...
 DecisionBayesParameters(M...% estimate market parameters
 DecisionBestPerfomer(Mark...% find index of best performer
 DecisionPrior(Market,Inve...prior is the equally weighted allocation
 DecisionSample(Market,Inv...% estimate market parameters
 E=TwoDimEllipsoid(Locatio...
 E=TwoDimEllipsoid(Locatio...
 E=TwoDimEllipsoid(Locatio...
 EMforT(x,Nu,Tolerance)
 EfficientFrontier(NumPort...This function returns the NumPortf x 1 vector expected returns,
 EfficientFrontier(NumPort...This function returns the NumPortf x 1 vector expected returns,
 EfficientFrontier(NumPort...This function returns the NumPortf x 1 vector expected returns,
 EfficientFrontier(NumPort...This function returns the NumPortf x 1 vector expected returns,
 EfficientFrontier(NumPort...% determine exp value of minimumvariance portfolio
 EfficientFrontier(NumPort...This function returns the NumPortf x 1 vector expected returns,
 EfficientFrontier(NumPort...This function returns the NumPortf x 1 vector expected returns,
 EfficientFrontierNoConstr...determine exp value of minimumvariance portfolio
 G_Hat_1(X)
 G_Hat_2(X)
 InvWishCorr(S,Nu,NumCases)
 L=Lklhd(Theta,X,T,N,VecIn...this function computes the likelihood of an Nvariate normal sample of length T
 LogLik(x,Nu,Mu,Sigma)
 LogLik(x,Nu,Mu,Sigma)
 LogTCopulaPDF(u,nu,Mu,Sig...this function computes the pdf of the copula of the logt distribution
 LogTPDF(x,nu,Mu,Sigma)
this function computes the pdf of the Nvariate logt distribution
 LognormalCopulaPDF(u,Mu,S...this function computes the pdf of the copula of the lognormal distribution
 LognormalPDF(x,Mu,Sigma)
this function computes the pdf of the Nvariate lognormal distribution
 MktProjection(Exp_Yr_Comp...
 MleRecursionForT(x,Nu,Tol...this function computes recursively the ML estimators of location and scatter
 NormalCopulaCDF(u,Mu,Sigma)
 NormalCopulaCDF(u,Mu,Sigma)
 NormalCopulaPDF(u,Mu,Sigma)
this function computes the pdf of the copula of the normal distribution
 NormalPDF(x,Mu,Sigma)
this function computes the pdf of the Nvariate normal distribution
 OutlierCutoff(d,d_0)
 PlotFrontier(Portfolios)
 PlotFrontier(Portfolios)
 PlotNIWMarginals(Mu_Simul...this function plots numerically and analytically the marginal pdf of
 PopK(d,x,K,lpq)
 PriorPDF(Theta,Theta_0,c_...This function computes the joint pdf of the normalinverseWishart distribution. For notation and theory
 ProcessNPlotFrontier(T_0,...
 Q=QuantileNormalMixture(c...this function computes the quantile for a mixture of normals
 Rejected=RejectOutlier(Sa...this function finds the "worst" outlier in a time series.
 RunAnalysis(Dates,Data)
this function performs simple invariance (i.i.d.) tests on a time series
 Satisfaction(Allocation,M...
 Satisfaction(Allocation,M...
 Satisfaction(Allocation,M...
 Satisfaction(Allocation,M...
 Satisfaction(Allocation,M...
 TCopulaCDF(u,nu,Mu,Sigma)
 TCopulaPDF(u,nu,Mu,Sigma)
this function computes the pdf of the copula of the t distribution
 TPDF(x,nu,Mu,Sigma)
this function computes the pdf of the Nvariate t distribution
 TwoDimEllipsoid(Location,...this function computes the locationdispersion ellipsoid
 TwoDimEllipsoid(Location,...this function computes the locationdispersion ellipsoid
 TwoDimEllipsoid(Location,...this function computes the locationdispersion ellipsoid
 UniformEllipticalPDF(x,Mu...this function computes the pdf of the Nvariate
 WishartPDF(W,nu,S)
this function computes the pdf of the NxNvariate Wishart distribution
 [Dates,ZeroPrices]=Proces...fixedincome invariance quest from
 [E,V,MV_ExpectedValue,MV_...compute useful parameters
 [E,V,MV_ExpectedValue,MV_...compute useful parameters
 [E,V,MV_ExpectedValue,MV_...compute useful parameters
 [E_EM, S_EM, Y, CountLoop...this function implements the ExpectationMaximization (EM) algorithm to recover
 [E_hat,V_hat]=UnevenSerie...this function estimates the parameters of a multivariate normal distribution
 [Expected_Value,Covarianc...this function computes analytically the summary statistics of a lognormal variable
 [M,S]=Log2Lin(Mu,Sigma)
 [M,S]=Log2Lin(Mu,Sigma)
 [MVE_Location,MVE_Dispers...this function computes the minimum volume ellipsoid for a given time series.
 [Mu,Sigma,InvSigma]=randN...this function generates a multivariate i.i.d. sample of lenght J from the
 [Mu,Sigma]=HubertM(x)
this function computes the location and scatter parameters
 [Mu,Sigma]=NormalMLE(X)
 [Mu_shr, Sigma_shr]=Shrin...% standard sample estimate
 [Nu,Mu,Sigma]=FitT(x)
 [Nu,Mu,Sigma]=StudentMLE(x)
This function computes the maximumlikelihood estimate of the
 [newAt,newb,newc,newK,pre...[newAt,newb,newc,newK,prepinfo]=preprocessSDP(At,b,c,K)
 [x,info]=RobSocpMVPortf(m...this function transforms the SOCP meanvariance problem in SeDuMi format
 [x,y,K]=postprocessSDP(ne...[x,y,K]=postprocessSDP(newx,newy,prepinfo,newK)
 a2=PlotEstimatorStressTes...plot loss
 a2=PlotEstimatorStressTes...plot loss
 a2=PlotEstimatorStressTes...plot loss
 a2=PlotEstimatorStressTes...plot loss
 a2=PlotEstimatorStressTes...plot loss
 a2=PlotEstimatorStressTes...plot loss
 asmDxq(d, x, K, ddotx)
 blkchol(L,X,pars,absd)
 bwblkslv(L,b)
BWBLKSLV Solves block sparse uppertriangular system.
 bwdpr1(Lden, b)
 cellK(x,K)
 checkpars(pars,lponly)
pars = checkpars(pars,lponly)
 ddot(d,X,blkstart, Xblkjc)
 deninfac(symLden, L,dense...
 dpr1fact(x, d, Lsym, smul...
 e=FitError(gamma,X,Y,Corr...
 eigK(x,K)
 extractA(At,Ajc,blk0,blk1...Apart = extractA(At,Ajc,blk0,blk1,blkstart[,blkstart2])
 eyeK(K)
 findblks(At,Ablkjc,blk0,b...Ablk = findblks(At,Ablkjc,blk0,blk1,blkstart)
 finsymbden(LAD,perm,dz,fi...Lden = finsymbden(LAD,perm,dz,firstq)
 frameit(lab,frmq,frms,K)
 fwblkslv(L,b)
FWBLKSLV Solves block sparse uppertriangular system.
 fwdpr1(Lden, b)
 getDAt(At,Ablk,colsel, d,...
 getDAtm(A,Ablkjc,dense,DA...
 getada1(ADA, A,Ajc2,perm,...
 getada2(ADA, DAt,Aord, K)
 getada3(ADA, A,Ajc1,Aord,...
 getdense(At,Ablkjc,K,pars)
 getsymbada(At,Ablkjc,DAt,...SYMBADA = getsymbada(At,Ajc,DAt,psdblkstart)
 givensrot(gjc,g,x,K)
 h_ellips=TwoDimEllipsoid(...this function computes the locationdispersion ellipsoid
 incorder(At,Ajc1,ifirst)
 invcholfac(u,K, perm)
 iswnbr(w,thetaSQR)
 loopPcg(L,Lden,At,dense,d...
 makereal(x,K,cpx)
 mat(x,n)
 maxstep(dx,x,auxx,K)
 my_fprintf(fid, varargin)
This function is needed because Matlab R2006B does not support fprintf with
 optstep(A,b,c, y0,y,d,v,d...
 ordmmdmex(adjncy)
perm = ordmmdmex(adjncy)
 partitA(At,blkstart)
Ablkjc = partitA(At,blkstart)
 posttransfo(x,y,prep,K,pa...
 pretransfo(At,b,c,K,pars)
 psdeig(x,K)
 psdfactor(x,K)
 psdinvjmul(xlab,xfrm, y, K)
 psdmul(x,y, K)
 psdscale(ud,x,K [,transp])
 qblkmul(mu,d,blkstart)
 qframeit(lab,frmq,K)
 qinvjmul(labx,frmx,b,K)
 qjmul(x,y,K)
 qreshape(x,flag, K)
 quadadd(xhi,xlo,y)
 r2=R2(I_k,Cov_XX,Cov_XF,C...
 rotlorentz(c,K)
 sddir(L,Lden,Lsd,pv,...
 sdfactor(L,Lden, dense,DA...
 sdinit(At,b,c,dense,K,pars)
 sedumi(A,b,c,K,pars)
 sortnnz(At,Ajc1,Ajc2)
 sparbwslv(L,b)
SPARBWSLV Solves block sparse uppertriangular system.
 sparfwslv(L,b, ysymb)
SPARFWSLV Solves block sparse uppertriangular system.
 sparsity=spars(x)Returns the sparsity of the matrix/vector x. It works for sparse and dense
 sqrtinv(q,vlab,K)
 statsK(K)
 stepdif(d,R,y0,x,y,z,dy0,...
 symbchol(X,cachsz)
 symbcholden(L,dense,DAt)
Lden = symbcholden(L,dense,DAt)
 symfctmex(adjncy, perm, c...
 tdet(x,K)
 triumtriu(r,u,K)
 trydif(t,wrIN,wIN, x,z, p...
 updtransfo(x,z,w, dIN,K)
 urotorder(u,K, maxu,permIN)
 vec(X)
 veccomplex(x,cpx,K)
 vecsym(x,K)
 vectril(x,K)
 whichcpx(K)
 widelen(xc,zc,y0, dx,dz,d...
 wrapPcg(L,Lden,At,dense,d...
 Contents.m
 EstimateNGeneratePrior.m% estimation of prior market distribution and generation of Monte Carlo scenarios from this prior distribution:
 PlotBlackLittAllocation.m
 PlotDeceptionInMV.mwhat the investor believes...
 PlotEvaluationBayesian.m
 PlotEvaluationGeneric.moptimal allocation vs. allocation decision
 PlotEvaluationPrior.m
 PlotEvaluationSample.m
 PlotSampleInMV.mcompute budget constraint
 PlotTotalRetsVsRelativeRe...% absolute coordinates: variance  expected value
 S_AffineConstraint.mthis script shows the computation behind the analytical solution of the
 S_AnalyzeLognormalCorrela...this script analyzes the correlation of two jointly lognormal variables
 S_AnalyzeNIWPriorPosterior.mThis script familiarizes the users with multivariate Bayesian estimation.
 S_AnalyzeNormalCorrelation.mthis script analyzes the correlation of two jointly normal variables
 S_AssessNModifyViews.mthis script implements a simple technique to assess the impact of
 S_BlackLitterman.mthis script compares
 S_BlackLittermanVsBruteFo...this script compares the BlackLitterman approach to inputing views on the market
 S_BondPrices.mthis script shows that zerobond prices cannot be market invariants because
 S_COP.mthis script computes the COP posterior given
 S_CaseStudy.mthis script performs all the computations for a twostep optimal allocation,
 S_CaseStudyPCAEmprical.mthis script performs the principal component analysis of the swap curve. it computes and plots, among others,
 S_CaseStudyPCALimitContin...this script computes the PCA structure of the swap markets in the continuum limit
 S_CaseStudySwapDistributi...this script computes the PnL distribution at the investment horizon of a forward swap position
 S_CopulaMarginalDecomposi...this script generates a joint distribution with normal copula and arbitrary marginals
 S_CornishFisher.mthis script compares the CornishFisher estiamte of the VaR with the true analytical VaR
 S_DeceptionInMV.mthis script shows that the estimates of the meanvariance coordinates of a generic allocation,
 S_DifferentHorizons.mthis script shows how the efficient frontier depends on the investment horizon
 S_DisplayCopulaCDF.mthis script displays the cdf of the normal and t copulas
 S_DisplayCopulaPDF.mthis script displays the pdf of the copula
 S_DisplayLogTPDF.mthis script displays the pdfs of the logt distribution
 S_DisplayLognormalPDF.mthis script displays the pdfs of the lognormal distribution
 S_DisplayMleRecursionForT.mthis script demonstrates the recursive ML estimation of the location and scatter
 S_DisplayNormalPDF.mthis script displays the pdfs of the normal distribution
 S_DisplayRobustness.mthis script shows in terms of the locationdispersion ellipsoid how the sample
 S_DisplayRobustness.mthis script shows in terms of the locationdispersion ellipsoid how,
 S_DisplayTPDF.mthis script displays the pdfs of the Student t distribution
 S_DisplayUniformPDF.mthis script displays the pdfs of the uniform distribution on an ellipsoid
 S_DisplayWishartPDF.mthis script displays the pdfs of the 1x1 Wishart distribution,
 S_DiversificationCorrelat...this script shows the diversification effect of correlation in a simplified market of two variables
 S_DiversificationNumAssets.mthis script shows the diversification effect of increasing the number of securities in a market
 S_ES_Contributions.mthis script computes ES and contributions to ES from each exposure
 S_ES_is_HomogConcave.mthis script shows that (minus) the expected shortfall is a concave and homogeneous index of satisfaction
 S_EVT.mthis script compares the EVT and sample estimates of the VaR with the true analytical VaR
 S_EigenvalueDispersion.mthis script displays the scatteringofeigenvalues phenomenon
 S_EllipsoidGeometryVsStat...this script shows the relationship between geometry, algebra and statistics
 S_EllipsoidLogNormal.mthis script represents covariance and expected value in terms
 S_EllipsoidNormal.mthis script represents covariance and expected value in terms
 S_Elliptical2Dim.mthis script decomposes the bivariate normal distribution into its norm and uniform components
 S_Elliptical3Dim.mthis script decomposes the trivariate normal distribution into its norm and uniform components
 S_EllipticalNDim.mthis script decomposes the Nvariate normal distribution into its norm and uniform components
 S_EquitiesInvariants.mthis script performs the quest for invariance in the stock market
 S_EquivarianceLogNormal.mthis script shows the affine equivariance properties of expected value
 S_EquivarianceNormal.mthis script shows the affine equivariance properties of expected value
 S_EstimateExpectedValueEv...this script familiarizes the user with the evaluation of an estimator:
 S_EvaluationBayesian.mthis script evaluates the Bayesian allocation, which replaces the true, unknown market parameter
 S_EvaluationGeneric.mthis script evaluates a generic allocation decision (in this case the
 S_EvaluationPrior.mthis script evaluates a prior allocation decision (in this case the "equal weight" strategy
 S_EvaluationSample.mthis script evaluates the samplebased allocation, which replaces the true, unknown market parameter
 S_ExponentialUtil_is_Tran...this script shows that the certainty equivalent for exponential utility functions
 S_FixedIncomeInvariants.mthis script performs the quest for invariance in the bond market
 S_Gamma.mthis script familiarizes the user with the properties of the gamma
 S_GammaCdf.mthis script confirms that the analytical expression for the cdf of the gamma
 S_GenericCopula.mthis script simulates the copula of a generic distribution.
 S_Grades.mthis script shows how a generic distribution can be mapped into another arbitrary
 S_HighBreakdownMVE.mthis script shows how to use the minimum volume ellipsoid to detect outliers.
 S_Introduction.m
 S_KendallTau.mthis script simulates and computes analytically Kendall's tau
 S_KernelQuantile.mthis script computes the nonparametric kernel estimator of the quantile (value at risk)
 S_LeadingExample.mthis script performs the computations for the analytical example discussed
 S_LogNormal.mthis script simulates a bivariate lognormal distribution
 S_LogT.mthis script simulates a bivariate logt distribution
 S_LogTCopulaSimul.mthis script simulates the copula of a bivariate logt distribution
 S_Lognormal.mthis script familiarizes the user with some basic properties of the
 S_LognormalCopulaSimul.mthis script simulates the copula of a bivariate lognormal distribution
 S_MCMC.mThis script familiarizes the user with the MCMC approach to generate
 S_MissingValuesEM.mthis script implements the ExpectationMaximization (EM) algoritm, which estimates
 S_Motivation.mthis script highlights the issue of estimation risk: the "optimal" frontier estimated with
 S_MotivationsBL.mthis script shows the motivations for the BlackLitterman approach:
 S_NoEquivarianceMedian.mthis script is meant to show that the median is not affine equivariant
 S_Normal.mnormal distribution, see "Risk and Asset Allocation"Springer (2005), by A. Meucci
 S_Normal.mthis script simulates a bivariate normal distribution
 S_NormalCDF.mthis script computes the cdf of a bivariate normal distribution at a grid of points
 S_NormalCopulaSimul.mthis script simulates the copula of a bivariate normal distribution
 S_NormalMatrix.mthis script simulates a matrixvariate normal distribution
 S_OLS.mthis script illustrates the geometrica interpreation of the OLS estimator
 S_OptionsInvariants.mthis script performs the quest for invariance in the option market
 S_OrderStatistics.mthis script shows that the pdf of the rth order statistics is concentrated
 S_OrderStatisticsPDFCentr...this script shows that the pdf of the rth order statistics is concentrated
 S_OrderStatisticsPDFLogn.mthis script shows that the pdf of the rth order statistics is concentrated
 S_OrderStatisticsPDFStude...this script shows that the pdf of the rth order statistics is concentrated
 S_PCA2Dim.mthis script illustrates PCA dimension reduction in a simple bivariate case
 S_PCA3Dim.mthis script illustrates PCA dimension reduction in a trivariate case
 S_PCAvsRegression.mthis script compare PCA (implicit factors) with regression (explicit factors)
 S_PowerUtil_Contributions...since the certainty equivalent for a power utility functions is homogeneous
 S_PowerUtil_is_Homogeneous.mthis script shows that the certainty equivalent for a power utility functions
 S_PricesVsReturns.mthis script shows how to switch between
 S_PricingAnyOrder.mthis script shows how the goodness of the Taylor approximation
 S_PricingCallOption.mthis script shows how the goodness of the deltagammagammadelta approximation
 S_PriorCorrelationParamet...this script generates random correlation matrices by randomizing the
 S_PriorCorrelationUniform.mthis script shows how a jointly uniform prior on the correlations implies
 S_Projection_Beta.mthis script performs the horizon projection of a betadistributed invariant
 S_Projection_Gamma.mthis script performs the horizon projection of a gammadistributed invariant
 S_Projection_Lognormal.mthis script performs the horizon projection of a lognormal invariant
 S_Projection_NonParam.mthis script performs the horizon projection of an invariant whose
 S_Projection_T.mthis script performs the horizon projection of a tdistributed invariant
 S_ProspectTheory_isnot_Co...this script shows that the certainty equivalent for prospect theory
 S_Regression2Dim.mthis script illustrates regression dimension reduction in a simple bivariate case
 S_Regression3Dim.mthis script illustrates regression dimension reduction in a simple bivariate case
 S_Regularization.mthis script displyays the regularized empirical distribution
 S_RobustBayesMV.mthis script computes and displays the robust Bayesian allocation frontier, which shrinks the sample
 S_RobustBayesMVSimulations.mthis script computes and displays in the meanvariance coordinates
 S_RobustBayesSnP.mthis script compares robust Bayesian allocation, which shrinks the sample
 S_RobustMV.mthis script computes the robust meanvariance allocation by means of SOCP
 S_SampleMVCoordinates.mthis script shows the true meanvariance coordinates of the samplebased pseudooptimal allocation
 S_SampleMeanCov.mthis script shows that the sample mean and sample covariance correspond
 S_SatisfactionVsCorrelati...this script shows how overall correlation affects the maximum level of satisfaction, as measured
 S_SelectFactors.mthis script selects the best stocks to replicate an index. The same routine
 S_ShrinkageEstimators.mthis script computes the multivariate shrinkage estimators of location and scatter under the normal assumption
 S_SimulationsVsAnalytical.mthis script shows how the empirical distribution converges to the tre
 S_SimulationsVsAnalytical.mthis script shows how the empirical distribution converges to the tre
 S_SpearmanRho.mthis script computes Spearman's rho in simulation
 S_SphericallySymmetric.mthis script decomposes the bivariate normal distribution into its radial and uniform components
 S_StochasticDominanceNorm...this script shows that lowerorder dominance implies higherorder dominance
 S_StochasticDominanceNormT.mthis script shows that lowerorder dominance implies higherorder dominance
 S_StochasticDominanceUniB...this script shows that lowerorder dominance implies higherorder dominance
 S_StressCorrelation.mthis script evaluates a robust Mestimator (Huber) of location and scatter
 S_StressCorrelation.mthis script evaluates the shrinkage estimators of location and scatter under the
 S_StressCorrelation.mthis script evaluates the ML estimator of location and scatter under the
 S_StressCorrelation.mthis script evaluates the ML estimator of location and scatter under the
 S_StressLognormalMu.mthis script evaluates the ML estimator of location and scatter under the
 S_StressLognormalSigma.mthis script evaluates the ML estimator of location and scatter under the
 S_StressNormalMu.mthis script evaluates the ML estimator of location and scatter under the
 S_StressNormalSigma.mthis script evaluates the ML estimator of location and scatter under the
 S_StudentT.mthis script simulates a bivariate t distribution
 S_StudentT.mthis script familiarizes the user with some basic properties of the
 S_SwaptionsInvariants.mthis script performs the quest for invariance in the swaption market
 S_TCDF.mthis script computes the cdf of a bivariate t distribution at a grid of points
 S_TCopulaSimul.mthis script simulates the copula of a bivariate t distribution
 S_TotalRetsVsRelativeRets.mthis script performs all the computations for the comparison of totalreturn vs. benchmarkdriven allocation
 S_UnevenSeries.mthis script estimates the parameters of a multivariate normal distribution
 S_Uniform.mthis script simulates a bivariate uniform distribution on an ellipsoid
 S_Uniform.mthis script familiarizes the user with some basic properties of the
 S_UniformEllipsoid.mthis script generates a uniform sample on the interior of an ellipsoid in N dimensions
 S_UniformEllipsoid2.mthis script generates a uniform sample on the interior of an ellipsoid in
 S_VaRContributions.mthis script computes VaR and contributions to VaR from each exposure
 S_VaRContributions_Tdistr...this script computes VaR and contributions to VaR from each exposure
 S_VaR_is_HomogNotConcave.mthis script shows that the quantilebased index of satisfaction is not necessarily concave
 S_Wishart.mthis script generates a sample from the 2x2 Wishart distribution
 S_WishartCopulaSimul.mthis script simulates the copula of the diagonal elements of a 2x2 Wishart distribution
 ada_pcg.mA dummy file for Yalmip.
 install_sedumi.mSeDuMi installatino script

View all files
Risk and Asset Allocation
by
Attilio Meucci
16 Nov 2005
(Updated
10 Apr 2009)
Software for quantitative portfolio and risk management

S_SatisfactionVsCorrelation.m 
% this script shows how overall correlation affects the maximum level of satisfaction, as measured
% by the certainty equivalent of an exponential utility function in a multivariate normal market
% see "Risk and Asset Allocation"  Springer (2005), by A. Meucci
clc; clear; close all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% input investor's parameters
InvestorProfile.Budget=10000;
InvestorProfile.RiskPropensity=20;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% input market parameters
NumAssets=4;
Overall_Correlations=[0 :.01 : .99];
Min_EV=.03; Max_EV=.18; Step=(Max_EVMin_EV)/(NumAssets1);
Market.LinRets_EV = [Min_EV : Step : Max_EV]'; % hidden
Market.St_Devations = 2*Market.LinRets_EV; % hidden
Market.CurrentPrices=10*ones(NumAssets,1); % not hidden
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Store_CE=[];
for t=1:length(Overall_Correlations)
% input the remaining market parameters
Correlation = (1Overall_Correlations(t)) * eye(NumAssets) + Overall_Correlations(t) * ones(NumAssets,NumAssets);
Market.LinRets_Cov = diag(Market.St_Devations)*Correlation*diag(Market.St_Devations);
% compute optimal allocation
Market.Exp_Prices=diag(Market.CurrentPrices)*(1+Market.LinRets_EV);
Market.Cov_Prices=diag(Market.CurrentPrices)*Market.LinRets_Cov*diag(Market.CurrentPrices);
S=inv(Market.Cov_Prices);
A=Market.CurrentPrices'*S*Market.CurrentPrices;
B=Market.CurrentPrices'*S*Market.Exp_Prices;
Gamma = (InvestorProfile.Budget  InvestorProfile.RiskPropensity*B)/A;
Allocation = InvestorProfile.RiskPropensity*S*Market.Exp_Prices + Gamma*S*Market.CurrentPrices;
CE = Allocation'*Market.Exp_Prices 1/(2*InvestorProfile.RiskPropensity)*Allocation'*Market.Cov_Prices*Allocation;
Store_CE=[Store_CE; CE];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure % optimal allocation vs. fixed allocation
h=plot(Overall_Correlations,Store_CE);
grid on
box off


Contact us