주요 콘텐츠

estimateAssetMoments

R2026b

Estimate mean and covariance of asset returns from data

Description

obj = estimateAssetMoments(obj,AssetReturns) estimates the mean and covariance of asset returns from data for a Portfolio object. For details on the workflow, see Portfolio Object Workflow.

example

obj = estimateAssetMoments(___,Name=Value) estimates the mean and covariance of asset returns from data with additional options specified by one or more name-value arguments. For example, estimateAssetMoments(obj,AssetReturns,Probabilities=p) estimates the weighted mean and covariance using the probability weights in p.

example

Examples

collapse all

This example shows how to use the estimateAssetMoments function to estimate the mean and covariance of asset returns from data for a Portfolio object.

Generate random samples of 120 observations of asset returns for four assets from known mean and covariance values using the portsim function. Also create a corresponding price series from the returns.

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;
X = portsim(m,C,120);
Y = ret2tick(X);

Create a Portfolio object and estimate asset moments from the return data in X using the estimateAssetMoments function. Compare the estimated moments with directly assigned moments.

p = Portfolio(AssetMean=m,AssetCovar=C);
q = Portfolio;
q = estimateAssetMoments(q,X);

[pMean,pCovar] = getAssetMoments(p)
pMean = 4×1

    0.0042
    0.0083
    0.0100
    0.0150

pCovar = 4×4

    0.0005    0.0003    0.0002         0
    0.0003    0.0024    0.0017    0.0010
    0.0002    0.0017    0.0048    0.0028
         0    0.0010    0.0028    0.0102

[qMean,qCovar] = getAssetMoments(q)
qMean = 4×1

    0.0042
    0.0083
    0.0100
    0.0150

qCovar = 4×4

    0.0005    0.0003    0.0002    0.0000
    0.0003    0.0024    0.0017    0.0010
    0.0002    0.0017    0.0048    0.0028
    0.0000    0.0010    0.0028    0.0102

Both approaches yield the same moments because the portsim function creates simulated data with estimated mean and covariance identical to the input moments.

If you have asset prices instead of returns, specify the DataFormat name-value argument set as "Prices" to indicate that the input data contains prices.

r = Portfolio;
r = estimateAssetMoments(r,Y,DataFormat="Prices");

[rMean,rCovar] = getAssetMoments(r)
rMean = 4×1

    0.0042
    0.0083
    0.0100
    0.0150

rCovar = 4×4

    0.0005    0.0003    0.0002    0.0000
    0.0003    0.0024    0.0017    0.0010
    0.0002    0.0017    0.0048    0.0028
    0.0000    0.0010    0.0028    0.0102

The estimated moments from prices match those estimated from returns.

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)
       Time          AAPL         AMZN         CSCO         DELL         EBAY       GOOG       HPQ          IBM         INTC         MSFT         ORCL         YHOO        MARKET         CASH   
    ___________    _________    _________    _________    _________    _________    ____    _________    _________    _________    _________    _________    _________    _________    __________

    03-Jan-2000     0.088805       0.1742     0.008775    -0.002353      0.12829    NaN       0.03244     0.075368      0.05698    -0.001627     0.054078     0.097784    -0.012143    0.00020522
    04-Jan-2000    -0.084331     -0.08324     -0.05608     -0.08353    -0.093805    NaN     -0.075613    -0.033966    -0.046667    -0.033802      -0.0883    -0.067368     -0.03166    0.00020339
    05-Jan-2000     0.014634     -0.14877    -0.003039     0.070984     0.066875    NaN     -0.006356      0.03516     0.008199     0.010567    -0.052837    -0.073363     0.011443    0.00020376
    06-Jan-2000    -0.086538    -0.060072    -0.016619    -0.038847    -0.012302    NaN     -0.063688    -0.017241     -0.05824    -0.033477    -0.058824     -0.10307     0.011743    0.00020266
    07-Jan-2000     0.047368     0.061013       0.0587    -0.037708    -0.000964    NaN      0.028416    -0.004386      0.04127     0.013091     0.076771      0.10609      0.02393    0.00020157

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')
    {'AAPL'  }
    {'AMZN'  }
    {'CSCO'  }
    {'DELL'  }
    {'EBAY'  }
    {'GOOG'  }
    {'HPQ'   }
    {'IBM'   }
    {'INTC'  }
    {'MSFT'  }
    {'ORCL'  }
    {'YHOO'  }
    {'MARKET'}
    {'CASH'  }

Input Arguments

collapse all

Portfolio, specified as a Portfolio object.

Asset return or price data, specified as a matrix, table, or timetable. The rows correspond to samples and the columns correspond to assets.

Use the DataFormat name-value argument to indicate when AssetReturns contains asset prices. When the data contains prices, the function converts the prices to returns internally.

Note

Portfolio optimization typically requires total returns, not simply price returns. Use caution when working with asset price data.

Name-Value Arguments

collapse all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: p = estimateAssetMoments(p,Y,Dataformat="prices")

Format of input data, specified as "Returns" or "Prices".

  • "Returns" — Data in AssetReturns contains asset total returns.

  • "Prices" — Data in AssetReturns contains asset total return prices. The function converts prices to returns before estimating moments.

Whether to use ECM algorithm for missing data, specified as a numeric or logical 0 (false) or 1 (true).

  • false — Exclude samples with NaN values.

  • true — Use the ECM algorithm to obtain maximum likelihood estimates in the presence of NaN values.

For more information on the ECM algorithm, see ecmnmle and Multivariate Normal Regression.

Note

Specifying the MissingData name-value argument as true is not supported when you specify the Probabilities name-value argument. If you specify MissingData as true and also specify a value for Probabilities, then the function issues a warning and estimates the moments while ignoring missing values. (since R2026b)

Whether to generate asset names from input data, specified as a numeric or logical 0 (false) or 1 (true).

  • false — Do not generate asset names.

  • true

    • If AssetReturns is a matrix, then the function generates asset names based on the defaultforAssetList property of the portfolio, which is 'Asset' by default. The asset names take the form <prefix>1, <prefix>2, …, <prefix>n, where <prefix> is the defaultforAssetList property of the portfolio and n is the number of assets in the portfolio.

    • If AssetReturns is a table or timetable, then the function generates uses the column names from AssetReturns for asset names.

Since R2026b

Probability weights for each observation, specified as a nonnegative numeric vector that sums to 1. Each element corresponds to the probability weight assigned to the corresponding row of asset return data. When you specify the Probabilities name-value argument, the function estimates the weighted mean and the population (biased) covariance.

The length of Probabilities depends on the value of the DataFormat name-value argument:

  • If DataFormat is "Returns" (or if you do not specify DataFormat), then the length of Probabilities must be the same as the number of rows in AssetReturns.

  • If DataFormat is "Prices", then the length of Probabilities must be the one fewer than the number of rows in AssetReturns.

When you specify the Probabilities name-value argument, the function estimates the weighted mean and the population (biased) covariance. For more information, see Algorithms.

Output Arguments

collapse all

Updated portfolio, returned as a Portfolio object. The function sets the AssetMean and AssetCovar properties to the estimated mean and covariance, respectively.

Algorithms

The estimateAssetMoments function estimates the mean and covariance of asset returns using one of two methods, depending on whether you specify the Probabilities name-value argument. In the following formulas, n is the number of observations, and x and y each represent the return series of an asset.

  • When you do not specify Probabilities, the function estimates the mean and covariance using the standard sample estimators:

    • Sample mean: x¯=1nni=1xi

    • Unbiased sample covariance: cov(x,y)=1n1ni=1(xix¯)(yiy¯)

  • When you specify Probabilities with probability vector p, the data and probabilities fully specify an empirical distribution. The function computes the mean and estimates the covariance using these formulas:

    • Distributional mean:

      μx=ni=1pixi

    • Population covariance:

      cov(x,y)=ni=1pi(xiμx)(yiμy)

Version History

Introduced in R2011a

expand all