%% Estimate Mean and Covariance of Asset Returns from Timetable Data for a Portfolio Object
% To illustrate using the estimateAssetMoments function with AssetReturns data continued 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), because it was not listed before Aug 2004. The estimateAssetMoments 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, estimateAssetMoments uses the ECM algorithm to estimate asset moments.

r = Portfolio;
r = estimateAssetMoments(r,AssetsTimeTable,'dataformat','returns','missingdata',true);

% In addition, the estimateAssetMoments function also extracts asset names or identifiers from a timetable object when the name-value argument 'GetAssetList' 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 Portfolio object. To show this, the formation of the Portfolio object r is repeated with the 'GetAssetList' flag set to true.

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

%
%
%
% Copyright 2012 The MathWorks, Inc.