Code covered by the BSD License  

Highlights from
Weighted Covariance Matrix

Be the first to rate this file! 33 Downloads (last 30 days) File Size: 2.22 KB File ID: #37184

Weighted Covariance Matrix

by

 

15 Jun 2012 (Updated )

Calculates a Weighted Covariance Matrix

| Watch this File

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

See also CORRCOEF, COV, STD, MEAN.
Check also WEIGHTEDCORRS (FE 20846) and KENDALLTAU (FE 27361)

Acknowledgements

Weighted Correlation Matrix inspired this file.

MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Updates
25 Jun 2012

Corrected minor issue

Contact us