Reputation: 575
I want to calculate portfolio returns over time for 10 portfolios. Weights are fixed, i.e. rebalanced every month.
My data (extract) looks as follows (return data, variable name 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
The structure is:
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
my weights (x) are
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
Their structure is
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" ...
So essentially, I want to calculate monthly returns for 117 months for my 10 portfolios.
When I do so with Return.portfolio or Return.rebalancing, I get the following error message
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'.
or
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.
My code is as follows:
pf_returns=Return.portfolio(returns_xts,coredata(x),wealth.index=FALSE,geometric=TRUE)
Can somebody help me out of this misery (ie. help me to restructure my weight matrix)?
Andreas
Upvotes: 0
Views: 2757
Reputation: 3600
Your 'weights' object is not a time series.
As stated in the documentation, weights needs to be
a time series or single-row matrix/vector containing asset weights, as percentages
a single row or vector of weights does not need to be a time series, as it will just be handled as a single set of weights to apply at the beginning of the time series.
If you actually want rebalancing, you need to tell the Return.rebalancing function what dates to rebalance the portfolio on, thus the need that weights also be a time series (preferably xts) object.
Upvotes: 3