From 83b41368bbc072bead2b6311c7a019b40164bba4 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Tue, 18 Oct 2011 02:40:30 -0400 Subject: Tons of fixes have downloaded a complete history of the sp500 since 01/01/2000 --- patch-adjRatios.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'patch-adjRatios.R') 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))) { -- cgit v1.2.3-70-g09d2