From 4e915553e73fa7a366c867ff1fdfff725d39cd39 Mon Sep 17 00:00:00 2001 From: brian Date: Wed, 27 Mar 2019 18:08:13 +0000 Subject: [PATCH] extend the first training period by one obs. so test period is correct We need to extend the length of the first training period by one period so that the first testing period starts in the correct place. Other edge cases exist and have been covered in other commits. This commit solves a remaining issue, discussed in #90, where the training period does not start where expected, but rather one observation earlier than expected. All subsequent periods are the expected length, so we only need to adjust the first one. fixes #90 --- R/walk.forward.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/walk.forward.R b/R/walk.forward.R index 3711db9..4255470 100644 --- a/R/walk.forward.R +++ b/R/walk.forward.R @@ -124,7 +124,8 @@ walk.forward <- function( strategy.st total.timespan <- paste(index(symbol.data[total.start]), '', sep='/', index(last(symbol.data))) # construct the subsets to use for training/testing - training.end.v <- ep[c(k.training,k.training+cumsum(rep(k.testing,as.integer((length(ep)-k.training)/k.testing))))] + training.end.v <- ep[c(k.training+1,(k.training+1)+cumsum(rep(k.testing,as.integer((length(ep)-k.training)/k.testing))))] + if( is.na(last(training.end.v)) ) { training.end.v <- training.end.v[-length(training.end.v)] }