问题描述
我每周都有返回数据以升序排列。假设我要计算指数加权移动协方差矩阵,假设其半衰期为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