| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Financial Toolbox |
| Contents | Index |
| Learn more about Financial Toolbox |
RetSeries = portsim(ExpReturn, ExpCovariance, NumObs, RetIntervals, NumSim, Method)
ExpReturn | 1 by number of assets (NASSETS) vector specifying the expected (mean) return of each asset. |
ExpCovariance | NASSETS-by-NASSETS matrix of asset return covariances. ExpCovariance must be symmetric and positive semidefinite (no negative eigenvalues). The standard deviations of the returns are ExpSigma = sqrt(diag(ExpCovariance)). |
NumObs | Positive scalar integer indicating the number of consecutive observations in the return time series. If NumObs is entered as the empty matrix [], the length of RetIntervals is used. |
RetIntervals | (Optional) Positive scalar or number of observations (NUMOBS)-by-1 vector of interval times between observations. If RetIntervals is not specified, all intervals are assumed to have length 1. |
NumSim | (Optional) Positive scalar integer indicating the number of simulated sample paths (realizations) of NUMOBS observations. Default = 1 (single realization of NUMOBS correlated asset returns). |
Method | (Optional) String indicating the type of Monte Carlo simulation: 'Exact' (default) generates correlated asset returns in which the sample mean and covariance match the input mean (ExpReturn) and covariance (ExpCovariance) specifications. 'Expected' generates correlated asset returns in which the sample mean and covariance are statistically equal to the input mean and covariance specifications. (The expected value of the sample mean and covariance are equal to the input mean (ExpReturn) and covariance (ExpCovariance) specifications.) For either method the sample mean and covariance returned are appropriately scaled by RetIntervals. |
portsim simulates correlated returns of NASSETS assets over NUMOBS consecutive observation intervals. Asset returns are simulated as the proportional increments of constant drift, constant volatility stochastic processes, thereby approximating continuous-time geometric Brownian motion.
RetSeries is a NUMOBS-by-NASSETS-by-NUMSIM three-dimensional
array of correlated, normally distributed, proportional asset returns.
Asset returns over an interval of length
are given by
![]()
where
is
the asset price,
is
the expected rate of return,
is
the volatility of the asset price, and
represents a random drawing from a standardized
normal distribution.
Notes
|
Example 1. Distinction Between Simulation Methods
This example highlights 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);
ExpCovariance =
1.0e-003 *
0.0904 0.0597 0.0686 0.0456 0.0709
0.0597 0.2033 0.1649 0.1232 0.0674
0.0686 0.1649 0.2319 0.1175 0.0816
0.0456 0.1232 0.1175 0.1224 0.0516
0.0709 0.0674 0.0816 0.0516 0.1183
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.
randn('state',0);
RetExact = portsim(ExpReturn, ExpCovariance, NumObs, ...
RetIntervals, NumSim, 'Exact');
randn('state',0);
RetExpected = portsim(ExpReturn, ExpCovariance, NumObs, ...
RetIntervals, NumSim, 'Expected');
If you 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')

Example 2. Interaction Between ExpReturn, ExpCovariance and RetIntervals
Recall that portsim simulates correlated
asset returns over an interval of length
, given by the equation
![]()
where
is
the asset price,
is
the expected rate of return,
is
the volatility of the asset price, and
represents a random drawing from a standardized
normal distribution.
The time increment
is
determined by the optional input RetIntervals,
either as an explicit input argument or as a unit time increment by
default. Regardless, the periodicity of ExpReturn, ExpCovariance and RetIntervals must
be consistent. For example, if ExpReturn and ExpCovariance are
annualized, then RetIntervals must be in years.
This point is often misunderstood.
To illustrate the interplay among ExpReturn, ExpCovariance, and RetIntervals, consider a portfolio of five assets with the following expected returns, standard deviations, and correlation matrix based on daily asset 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 of daily returns.
ExpCovariance = corr2cov(Sigmas, Correlations);
Assume 252 trading days per calendar year, and simulate a single sample path of daily returns over a four-year period. Since the ExpReturn and ExpCovariance inputs are expressed daily, set RetIntervals = 1.
StartPrice = 100;
NumObs = 1008; % four calendar years of daily returns
RetIntervals = 1; % one trading day
NumAssets = length(ExpReturn);
randn('state',0);
RetSeries1 = portsim(ExpReturn, ExpCovariance, NumObs, ...
RetIntervals, 1, 'Expected');
Now annualize the daily data, thereby changing the periodicity of the data, by multiplying ExpReturn and ExpCovariance by 252 and dividing RetIntervals by 252 (RetIntervals = 1/252 of a year).
Resetting the random number generator to its initial state, you can reproduce the results.
randn('state',0);
RetSeries2 = portsim(ExpReturn*252, ExpCovariance*252, ...
NumObs, RetIntervals/252, 1, 'Expected');
Assume an equally weighted portfolio and compute portfolio returns associated with each simulated return series.
Weights = ones(NumAssets, 1)/NumAssets; PortRet1 = RetSeries2 * Weights; PortRet2 = RetSeries2 * Weights;
Comparison of the data reveals that PortRet1 and PortRet2 are identical.
Example 3. Univariate Geometric Brownian Motion
This example simulates a univariate geometric Brownian motion process. It is based on an example found in Hull, Options, Futures, and Other Derivatives, 5th Edition (see example 12.2 on page 236). In addition to verifying Hull's example, it also graphically illustrates the lognormal property of terminal stock prices by a rather large Monte Carlo simulation.
First, assume you own a stock with an initial price of $20, an annualized expected return of 20% and volatility of 40%. Simulate the daily price process for this stock over the course of one full calendar year (252 trading days).
StartPrice = 20; ExpReturn = 0.2; ExpCovariance = 0.4^2; NumObs = 252; NumSim = 10000; RetIntervals = 1/252;
Note that RetIntervals is expressed in years, consistent with the fact that ExpReturn and ExpCovariance are annualized. Also, note that ExpCovariance is entered as a variance rather than the more familiar standard deviation (volatility).
Now set the random number generator state, and simulate 10,000 trials (realizations) of stock returns over a full calendar year of 252 trading days.
randn('state',10);
RetSeries = squeeze(portsim(ExpReturn, ExpCovariance, NumObs, ...
RetIntervals, NumSim, 'Expected'));
The squeeze function reformats the output array of simulated returns from a 252-by-1-by-10000 array to more convenient 252-by-10000 array. (Recall that portsim is fundamentally a multivariate simulation engine).
In accordance with Hull's equations 12.4 and 12.5 on page 236
![]()
![]()
convert the simulated return series to a price series and compute the sample mean and the variance of the terminal stock prices.
StockPrices = ret2tick(RetSeries, repmat(StartPrice, 1, NumSim)); SampMean = mean(StockPrices(end,:)) SampMean = 24.4587 SampVar = var(StockPrices(end,:)) SampVar = 104.2016
Compare these values with the values you obtain by using Hull's equations.
ExpValue = StartPrice*exp(ExpReturn) ExpValue = 24.4281 ExpVar = ... StartPrice*StartPrice*exp(2*ExpReturn)*(exp((ExpCovariance)) - 1) ExpVar = 103.5391
These results are very close to the results shown in Hull's example 12.2.
Next, display the sample density function of the terminal stock price after one calendar year. From the sample density function, the lognormal distribution of terminal stock prices is apparent.
[count, BinCenter] = hist(StockPrices(end,:), 30);
figure
bar(BinCenter, count/sum(count), 1, 'r')
xlabel('Terminal Stock Price')
ylabel('Probability')
title('Lognormal Terminal Stock Prices')

Hull, John, C., Options, Futures, and Other Derivatives, Upper Saddle River, New Jersey: Prentice-Hall. 5th ed., 2003, ISBN 0-13-009056-5.
ewstats, portopt, portstats, randn, ret2tick
![]() | portror | portstats | ![]() |
View demos and recorded presentations led by industry experts.
Now On Demand
Network with industry peers and learn the latest applications of the leading software product for computational finance.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |