Applying Quarterly Return Calculations to Multiple Stock Price Series
Summary
The document addresses how to turn daily closing prices for several stocks into quarterly returns in R. The proposed approach is to store the price series together, then apply the quarterly-return function to each series through a list operation. The questioner had tried applying the function across columns and received errors; the accepted answer reports that applying it to a list of price series worked.
The example is a practical hint for processing multiple instruments, rather than a full explanation of return conventions or data preparation. It does not discuss whether prices are adjusted for dividends and splits, how missing observations affect the series, or how to align quarterly results across stocks. Those choices matter when using the output in analysis, so the suggested workflow may need adaptation to the researcher’s data and intended definition of return.
Key ideas
- A list of price series can be processed by applying a quarterly-return function to each element.
- The answer recommends a list-based workflow for handling multiple stocks.
- The example does not explain return conventions or the effects of missing data.
- Researchers should check price adjustments and align output periods for their use case.
Tags
Full text
# Calculating Quarterly Returns using Daily Prices in R
# Calculating Quarterly Returns using Daily Prices in R
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
## Answer by Backs (score 1)
https://quant.stackexchange.com/a/33120
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.Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.