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

  • 1
    $\begingroup$ which program language are you asking for $\endgroup$
    – develarist
    Commented Aug 23, 2020 at 18:38
  • $\begingroup$ Hi, I am using R to get the returns. $\endgroup$
    – Lee Site
    Commented Aug 25, 2020 at 3:43

1 Answer 1


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.


Your Answer

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

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