# setAssetMoments

Set moments (mean and covariance) of asset returns for Portfolio object

## Syntax

``obj = setAssetMoments(obj,AssetMean)``
``obj = setAssetMoments(obj,AssetMean,AssetCovar,NumAssets)``

## Description

example

````obj = setAssetMoments(obj,AssetMean)` obtains mean and covariance of asset returns for a `Portfolio` object. For details on the workflow, see Portfolio Object Workflow.```

example

````obj = setAssetMoments(obj,AssetMean,AssetCovar,NumAssets)` obtains mean and covariance of asset returns for a `Portfolio` object with additional options for `AssetCovar` and `NumAssets`.```

## Examples

collapse all

Set the asset moment properties, given the mean and covariance of asset returns in the variables `m` and `C`.

```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; p = Portfolio; p = setAssetMoments(p, m, C); [assetmean, assetcovar] = getAssetMoments(p)```
```assetmean = 4×1 0.0042 0.0083 0.0100 0.0150 ```
```assetcovar = 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 ```

## Input Arguments

collapse all

Object for portfolio, specified using a `Portfolio` object. For more information on creating a portfolio object, see

Data Types: `object`

Mean of asset returns, specified as a vector.

### Note

If `AssetMean` is a scalar and the number of assets is known, scalar expansion occurs. If the number of assets cannot be determined, this method assumes that `NumAssets` = `1`.

Data Types: `double`

Covariance of asset returns, specified as a symmetric positive semidefinite matrix.

### Note

• If `AssetCovar` is a scalar and the number of assets is known, a diagonal matrix is formed with the scalar value along the diagonals. If it is not possible to determine the number of assets, this method assumes that `NumAssets` = `1`.

• If `AssetCovar` is a vector, a diagonal matrix is formed with the vector along the diagonal.

• If `AssetCovar` is not a symmetric positive semidefinite matrix, use `nearcorr` to create a positive semidefinite matrix for a correlation matrix.

Data Types: `double`

Number of assets, specified as an integer.

### Note

If `NumAssets` is not already set in the object, `NumAssets` can be entered to resolve array expansions with `AssetMean` or `AssetCovar`.

Data Types: `double`

## Output Arguments

collapse all

Updated portfolio object, returned as a `Portfolio` object. For more information on creating a portfolio object, see

## Tips

• You can also use dot notation to set moments (mean and covariance) of the asset returns.

`obj = obj.setAssetMoments(obj, AssetMean, AssetCovar, NumAssets);`

• To clear `NumAssets` and `AssetCovar`, use this function to set these respective inputs to `[]`.