# ewstats

Expected return and covariance from return time series

## Syntax

``[ExpReturn,ExpCovariance,NumEffObs] = ewstats(RetSeries)``
``[ExpReturn,ExpCovariance,NumEffObs] = ewstats(___,DecayFactor,WindowLength)``

## Description

example

````[ExpReturn,ExpCovariance,NumEffObs] = ewstats(RetSeries)` computes estimated expected returns (`ExpReturn`), estimated covariance matrix (`ExpCovariance`), and the number of effective observations (`NumEffObs`). These outputs are maximum likelihood estimates which are biased.```

example

````[ExpReturn,ExpCovariance,NumEffObs] = ewstats(___,DecayFactor,WindowLength)` adds optional input arguments for `DecayFactor` and `WindowLength`.```

## Examples

collapse all

This example shows how to compute the estimated expected returns and the estimated covariance matrix.

```RetSeries = [ 0.24 0.08 0.15 0.13 0.27 0.06 0.14 0.13 ]; DecayFactor = 0.98; [ExpReturn, ExpCovariance] = ewstats(RetSeries, DecayFactor)```
```ExpReturn = 1×2 0.1995 0.1002 ```
```ExpCovariance = 2×2 0.0032 -0.0017 -0.0017 0.0010 ```

## Input Arguments

collapse all

Return series, specified the number of observations (`NUMOBS`) by number of assets (`NASSETS`) matrix of equally spaced incremental return observations. The first row is the oldest observation, and the last row is the most recent.

Data Types: `double`

(Optional) Controls how much less each observation is weighted than its successor, specified as a numeric value. The kth observation back in time has weight `DecayFactor`k. `DecayFactor` must lie in the range: ```0 < DecayFactor <= 1```.

The default value of `1` is the equally weighted linear moving average model (BIS).

Data Types: `double`

(Optional) Number of recent observations in the computation, specified as a numeric value.

Data Types: `double`

## Output Arguments

collapse all

Estimated expected returns, returned as a `1`-by-`NASSETS` vector.

Estimated covariance matrix, returned as a `NASSETS`-by-`NASSETS` matrix.

The standard deviations of the asset return processes are defined as

``` STDVec = sqrt(diag(ExpCovariance)) ```

The correlation matrix is

``` CorrMat = ExpCovariance./( STDVec*STDVec' ) ```

`NumEffObs` is the number of effective observations where

`$NumEffObs=\frac{1-DecayFacto{r}^{WindowLength}}{1-DecayFactor}$`

A smaller `DecayFactor` or `WindowLength` emphasizes recent data more strongly but uses less of the available data set.

## Algorithms

For a return series r(1),…,r(n), where (n) is the most recent observation, and w is the decay factor, the expected returns (`ExpReturn`) are calculated by

`$E\left(r\right)=\frac{\left(r\left(n\right)+wr\left(n-1\right)+{w}^{2}r\left(n-2\right)+...+{w}^{n-1}r\left(1\right)\right)}{NumEffObs}$`

where the number of effective observations `NumEffObs` is defined as

`$NumEffObs=1+w+{w}^{2}+...+{w}^{n-1}=\frac{1-{w}^{n}}{1-w}$`

E(r) is the weighed average of r(n),…,r(`1`). The unnormalized weights are w, w2, …, w(n-1). The unnormalized weights do not sum up to `1`, so `NumEffObs` rescales the unnormalized weights. After rescaling, the normalized weights (which sum up to `1`) are used for averaging. When w = `1`, then `NumEffObs` = n, which is the number of observations. When w < `1`, `NumEffObs` is still interpreted as the sample size, but it is less than n due to the down-weight on the observations of the remote past.

Note

There is no relationship between `ewstats` function and the RiskMetrics® approach for determining the expected return and covariance from a return time series.