summaryrefslogtreecommitdiffstats
path: root/patch-adjRatios.R
diff options
context:
space:
mode:
authorGuillaume Horel <guillaume.horel@gmail.com>2011-10-18 02:40:30 -0400
committerGuillaume Horel <guillaume.horel@gmail.com>2011-10-18 02:40:30 -0400
commit83b41368bbc072bead2b6311c7a019b40164bba4 (patch)
treedf15f140e43e38e1c7d51bcc18319be19d13be9f /patch-adjRatios.R
parent08a6c748f17c8baf2c83d391341c731cb9eeef4f (diff)
downloadbandit-83b41368bbc072bead2b6311c7a019b40164bba4.tar.gz
Tons of fixes
have downloaded a complete history of the sp500 since 01/01/2000
Diffstat (limited to 'patch-adjRatios.R')
-rw-r--r--patch-adjRatios.R8
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))) {