2
$\begingroup$

I am trying to compute quarterly returns with daily stock prices. However, I don't want to use the quantmod function "quarterlyReturn(x)" for each single stock but instead for the whole list of stocks...

I would be happy about any advice on how to get there.

The beginning looks like this:

 TickerList <- c("SPG", "AKR","AIV", "ARE", "AAT", "AMT", "ARI", "ABR", "ARR" )

 ClosingPricesRead <- NULL for (Ticker in TickerList)  ClosingPricesRead <- cbind(ClosingPricesRead,
                  getSymbols(Ticker, from="1950-01-01", >verbose=FALSE, auto.assign=FALSE)[,6]) 

    ClosingPrices <- ClosingPricesRead[apply(ClosingPricesRead,1,function(x)
                     all(!is.na(x))),]

Now I would like to convert my daily closing Prices to quarterly returns, in such a way that I get a new dataframe with the returns for all Stocks. I tried to use the quantmod package so that:

apply(ClosingPrices, 2, function(x),quarterlyReturn(x))

But I am just receiving error messages...

Since I am fairly new to R, I would really appreciate your help!

Many thanks

$\endgroup$
2
  • $\begingroup$ Please provide a reproducible example and the error messages you're receiving. $\endgroup$
    – Bob Jansen
    Mar 16, 2017 at 12:57
  • $\begingroup$ @BobJansen thanks for your prompt response! Next time I will include a reproducible example, thx for the hint. $\endgroup$
    – Backs
    Mar 20, 2017 at 11:49

1 Answer 1

1
$\begingroup$

It turns out the answer is quite simple!

I just needed to adjust the "lapply" function correctly such that:

QuarterlyReturns <- lapply(Prices, quarterlyReturn, USE.NAMES = TRUE)

Now the calculation works perfectly fine.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.