我正在寻找以下问题的切实可行的解决方案:
我想结合使用table.CalendarReturns
包中的函数PerformanceAnalytics
生成的两个性能表。
一个表格包含投资组合的效果数据,可能如下所示:
require(PerformanceAnalytics)
set.seed(1)
df <- data.frame(Jan = sample(-60:140, 6, replace = T)/10,
Feb = sample(-60:140, 6, replace = T)/10,
Mrz = sample(-60:140, 6, replace = T)/10,
Apr = sample(-60:140, 6, replace = T)/10,
Mai = sample(-60:140, 6, replace = T)/10,
Jun = sample(-60:140, 6, replace = T)/10,
Jul = sample(-60:140, 6, replace = T)/10,
Aug = sample(-60:140, 6, replace = T)/10,
Sep = sample(-60:140, 6, replace = T)/10,
Okt = sample(-60:140, 6, replace = T)/10,
Nov = sample(-60:140, 6, replace = T)/10,
Dez = sample(-60:140, 6, replace = T)/10)
df$Return <- rowSums(df)
rownames(df) <- c(2012,2013,2014,2015,2016,2017)
为简单起见,返回显示为总数。
基准数字可能是:
set.seed(2)
df_bm <- data.frame(Jan = sample(-60:140, 6, replace = T)/10,
Feb = sample(-60:140, 6, replace = T)/10,
Mrz = sample(-60:140, 6, replace = T)/10,
Apr = sample(-60:140, 6, replace = T)/10,
Mai = sample(-60:140, 6, replace = T)/10,
Jun = sample(-60:140, 6, replace = T)/10,
Jul = sample(-60:140, 6, replace = T)/10,
Aug = sample(-60:140, 6, replace = T)/10,
Sep = sample(-60:140, 6, replace = T)/10,
Okt = sample(-60:140, 6, replace = T)/10,
Nov = sample(-60:140, 6, replace = T)/10,
Dez = sample(-60:140, 6, replace = T)/10)
df_bm$Return <- rowSums(df)
rownames(df_bm) <- c("2012 BM", "2013 BM", "2014 BM" ,"2015 BM" , "2016 BM" , "2017 BM")
我的目标是合并两个表,以便插入相应月份的基准值。
结果应如下所示(2012年至2013年1月至3月等等......):
Jan Feb Mrz
2012 -0.7 12.9 7.8
2012 BM -2.3 -3.5 -9.2
2013 1.4 7.2 1.7
2013 BM 8.1 10.7 -2.3
有什么想法吗?
感谢您的帮助!