Skip to content

Commit

Permalink
extend the first training period by one obs. so test period is correct
Browse files Browse the repository at this point in the history
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
  • Loading branch information
braverock committed Mar 27, 2019
1 parent 0695c8b commit 4e91555
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/walk.forward.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
}
Expand Down

0 comments on commit 4e91555

Please sign in to comment.