The CVaR of a portfolio is a conditional expectation. (For the definition of the CVaR function, see Risk Proxy.) Therefore, the CVaR portfolio optimization problem is a stochastic optimization problem. Given a sample of scenarios, the conditional expectation that defines the sample CVaR of the portfolio can be expressed as a finite sum, a weighted average of losses. The weights of the losses depend on their relative magnitude; for a confidence level α, only the worst (1 − α) x 100% losses get a positive weight. As a function of the portfolio weights, the CVaR of the portfolio is a convex function (see [48], [49] Rockafellar & Uryasev at Portfolio Optimization). It is also a nonsmooth function, but its edges are less sharp as the sample size increases.
There are reformulations of the CVaR portfolio optimization
problem (see [48], [49] at Rockafellar & Uryasev) that result
in a linear programming problem, which can be solved either with standard
linear programming techniques or with stochastic programming solvers.
The PortfolioCVaR object, however, does not reformulate the problem
in such a manner. The PortfolioCVaR object computes the CVaR as a
nonlinear function. The convexity of the CVaR, as a function of the
portfolio weights and the dull edges when the number of scenarios
is large, make the CVaR portfolio optimization problem tractable,
in practice, for certain nonlinear programming solvers, such as fmincon
from Optimization Toolbox™.
The problem can also be solved using a cutting-plane method (see Kelley
[45] at Portfolio Optimization).
For more information, see Algorithms section of setSolver
. To learn more about the workflow
when using PortfolioCVaR objects, see PortfolioCVaR Object Workflow.
Since conditional value-at-risk portfolio optimization works with scenarios of asset returns to perform the optimization, several ways exist to specify and simulate scenarios. In many applications with CVaR portfolio optimization, asset returns may have distinctly nonnormal probability distributions with either multiple modes, binning of returns, truncation of distributions, and so forth. In other applications, asset returns are modeled as the result of various simulation methods that might include Monte-Carlo simulation, quasi-random simulation, and so forth. In many cases, the underlying probability distribution for risk factors may be multivariate normal but the resultant transformations are sufficiently nonlinear to result in distinctively nonnormal asset returns.
For example, this occurs with bonds and derivatives. In the case of bonds with a nonzero probability of default, such scenarios would likely include asset returns that are −100% to indicate default and some values slightly greater than −100% to indicate recovery rates.
Although the PortfolioCVaR object has functions to simulate
multivariate normal scenarios from either data or moments (simulateNormalScenariosByData
and simulateNormalScenariosByMoments
), the
usual approach is to specify scenarios directly from your own simulation
functions. These scenarios are entered directly as a matrix with
a sample for all assets across each row of the matrix and with samples
for an asset down each column of the matrix. The architecture of the
CVaR portfolio optimization tools references the scenarios through
a function handle so scenarios that have been set cannot be accessed
directly as a property of the PortfolioCVaR object.
Suppose that you have a matrix of scenarios in the AssetScenarios
variable.
The scenarios are set through the PortfolioCVaR
function
with:
m = [ 0.05; 0.1; 0.12; 0.18 ];
C = [ 0.0064 0.00408 0.00192 0;
0.00408 0.0289 0.0204 0.0119;
0.00192 0.0204 0.0576 0.0336;
0 0.0119 0.0336 0.1225 ];
m = m/12;
C = C/12;
AssetScenarios = mvnrnd(m, C, 20000);
p = PortfolioCVaR('Scenarios', AssetScenarios);
disp(p.NumAssets);
disp(p.NumScenarios);
4 20000
Notice that the PortfolioCVaR object determines and fixes the
number of assets in NumAssets
and the number of
scenarios in NumScenarios
based on the scenario's
matrix. You can change the number of scenarios by calling the PortfolioCVaR
function with a different
scenario matrix. However, once the NumAssets
property
has been set in the object, you cannot enter a scenario matrix with
a different number of assets. The getScenarios
function
lets you recover scenarios from a PortfolioCVaR object. You can also
obtain the mean and covariance of your scenarios using estimateScenarioMoments
.
Although not recommended for the casual user, an alternative
way exists to recover scenarios by working with the function handle
that points to scenarios in the PortfolioCVaR object. To access some
or all of the scenarios from a PortfolioCVaR object, the hidden property localScenarioHandle
is
a function handle that points to a function to obtain scenarios that
have already been set. To get scenarios directly from a PortfolioCVaR
object p
, use
scenarios = p.localScenarioHandle([], []);
startrow
to endrow
,
usescenarios = p.localScenarioHandle(startrow, endrow);
1
≤ startrow
≤ endrow
≤ numScenarios
.You can also set scenarios using setScenarios
.
For example, given the mean and covariance of asset returns in the
variables m
and C
, the asset
moment properties can be set:
m = [ 0.05; 0.1; 0.12; 0.18 ]; C = [ 0.0064 0.00408 0.00192 0; 0.00408 0.0289 0.0204 0.0119; 0.00192 0.0204 0.0576 0.0336; 0 0.0119 0.0336 0.1225 ]; m = m/12; C = C/12; AssetScenarios = mvnrnd(m, C, 20000); p = PortfolioCVaR; p = setScenarios(p, AssetScenarios); disp(p.NumAssets); disp(p.NumScenarios);
4 20000
The estimateScenarioMoments
function
obtains estimates for the mean and covariance of scenarios in a PortfolioCVaR
object.
m = [ 0.05; 0.1; 0.12; 0.18 ]; C = [ 0.0064 0.00408 0.00192 0; 0.00408 0.0289 0.0204 0.0119; 0.00192 0.0204 0.0576 0.0336; 0 0.0119 0.0336 0.1225 ]; m = m/12; C = C/12; AssetScenarios = mvnrnd(m, C, 20000); p = PortfolioCVaR; p = setScenarios(p, AssetScenarios); [mean, covar] = estimateScenarioMoments(p)
mean = 0.0043 0.0085 0.0098 0.0153 covar = 0.0005 0.0003 0.0002 0.0000 0.0003 0.0024 0.0017 0.0010 0.0002 0.0017 0.0049 0.0029 0.0000 0.0010 0.0029 0.0102
As a convenience, the two functions (simulateNormalScenariosByData
and simulateNormalScenariosByMoments
) exist
to simulate scenarios from data or moments under an assumption that
they are distributed as multivariate normal random asset returns.
Given either return or price data, use the function simulateNormalScenariosByData
to simulate
multivariate normal scenarios. Either returns or prices are stored
as matrices with samples going down the rows and assets going across
the columns. In addition, returns or prices can be stored in a financial
time series fints
object (see Simulating Normal Scenarios from Time Series Data). To illustrate
using simulateNormalScenariosByData
,
generate random samples of 120 observations of asset returns for four
assets from the mean and covariance of asset returns in the variables m
and C
with portsim
. The default behavior of portsim
creates simulated data with estimated
mean and covariance identical to the input moments m
and C
.
In addition to a return series created by portsim
in
the variable X, a price series is created in the
variable Y:
m = [ 0.0042; 0.0083; 0.01; 0.15 ]; C = [ 0.005333 0.00034 0.00016 0; 0.00034 0.002408 0.0017 0.000992; 0.00016 0.0017 0.0048 0.0028; 0 0.000992 0.0028 0.010208 ]; X = portsim(m', C, 120); Y = ret2tick(X);
Note: Portfolio optimization requires that you use total returns and not just price returns. So, "returns" should be total returns and "prices" should be total return prices. |
Given asset returns and prices in variables X and Y from
above, this sequence of examples demonstrates equivalent ways to simulate
multivariate normal scenarios for the PortfolioCVaR object. Assume
a PortfolioCVaR object created in p
that uses the
asset returns in X uses simulateNormalScenariosByData
:
p = PortfolioCVaR; p = simulateNormalScenariosByData(p, X, 20000); [passetmean, passetcovar] = estimateScenarioMoments(p)
passetmean = 0.0043 0.0083 0.0102 0.1507 passetcovar = 0.0053 0.0003 0.0002 0.0000 0.0003 0.0024 0.0017 0.0010 0.0002 0.0017 0.0049 0.0028 0.0000 0.0010 0.0028 0.0101
The default behavior of simulateNormalScenariosByData
is
to work with asset returns. If, instead, you have asset prices as
in the variable Y, simulateNormalScenariosByData
accepts
a name-value pair argument name 'DataFormat'
with
a corresponding value set to 'prices'
to indicate
that the input to the function is in the form of asset prices and
not returns (the default value for the 'DataFormat'
argument
is 'returns'
). This example simulates scenarios
with the asset price data in Y for the PortfolioCVaR
object q
:
p = PortfolioCVaR; p = simulateNormalScenariosByData(p, Y, 20000, 'dataformat', 'prices'); [passetmean, passetcovar] = estimateScenarioMoments(p)
passetmean = 0.0043 0.0084 0.0094 0.1490 passetcovar = 0.0054 0.0004 0.0001 -0.0000 0.0004 0.0024 0.0016 0.0009 0.0001 0.0016 0.0048 0.0028 -0.0000 0.0009 0.0028 0.0100
Often when working with multiple assets, you have missing data
indicated by NaN
values in your return or price
data. Although Multivariate Normal Regression goes into detail about regression
with missing data, the simulateNormalScenariosByData
function
has a name-value pair argument name 'MissingData'
that
indicates with a Boolean value whether to use the missing data capabilities
of Financial Toolbox™. The default value for 'MissingData'
is false
which
removes all samples with NaN
values. If, however, 'MissingData'
is
set to true
, simulateNormalScenariosByData
uses
the ECM algorithm to estimate asset moments. This example shows how
this works on price data with missing values:
m = [ 0.0042; 0.0083; 0.01; 0.15 ]; C = [ 0.005333 0.00034 0.00016 0; 0.00034 0.002408 0.0017 0.000992; 0.00016 0.0017 0.0048 0.0028; 0 0.000992 0.0028 0.010208 ]; X = portsim(m', C, 120); Y = ret2tick(X); Y(1:20,1) = NaN; Y(1:12,4) = NaN;
Notice that the prices above in Y
have missing
values in the first and fourth series.
p = PortfolioCVaR; p = simulateNormalScenariosByData(p, Y, 20000, 'dataformat', 'prices'); q = PortfolioCVaR; q = simulateNormalScenariosByData(q, Y, 20000, 'dataformat', 'prices', 'missingdata', true); [passetmean, passetcovar] = estimateScenarioMoments(p) [qassetmean, qassetcovar] = estimateScenarioMoments(q)
passetmean = 0.0020 0.0074 0.0078 0.1476 passetcovar = 0.0055 0.0003 -0.0001 -0.0003 0.0003 0.0024 0.0019 0.0012 -0.0001 0.0019 0.0050 0.0028 -0.0003 0.0012 0.0028 0.0101 qassetmean = 0.0024 0.0085 0.0106 0.1482 qassetcovar = 0.0071 0.0004 -0.0001 -0.0004 0.0004 0.0032 0.0022 0.0012 -0.0001 0.0022 0.0063 0.0034 -0.0004 0.0012 0.0034 0.0127
p
, contains scenarios obtained
from price data in Y
where NaN
values
are discarded and the second PortfolioCVaR object, q
,
contains scenarios obtained from price data in Y
that
accommodate missing values. Each time you run this example, you get
different estimates for the moments in p
and q
. The simulateNormalScenariosByData
function
also accepts asset returns or prices stored in financial time series
(fints
) objects. The function
implicitly works with matrices of data or data in a fints
object using the same rules for
whether the data are returns or prices. To illustrate, use fints
to create the fints
object Xfts
that
contains asset returns generated with fints
(see Estimating Asset Moments from Prices or Returns)
and add series labels:
m = [ 0.0042; 0.0083; 0.01; 0.15 ]; C = [ 0.005333 0.00034 0.00016 0; 0.00034 0.002408 0.0017 0.000992; 0.00016 0.0017 0.0048 0.0028; 0 0.000992 0.0028 0.010208 ]; X = portsim(m', C, 120); d = (datenum('31-jan-2001'):datenum('31-dec-2010'))'; Xfts = fints(d, zeros(numel(d),4), {'Bonds', 'LargeCap', 'SmallCap', 'Emerging'}); Xfts = tomonthly(Xfts); Xfts.Bonds = X(:,1); Xfts.LargeCap = X(:,2); Xfts.SmallCap = X(:,3); Xfts.Emerging = X(:,4); p = PortfolioCVaR; p = simulateNormalScenariosByData(p, Xfts, 20000); [passetmean, passetcovar] = estimateScenarioMoments(p)
passetmean = 0.0044 0.0082 0.0102 0.1504 passetcovar = 0.0054 0.0004 0.0002 -0.0000 0.0004 0.0024 0.0017 0.0010 0.0002 0.0017 0.0047 0.0027 -0.0000 0.0010 0.0027 0.0102
The name-value inputs 'DataFormat'
to handle
return or price data and'MissingData'
to ignore
or use samples with missing values also work for fints
data. In addition, simulateNormalScenariosByData
extracts
asset names or identifiers from a fints
object
if the argument name 'GetAssetList'
is set to true
(the
default value is false
). If the 'GetAssetList'
value
is true
, the identifiers are used to set the AssetList
property
of the PortfolioCVaR object. Thus, repeating the formation of the
PortfolioCVaR object q
from the previous example
with the 'GetAssetList'
flag set to true
extracts
the series labels from the fints
object:
p = simulateNormalScenariosByData(p, Xfts, 20000, 'getassetlist', true);
disp(p.AssetList)
'Bonds' 'LargeCap' 'SmallCap' 'Emerging'
If you set the'GetAssetList'
flag set to true
and
your input data is in a matrix, simulateNormalScenariosByData
uses
the default labeling scheme from setAssetList
as
described in Setting Up a List of Asset Identifiers.
Given the mean and covariance of asset returns, use the simulateNormalScenariosByMoments
function
to simulate multivariate normal scenarios. The mean can be either
a row or column vector and the covariance matrix must be a symmetric
positive-semidefinite matrix. Various rules for scalar expansion
apply. To illustrate using simulateNormalScenariosByMoments
,
start with moments in m
and C
and
generate 20,000 scenarios:
m = [ 0.0042; 0.0083; 0.01; 0.15 ]; C = [ 0.005333 0.00034 0.00016 0; 0.00034 0.002408 0.0017 0.000992; 0.00016 0.0017 0.0048 0.0028; 0 0.000992 0.0028 0.010208 ]; p = PortfolioCVaR; p = simulateNormalScenariosByMoments(p, m, C, 20000); [passetmean, passetcovar] = estimateScenarioMoments(p)
passetmean = 0.0049 0.0083 0.0101 0.1503 passetcovar = 0.0053 0.0003 0.0002 -0.0000 0.0003 0.0024 0.0017 0.0010 0.0002 0.0017 0.0047 0.0028 -0.0000 0.0010 0.0028 0.0101
simulateNormalScenariosByMoments
performs
scalar expansion on arguments for the moments of asset returns. If NumAssets
has
not already been set, a scalar argument is interpreted as a scalar
with NumAssets
set to 1
. simulateNormalScenariosByMoments
provides
an additional optional argument to specify the number of assets so
that scalar expansion works with the correct number of assets. In
addition, if either a scalar or vector is input for the covariance
of asset returns, a diagonal matrix is formed such that a scalar expands
along the diagonal and a vector becomes the diagonal.
estimatePortVaR
| PortfolioCVaR
| setCosts
| setProbabilityLevel
| setScenarios
| simulateNormalScenariosByData
| simulateNormalScenariosByMoments