[R-SIG-Finance] EWMA covariance matrix
Eric Zivot
ezivot at u.washington.edu
Tue Apr 14 23:58:43 CEST 2009
Does anyone have a suggestion for the best function to use to compute a EWMA covariance matrix? I see that the function cov.wt() (in stats) and cov.shrink (in corpcor) will compute a weighted covariance estimate. I assume I can just use exponentially declining weights as follows
> set.seed(123)
> testData = matrix(rnorm(100), 50, 2)
> lam = 0.9
> i = 0:49
> ewma.wt = lam^i
> ewma.wt = ewma.wt/sum(ewma.wt)
> cov.ewma = cov.wt(testData, wt=rev(ewma.wt))
> cov.ewma
$cov
[,1] [,2]
[1,] 0.8374426 -0.1366568
[2,] -0.1366568 1.0205296
$center
[1] 0.0456912 0.3136311
$n.obs
[1] 50
$wt
[1] 0.0005756082 0.0006395647 0.0007106275 0.0007895861 0.0008773179
[6] 0.0009747976 0.0010831085 0.0012034538 0.0013371709 0.0014857455
[11] 0.0016508283 0.0018342537 0.0020380597 0.0022645107 0.0025161230
[16] 0.0027956923 0.0031063247 0.0034514719 0.0038349688 0.0042610765
[21] 0.0047345294 0.0052605882 0.0058450980 0.0064945534 0.0072161704
[26] 0.0080179671 0.0089088523 0.0098987248 0.0109985831 0.0122206479
[31] 0.0135784977 0.0150872197 0.0167635774 0.0186261971 0.0206957746
[36] 0.0229953051 0.0255503390 0.0283892655 0.0315436284 0.0350484760
[41] 0.0389427511 0.0432697234 0.0480774705 0.0534194116 0.0593549018
[46] 0.0659498909 0.0732776566 0.0814196184 0.0904662427 0.1005180474
****************************************************************
* Eric Zivot *
* Professor and Gary Waterman Distinguished Scholar *
* Department of Economics *
* Adjunct Professor of Finance *
* Adjunct Professor of Statistics
* Box 353330 email: ezivot at u.washington.edu *
* University of Washington phone: 206-543-6715 *
* Seattle, WA 98195-3330 * *
* www: http://faculty.washington.edu/ezivot *
More information about the R-SIG-Finance
mailing list