我想计算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)有人能帮我摆脱这种痛苦吗?帮助我重组我的体重矩阵)?
安德烈亚斯
发布于 2013-10-22 11:17:20
你的“重量”对象不是时间序列。
正如文档中所述,权数需要
a time series or single-row matrix/vector containing asset weights, as percentages单行或权向量不需要是时间序列,因为它将作为一组权重来处理,以便在时间序列开始时应用。
如果您实际上想要重新平衡,您需要告诉Return.rebalancing函数重新平衡投资组合的日期,因此权重也需要是一个时间序列(最好是xts)对象。
https://stackoverflow.com/questions/19511584
复制相似问题