portsim
Monte Carlo simulation of correlated asset returns
Syntax
Description
simulates correlated returns ofRetSeries
= portsim(ExpReturn
,ExpCovariance
,NumObs
)NASSETS
assets overNUMOBS
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.
Note
An alternative for portfolio optimization is to use thePortfolio
object for mean-variance portfolio optimization. This object supports gross or net portfolio returns as the return proxy, the variance of portfolio returns as the risk proxy, and a portfolio set that is any combination of the specified constraints to form a portfolio set. For information on the workflow when usingPortfolio
objects, seePortfolio Object Workflow.
specifies options using one or more optional arguments in addition to the input arguments in the previous syntax.RetSeries
= portsim(___,RetIntervals
,NumSim
,Method
)
Examples
Distinction Between Simulation Methods
This example shows the distinction between theExact
andExpected
methods of simulation.
Consider a portfolio of five assets with the following expected returns, standard deviations, and correlation matrix based on daily asset returns (whereExpReturn
andSigmas
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 =5×510-3× 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. SinceExpReturn
andExpCovariance
are expressed daily, setRetIntervals = 1
.
StartPrice = 100; NumObs = 504;% two calendar years of daily returnsNumSim = 2; RetIntervals = 1;% one trading dayNumAssets = 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 ofRetExact
with the inputs (ExpReturn
andExpCovariance
), you will observe that they are almost identical.
At this point,RetExact
andRetExpected
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 arraysPortRetExact
andPortRetExpected
are 504-by-2 matrices.
Weights = ones(NumAssets, 1)/NumAssets; PortRetExact = zeros(NumObs, NumSim); PortRetExpected = zeros(NumObs, NumSim);fori = 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 theExact
method matches expected return and covariance, the terminal portfolio prices are virtually identical for each sample path. This is not true for theExpected
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')
Interaction BetweenExpReturn
,ExpCovariance
, andRetIntervals
This example shows the interplay amongExpReturn
,ExpCovariance
, andRetIntervals
. Recall thatportsim
simulates correlated asset returns over an interval of lengthdt, given by the equation
whereSis the asset price,μis the expected rate of return,σ资产价格的波动,εrepresents a random drawing from a standardized normal distribution.
The time incrementdtis determined by the optional inputRetIntervals
, either as an explicit input argument or as a unit time increment by default. Regardless, the periodicity ofExpReturn
,ExpCovariance
, andRetIntervals
must be consistent. For example, ifExpReturn
andExpCovariance
are annualized, thenRetIntervals
must be in years. This point is often misunderstood.
To illustrate the interplay amongExpReturn
,ExpCovariance
, andRetIntervals
, 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 theExpReturn
andExpCovariance
inputs are expressed daily, setRetIntervals = 1
.
StartPrice = 100; NumObs = 1008;% four calendar years of daily returnsRetIntervals = 1;% one trading dayNumAssets = 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 multiplyingExpReturn
andExpCovariance
by 252 and dividingRetIntervals
by 252 (RetIntervals
= 1/252 of a year). Resetting the random number generator to its initial state, you can reproduce the results.
rng('default'); 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 thatPortRet1
andPortRet2
are identical.
Univariate Geometric Brownian Motion
This example shows how to simulate 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.
Assume that 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;
RetIntervals
is expressed in years, consistent with the fact thatExpReturn
andExpCovariance
are annualized. Also,ExpCovariance
is entered as a variance rather than the more familiar standard deviation (volatility).
Set the random number generator state, and simulate 10,000 trials (realizations) of stock returns over a full calendar year of 252 trading days.
rng('default'); RetSeries = squeeze(portsim(ExpReturn, ExpCovariance, NumObs,...RetIntervals, NumSim,'Expected'));
Thesqueeze
function reformats the output array of simulated returns from a252
-by-1
-by-10000
array to more convenient252
-by-10000
array. (Recall thatportsim
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,:)) SampVar = var(StockPrices(end,:))
SampMean = 24.4489 SampVar = 101.4243
Compare these values with the values you obtain by using Hull's equations.
ExpValue = StartPrice*exp(ExpReturn) ExpVar =...StartPrice*StartPrice*exp(2*ExpReturn)*(exp((ExpCovariance)) - 1)
ExpValue = 24.4281 ExpVar = 103.5391
These results are very close to the results shown in Hull's example 12.2.
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')
Input Arguments
ExpReturn
—Expected (mean) return of each asset
vector
Expected (mean) return of each asset, specified as a1
-by-NASSETS
vector.
Data Types:double
ExpCovariance
—Asset return covariances
matrix
Asset return covariances, specified as anNASSETS
-by-NASSETS
matrix.ExpCovariance
必须对称半正定(没有不gative eigenvalues). The standard deviations of the returns areExpSigma = sqrt(diag(ExpCovariance))
. IfExpCovariance
is not a symmetric positive semidefinite matrix, usenearcorr
to create a positive semidefinite matrix for a correlation matrix.
Data Types:double
NumObs
—Number of consecutive observations in the return time series
positive scalar integer
number of consecutive observations in the return time series, specified as a positive scalar integer. IfNumObs
is entered as the empty matrix[]
, the length ofRetIntervals
is used.
Data Types:double
RetIntervals
—Interval times between observations
1
(default) |positive scalar|vector
(Optional) Interval times between observations, specified as a positive scalar or a number of observationsNUMOBS
-by-1
vector. IfRetIntervals
is not specified, all intervals are assumed to have length1
.
Data Types:double
NumSim
—Number of simulated sample paths (realizations) ofNUMOBS
observations
1
(default) |positive scalar integer
(Optional) Number of simulated sample paths (realizations) ofNUMOBS
observations, specified as a positive scalar integer. The default value forNumSim
is1
(single realization ofNUMOBS
correlated asset returns).
Data Types:double
Method
—Type of Monte Carlo simulation
'Exact'
(default) |character vector
(Optional) Type of Monte Carlo simulation, specified as a character vector with one of the following values:
'Exact'
(默认)生成相关wh的资产回报ich 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 values of the sample mean and covariance are equal to the input mean (ExpReturn
) and covariance (ExpCovariance
) specifications.)
For eitherMethod
, the sample mean and covariance returned are appropriately scaled byRetIntervals
.
Data Types:char
Output Arguments
RetSeries
— Three-dimensional array of correlated, normally distributed, proportional asset returns
array
Three-dimensional array of correlated, normally distributed, proportional asset returns, returned as aNUMOBS
-by-NASSETS
-by-NUMSIM
three-dimensional array.
Asset returns over an interval of lengthdtare given by
whereSis the asset price,μis the expected rate of return,σ资产价格的波动,εrepresents a random drawing from a standardized normal distribution.
Notes
When
Method
is'Exact'
, the sample mean and covariance of all realizations (scaled byRetIntervals
) match the input mean and covariance. When the returns are then converted to asset prices, all terminal prices for a given asset are in close agreement. Although all realizations are drawn independently, they produce similar terminal asset prices. SetMethod
to'Expected'
to avoid this behavior.The returns from the portfolios in
PortWts
are given byPortReturn = PortWts * RetSeries(:,:,1)'
, wherePortWts
is a matrix in which each row contains the asset allocations of a portfolio. Each row ofPortReturn
corresponds to one of the portfolios identified inPortWts
, and each column corresponds to one of the observations taken from the first realization (the first plane) inRetSeries
. Seeportopt
andportstats
for portfolio specification and optimization.
References
[1] Hull, J. C.Options, Futures, and Other Derivatives.Prentice-Hall, 2003.
Version History
Introduced before R2006a
Beispiel öffnen
Sie haben eine geänderte Version dieses Beispiels. Möchten Sie dieses Beispiel mit Ihren Änderungen öffnen?
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- 西班牙(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)