Python中的指数加权协方差矩阵

问题描述

我每周都有返回数据以升序排列。假设我要计算指数加权移动协方差矩阵,假设其半衰期为5年或260周。我正在尝试遵循pandas.DataFrame.ewm,但在我的情况下如何实现这一点还不清楚。鉴于我不能提及半衰期,因为“仅适用于mean()和半衰期值将不适用于其他函数。”

使用alpha = 1-exp(ln(0.5)/ HalfLife)= 2 /(span + 1),我使用了span = 750。

ret是我的带有DatetimeIndex的返回数据帧。 ret.shape(895,11)

我尝试了SigmaExpW = ret.ewm(span = 750).cov(),但是结果不是我期望的。 SigmaExpW.shape(9845,11)

对于上下文-

ret.info()

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 895 entries,2003-06-04 to 2020-07-22
Data columns (total 11 columns):
 #   Column       Non-Null Count  Dtype  
---  ------       --------------  -----  
 0   GE           895 non-null    float64
 1   IGM          895 non-null    float64
 2   USLC         895 non-null    float64
 3   USSC         895 non-null    float64
 4   ExUS         895 non-null    float64
 5   ExUSHedged   895 non-null    float64
 6   EM           895 non-null    float64
 7   Commodities  895 non-null    float64
 8   HYM          895 non-null    float64
 9   Government   895 non-null    float64
 10  Cash         895 non-null    float64
dtypes: float64(11)

我显然犯了一些基本的错误。希望能有所帮助。

解决方法

它每天都会创建 11*11 矩阵。 895*11 = 9845

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...