r - 回报时间序列的预期回报和协方差
问题描述
我正在尝试模拟ewstats
此处定义的 Matlab 函数:
https://it.mathworks.com/help/finance/ewstats.html
Matlab给出的结果如下:
> ExpReturn = 1×2
0.1995 0.1002
> ExpCovariance = 2×2
0.0032 -0.0017
-0.0017 0.0010
我正在尝试使用 RiskPortfolios R 包复制该示例:
https://cran.r-project.org/web/packages/RiskPortfolios/RiskPortfolios.pdf
我正在使用的 R 代码是这个:
library(RiskPortfolios)
rets <- as.matrix(cbind(c(0.24, 0.15, 0.27, 0.14), c(0.08, 0.13, 0.06, 0.13)))
w <- 0.98
rets
w
meanEstimation(rets, control = list(type = 'ewma', lambda = w))
covEstimation(rets, control = list(type = 'ewma', lambda = w))
均值估计与示例中的相同,但协方差矩阵不同:
> rets
[,1] [,2]
[1,] 0.24 0.08
[2,] 0.15 0.13
[3,] 0.27 0.06
[4,] 0.14 0.13
> w
[1] 0.98
>
> meanEstimation(rets, control = list(type = 'ewma', lambda = w))
[1] 0.1995434 0.1002031
>
> covEstimation(rets, control = list(type = 'ewma', lambda = w))
[,1] [,2]
[1,] 0.007045044 -0.003857217
[2,] -0.003857217 0.002123827
我错过了什么吗?谢谢
解决方案
如果使用,他们给出相同的答案type = "lw"
:
round(covEstimation(rets, control = list(type = 'lw')), 4)
## 0.0032 -0.0017
## -0.0017 0.0010
推荐阅读
- ios - 不断偏移 SKNode 的位置 - Swift Sprite Kit
- c - *date = "星期天"; vs int *number = 7;
- vue.js - Vue JS(router.beforeEach)无法将异常转换为字符串
- mongodb - MongoDB $match 不适用于聚合查询中的 $group
- c - Xcode中的命令行参数抛出错误,但终端工作正常
- reactjs - 用玩笑和酶测试反应成分,覆盖率问题
- android - 将 android 本机应用程序替换为商店中的 React 本机应用程序
- python - 具有重复列的 Concat 数据框
- android - libGDX中的BitmapFont在隐藏和显示屏幕后变成正方形
- python - 如何在函数中使一个默认的空列表等于另一个?