2013-10-22 13 views
0

我想计算10个投资组合的投资组合回报。权重是固定的,即每个月重新平衡。Return.portfolio和Return.rebalancing在R

我的数据(提取物)如下所示(返回数据,变量名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) 

有人能帮助我摆脱这种痛苦(即帮助我重构体重矩阵)吗?

Andreas

回答

3

您的'权重'对象不是时间序列。

如文档中表示,权重必须

a time series or single-row matrix/vector containing asset weights, as percentages 

单行或权重向量并不需要是一个时间序列,因为它只是作为一个单一组加权处理适用于时间序列的开头。

如果你真的想重新平衡,你需要告诉Return.rebalancing功能具体日期,重新平衡投资组合,因此需要的是权重也是一个时间序列(最好XTS)对象。

+0

谢谢。有没有简单的方法来做到这一点,即使这个权重向量从12-87到09-13每个月的xts时间序列? – user2157086

+0

你有一个重量*清单*。我认为你最好的办法是先把它变成矩阵,然后变成一个xts对象。 –

+0

我还注意到问题中(不可重现)权重对象的每一行都是0,第一行除外。如果您只想要一组权重,请使用向量或单行时间序列。 –