Calculating Returns Across Missing Price Observations
Summary
The document discusses calculating daily log returns from price series with missing observations, where dropping every row containing a missing value can discard too much data. It presents a missing-data convention attributed to CRSP: keep the return missing when the current day's price is unavailable; when a current price is present, calculate its return from the most recent available earlier price, even if that price is more than one day back.
The example return is therefore a multi-day log return when observations have been skipped. The document suggests optionally recording the number of days covered, so users can distinguish ordinary one-day returns from returns spanning gaps. This approach preserves usable observations while making the interval explicit, but the source notes that methods have tradeoffs and depend on the use case. It does not specify how to handle corporate actions, stale prices, or downstream analyses that require equally spaced daily returns.
Key ideas
- A missing current price can be assigned a missing return for that date.
- When the current price exists, compare it with the most recent earlier available price.
- Returns computed across gaps cover multiple days rather than a single day.
- A counter for the interval length can preserve information about skipped observations.
- The handling of missing prices should match the intended analysis.
Tags
Full text
# How to exclude N/A while calculating daily log returns
# How to exclude N/A while calculating daily log returns
I have daily price data of hundreds of companies from 2010-01-01 to 2020-08-21, there are many missing values in my data frame. if I use na.omit, it deletes all my data. I try to use ROC(), but it does not work due to NA values.
How can I exclude N/A and calculate daily log returns?
Thank you guy, I know you are genius
## Answer by nbbo2 (score 1)
https://quant.stackexchange.com/a/57571
There are multiple solutions possible, depending on the situation.
What CRSP does is something like this:
If the price is "missing" on day t, you compute the return for day t as also "missing"
else if the price on day t exists, compute the return for today as the return from the most recent available price (which may not be $P_{t-1}$ if $P_{t-1}$ is missing) to the current i.e day t price. Store this value in a dataframe. Optionally you can also store a "return_days" counter which tracks the number of days for the return (1 when there is no missing data, in general $N$ where the return you computed is $\log(P_t/P_{t-N})$ because you skipped over $N-1$ missing days).
Like all programming techniques this solution of course has advantages and disadvantages.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.