我想计算 10 个投资组合的投资组合收益。权重是固定的,即每月重新平衡。
我的数据(提取)如下(返回数据,变量名returns_xts)
Cash CHF Cash EUR Cash USD Cash JPY Cash GBP Cash SEK Cash NOK
2004-01-30 0.0001758268 0.0069666073 0.0143854541 0.02939934 0.039127564 -0.011597439 -0.03418345
2004-02-27 0.0001575201 0.0068025711 0.0045099598 -0.02749282 0.030491352 0.006885383 0.00460446
2004-03-31 0.0002070932 -0.0099222699 0.0041733946 0.05164557 -0.006797264 -0.013120825 0.02877022
2004-04-30 0.0001835614 -0.0011155096 0.0246020555 -0.03410368 -0.009113713 0.013580744 0.02329576
2004-05-31 0.0001878767 -0.0143628583 -0.0323057302 -0.02467392 0.001095043 -0.009360966 -0.01190726
2004-06-30 0.0001861022 -0.0006346109 0.0002228905 0.00000000 -0.006496727 -0.007516115 -0.03100281
结构是:
An 'xts' object on 2004-01-30/2013-09-30 containing:
Data: num [1:117, 1:46] 0.000176 0.000158 0.000207 0.000184 0.000188 ...
- attr(*, "dimnames")=List of 2
..$ : NULL
..$ : chr [1:46] "Cash CHF" "Cash EUR" "Cash USD" "Cash JPY" ...
Indexed by objects of class: [POSIXct,POSIXt] TZ: UTC
xts Attributes:
NULL
我的体重 (x) 是
FI1 FI2 YI1 YI2 BAL1 BAL2 GRO1 GRO2 EQ1 EQ2
1 0.22 0.15 0.1 0.1 0.05 0.05 0.05 0.05 0.05 0.05
2 0.00 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
3 0.00 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
4 0.00 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
5 0.00 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
6 0.00 0.00 0.0 0.0 0.00 0.00 0.00 0.00 0.00 0.00
它们的结构是
num [1:46, 1:10] 0.22 0 0 0 0 0 0 0 0 0 ...
- attr(*, "dimnames")=List of 2
..$ : chr [1:46] "1" "2" "3" "4" ...
..$ : chr [1:10] "FI1" "FI2" "YI1" "YI2" ...
所以本质上,我想为我的 10 个投资组合计算 117 个月的月收益。
当我使用 Return.portfolio 或 Return.rebalancing 执行此操作时,我收到以下错误消息
Error in checkData(weights, method = "xts") :
The data cannot be converted into a time series. If you are trying to pass in names from a data object with one column, you should use the form 'data[rows, columns, drop = FALSE]'.
Rownames should have standard date formats, such as '1985-03-15'.
或者
Error in Return.portfolio(returns_xts, na.rm = TRUE), coredata(x), :
Use Return.rebalancing for multiple weighting periods.
This function is for portfolios with a single set of weights.
我的代码如下:
pf_returns=Return.portfolio(returns_xts,coredata(x),wealth.index=FALSE,geometric=TRUE)
有人可以帮助我摆脱这种痛苦(即帮助我重组我的权重矩阵)吗?
安德烈亚斯