diff options
Diffstat (limited to 'patch-adjRatios.R')
| -rw-r--r-- | patch-adjRatios.R | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/patch-adjRatios.R b/patch-adjRatios.R index a96f541..e7beeab 100644 --- a/patch-adjRatios.R +++ b/patch-adjRatios.R @@ -42,8 +42,12 @@ adjRatios <- function (splits, dividends, close) obj <- merge.xts(close, splits, dividends) # for a non NA dividend value, close from the previous day must be non NA #otherwise we can't compute the dividend ratio - if(any(is.na(close[-length(close)][!is.na(dividends)[-1]]))){ - stop("can't compute dividend ratio") + if(any(is.na(obj[-NROW(obj),1][!is.na(obj[,3])[-1]]))){ + for(i in which(!is.na(obj[,3]))){ + if( is.na(obj[i-1,1]) ){ + obj[i-1,1] <- last(na.omit(obj[1:(i-1),1])) + } + } } # if close is NA, then we can't compute the dividend ratio anway #if (!isTRUE(is.na(close))) { |
