%% Distinction Between Simulation Methods
% This example shows the distinction between the Exact and Expected methods of simulation.
% Consider a portfolio of five assets with the following expected returns, standard deviations, and correlation matrix based on daily asset returns (where ExpReturn and Sigmas are divided by 100 to convert percentages to returns).

ExpReturn     = [0.0246  0.0189  0.0273  0.0141  0.0311]/100;
Sigmas        = [0.9509  1.4259  1.5227  1.1062  1.0877]/100;
Correlations  = [1.0000  0.4403  0.4735  0.4334  0.6855
                 0.4403  1.0000  0.7597  0.7809  0.4343
                 0.4735  0.7597  1.0000  0.6978  0.4926
                 0.4334  0.7809  0.6978  1.0000  0.4289
                 0.6855  0.4343  0.4926  0.4289  1.0000];

%
% Convert the correlations and standard deviations to a covariance matrix.

ExpCovariance = corr2cov(Sigmas, Correlations)

%
% Assume that there are 252 trading days in a calendar year, and simulate two sample paths (realizations) of daily returns over a two-year period. Since ExpReturn and ExpCovariance are expressed daily, set RetIntervals = 1.

StartPrice    = 100;
NumObs        = 504;  % two calendar years of daily returns
NumSim        = 2;
RetIntervals  = 1;    % one trading day
NumAssets     = 5;

%
% To illustrate the distinction between methods, simulate two paths by each method, starting with the same random number state.

rng('default'); 
RetExact = portsim(ExpReturn, ExpCovariance, NumObs, ... 
RetIntervals, NumSim, 'Exact');
rng(0); 
RetExpected = portsim(ExpReturn, ExpCovariance, NumObs, ... 
RetIntervals, NumSim, 'Expected');

% Compare the mean and covariance of RetExact with the inputs (ExpReturn and ExpCovariance), you will observe that they are almost identical.
%
% At this point, RetExact and RetExpected are both 504-by-5-by-2 arrays. Now assume an equally weighted portfolio formed from the five assets and create arrays of portfolio returns in which each column represents the portfolio return of the corresponding sample path of the simulated returns of the five assets. The portfolio arrays PortRetExact and PortRetExpected are 504-by-2 matrices.

Weights         = ones(NumAssets, 1)/NumAssets;
PortRetExact    = zeros(NumObs, NumSim);
PortRetExpected = zeros(NumObs, NumSim);

for i = 1:NumSim
    PortRetExact(:,i)    = RetExact(:,:,i) * Weights;
    PortRetExpected(:,i) = RetExpected(:,:,i) * Weights; 
end

%
% Finally, convert the simulated portfolio returns to prices and plot the data. In particular, note that since the Exact method matches expected return and covariance, the terminal portfolio prices are virtually identical for each sample path. This is not true for the Expected simulation method. Although this example examines portfolios, the same methods apply to individual assets as well. Thus, Exact simulation is most appropriate when unique paths are required to reach the same terminal prices.

PortExact   = ret2tick(PortRetExact, ... 
repmat(StartPrice,1,NumSim)); 
PortExpected = ret2tick(PortRetExpected, ... 
repmat(StartPrice,1,NumSim)); 
subplot(2,1,1), plot(PortExact, '-r')
ylabel('Portfolio Prices')
title('Exact Method')
subplot(2,1,2), plot(PortExpected, '-b')
ylabel('Portfolio Prices')
title('Expected Method')

% Copyright 2012 The MathWorks, Inc.