%% Simulate Multivariate Normal Asset Return Scenarios from Data for a PortfolioCVaR Object Using Financial Timetable Data
% To illustrate using the simulateNormalScenariosByData function with AssetReturns data contined in a timetable object, use the CAPMuniverse.mat which contains a timetable object (AssetTimeTable) for returns data.

load CAPMuniverse;
AssetsTimeTable.Properties
head(AssetsTimeTable,5)

% Notice that GOOG has missing data (NaN) becuse it was not listed before Aug 2004. The simulateNormalScenariosByData function has a name-value pair argument 'MissingData' that indicates with a Boolean value whether to use the missing data capabilities of Financial Toolbox™ software. The default value for 'MissingData' is false which removes all samples with NaN values. If, however, 'MissingData' is set to true, the estimateAssetMoments function uses the ECM algorithm to estimate asset moments. The simulateNormalScenariosByData function also 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').

NumScenarios = 100;
r = PortfolioCVaR;
r = simulateNormalScenariosByData(r,AssetsTimeTable,NumScenarios,'DataFormat','Returns','MissingData',true);

% In addition, simulateNormalScenariosByData extracts asset names or identifiers from a timetable object when the name-value argument 'GetAssetList' is set to true (its default value is false). If the 'GetAssetList' value is true, the timetable column identifiers are used to set the AssetList property of the PortfolioCVaR object. To show this, the formation of the PortfolioCVaR object r is repeated with the 'GetAssetList' flag set to true.

r = simulateNormalScenariosByData(r,AssetsTimeTable,NumScenarios,'GetAssetList',true);
disp(r.AssetList)

% Copyright 2012 The MathWorks, Inc.