Code covered by the BSD License

### Highlights from Weighted Covariance Matrix

Be the first to rate this file! 10 Downloads (last 30 days) File Size: 2.21 KB File ID: #37184 Version: 1.2

# Weighted Covariance Matrix

### Liber Eleutherios (view profile)

15 Jun 2012 (Updated )

Calculates a Weighted Covariance Matrix

File Information
Description

WEIGHTEDCOV returns a symmetric matrix C of weighted covariances calculated from an input T-by-N matrix Y whose rows are observations and whose columns are variables and an input T-by-1 vector w of weights for the observations. This function may be a valid alternative to COV if observations are not all equally relevant and need to be weighted according to some theoretical hypothesis or knowledge.
C = WEIGHTEDCOV(Y, w) returns a positive semidefinite matrix C, i.e. all its eigenvalues are non-negative.

If w = ones(size(Y, 1), 1), no difference exists between WEIGHTEDCOV(Y, w) and COV(Y, 1).

REFERENCE: mathematical formulas in matrix notation are available in F. Pozzi, T. Di Matteo, T. Aste, "Exponential smoothing weighted correlations", The European Physical Journal B, Volume 85, Issue 6, 2012. DOI:10.1140/epjb/e2012-20697-x.

EXAMPLE:
% GENERATE CORRELATED STOCHASTIC PROCESSES
T = 100; % number of observations
N = 500; % number of variables
Y = randn(T, N); % shocks from standardized normal distribution
Y = cumsum(Y); % correlated stochastic processes
% CHOOSE EXPONENTIAL WEIGHTS
alpha = 2 / T;
w0 = 1 / sum(exp(((1:T) - T) * alpha));
w = w0 * exp(((1:T) - T) * alpha); % weights: exponential decay
% COMPUTE WEIGHTED COVARIANCE MATRIX
c = weightedcov(Y, w); % Weighted Covariance Matrix

Check also WEIGHTEDCORRS (FE 20846) and KENDALLTAU (FE 27361)

Acknowledgements

Weighted Correlation Matrix inspired this file.

MATLAB release MATLAB 7 (R14)
MATLAB Search Path
`/`