What is the most straight forward way to calculate the returns of an (n x m) xts object?
When I feed an (n x m) xts object mxts
into the quantmod
function dailyReturn
, the return value is an (n x 1) vector, representing the returns of the first column. What I am looking for is a way to generate an (n x m) xts object containing the respective return vector for each column of mxts
.
I have tried to work with some of the apply functions, such as
lapply(mxts,dailyReturn)
but the returns always had the wrong type and lost their labeling (dailyReturn
changes the value of the colnames
vector to "daily.returns").
Is there an easy, non-hacky way to achieve this? Am I maybe using a wrong function for this problem?