My overall objective is to analyse the impact of error in mean-variance analysis from historical data. I am given the returns and standard deviation for the five assets under consideration, as well as the correlation matrix for the five assets. Using the functions mvnrnd to generate the monthly returns and frontcon for the efficient frontier. Three different time periods need to be analysed, 2, 30, and 150yrs. I have written the function below to try and calculate the average efficient frontiers, but it fails on the 150 yrs attempt with the message below. This is the my first time writing anything in MATLAB (which I need to use), so I am not 100% sure of my code. It does produce graphs for the 2 yr and 30 yr time period, but I don't know if the failure of the 150 yr is due to my bad programming or not. In particular I wasn't sure how to calculate the average covariance across the 10,000 simulations. Any help would be greatly appreciated. My code is below the error message.
> Warning: Candidate solution is infeasible due to a bad pivot. > In lcprog>lcprealitycheck at 294 > In lcprog at 251 In qplcprog at 247 > In portopt at 249 > In frontcon at 231 In AverageEfficientFrontiers at 36 > Error using portopt (line 256) > > No portfolios satisfy all input constraints for maximum-return > portfolio. Possibly unbounded problem. > > Error in frontcon (line 231) [PRisk, PRoR, PWts] = portopt(ERet, > ECov, NPts, RTarget, ConSet, ... > > Error in AverageEfficientFrontiers (line 36) [Risk, Return, Weights] = > frontcon(AverageReturn, AverageCovariance, 10);" function  = AverageEfficientFrontiers( Years, Simulations ) AssetReturns = [0.006,0.01,0.014,0.018,0.022]; AssetStDev = [0.085,0.08,0.095,0.09,0.1]; CorrelationMatrix = [1,0.3,0.3,0.3,0.3; 0.3,1,0.3,0.3,0.3; 0.3,0.3,1,0.3,0.3; 0.3,0.3,0.3,1,0.3; 0.3,0.3,0.3,0.3,1]; Months = Years*12; CovarianceMatrix = corr2cov(AssetStDev,CorrelationMatrix); % Preallocating avoids the need for MATLAB to copy the data from one array % to another inside the loop TotalCumulativeReturn = zeros(Simulations,5); PeriodCovariance = zeros(Simulations,5,5); for i=1:Simulations MonthlyReturns = mvnrnd(AssetReturns,CovarianceMatrix,Months); % If A is a nonempty matrix, then prod(A) treats the columns of A as % vectors and returns a row vector of the products of each column. % A(i,:) is the ith row of A. TotalCumulativeReturn(i,:) = prod(1+MonthlyReturns)-1; % For matrix input X, where each row is an observation, and each column % is a variable, cov(X) is the covariance matrix. % http://www.mathworks.co.uk/help/matlab/ref/cov.html PeriodCovariance(i,:,:) = cov(MonthlyReturns)*Months; end % If A is a nonempty, nonvector matrix, then mean(A) treats the columns of % A as vectors and returns a row vector whose elements are the mean of each % column. AverageReturn = mean(TotalCumulativeReturn); AverageCovariance = mean(PeriodCovariance); % http://www.mathworks.co.uk/help/matlab/ref/reshape.html AverageCovariance = reshape(AverageCovariance, [5,5]); [Risk, Return, Weights] = frontcon(AverageReturn, AverageCovariance, 10); plot(Risk, Return); end