问题描述
我正在努力计算等权重的投资组合回报。我目前正在使用 Return.portfolio
包中的 PerformanceAnalytics
,但在处理 NA 时遇到问题。
举一个可复制的例子:
structure(c(5.49295774647889,4.80640854472629,-0.127388535031836,4.71938775510203,5.75517661388552,NA,1.46627565982405,4.09441233140655,1.31031876023686,10.3718442979729,-5.16056338028169,0.237614351906856,1.35119118169966,2.26775883557192,5.05941761423306,-1.76265063843784,2.14109258894431,3.73359337566391,3.40163825335787,7.58912642134959,-2.64397595765676,3.733593376,2.47850105350444,3.73359337566391
),.Dim = 5:6,.Dimnames = list(NULL,c("ALVGY","BAYNGY","BMWGY","PF.return.wrong","PF.return.expected","PF.return.weighted"
)),index = structure(c(1480464000,1483142400,1485820800,1488240000,1490918400),tzone = "UTC",tclass = "Date"),class = c("xts","zoo"),ret_type = "discrete",coredata_content = "discreteReturn")
ALVGY BAYNGY BMWGY PF.return.wrong PF.return.expected PF.return.weighted
2016-11-30 5.4929577 NA 1.3103188 2.267759 3.401638 NA
2016-12-31 4.8064085 NA 10.3718443 5.059418 7.589126 7.589126
2017-01-31 -0.1273885 NA -5.1605634 -1.762651 -2.643976 -2.643976
2017-02-28 4.7193878 1.466276 0.2376144 2.141093 2.141093 2.478501
2017-03-31 5.7551766 4.094412 1.3511912 3.733593 3.733593 3.733593
当我运行 Example$PF.return <- Return.portfolio(Example[,1:3],geometric = F)
时,我收到一个警告读数 In Return.portfolio(Example,geometric = F) : NA's detected: filling NA's with zeros
,并且实际上结果 PF.return.wrong
在计算中将 NA 作为零包含在内。
我确实希望在 PF.return.expected
中获得结果。
我想要做的是从投资组合回报计算中排除 NA。但是我无法做到这一点。
作为一种潜在的解决方法,我考虑过将 return.portfolio
与下面的加权矩阵 Example.wt 结合使用:
structure(c(0.5,0.5,0.333333333333333,0.333333333333333),.Dim = c(5L,3L),.Dimnames = list(
NULL,"BMWGY")),"zoo"))
ALVGY BAYNGY BMWGY
2016-11-30 0.5000000 0.0000000 0.5000000
2016-12-31 0.5000000 0.0000000 0.5000000
2017-01-31 0.5000000 0.0000000 0.5000000
2017-02-28 0.3333333 0.3333333 0.3333333
2017-03-31 0.3333333 0.3333333 0.3333333
运行 Example$PF.return.weighted <- Return.portfolio(Example[,geometric = F,weights = Example.wt)
我遇到三个问题:
- 出于某种原因,PF.return.weighted 的第一行返回 NA
- 第四行的值不等于 PF.return.expected,我不明白为什么
-
Example.wt
是手动构建的,因为我没有设法计算它。
您知道为什么 PF.return.weighted 有 NA 以及为什么第四行值与预期值不同吗?
至于权重矩阵的计算,你知道我如何从Example
中自动计算吗?我想过使用rowSums
和{{的某种组合1}} 但没有设法构建它。
很抱歉这篇长文章,但我真的被困在这里,希望得到任何帮助/提示!非常感谢!
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)