braverock / PerformanceAnalytics

209 stars 105 forks source link

Return.annualized should have na.omit argument, rather than disregarding NAs #172

Open Ljupch0 opened 2 years ago

Ljupch0 commented 2 years ago

It would be great if there is an option to control the treatment of NA, like in base functions mean and sum.

I would prefer if the following returned NA, rather than 0.1489125

Return.annualized(c(0.1, 0.2, NA), scale = 1)
Ljupch0 commented 2 years ago

This wrapper also works, but just saying would be a good option to have by default.

Return.annualized.na <- function(vector, ...) {
   if (any(is.na(vector))) {
      return(NA)
   } else {
      PerformanceAnalytics::Return.annualized(R = vector, ...)
   }
}