danielkrizian / strategery

Quant Strategy Specification, Backtesting, Optimization And Statistical Analysis Workflow
10 stars 21 forks source link

Delayed evaluation in *.indicator *.signal #8

Closed danielkrizian closed 10 years ago

danielkrizian commented 10 years ago

.indicator .signal should not evaluate the $.call slot when the object is being merely defined. Result being $data slot filled with data See for example this snippet:

 `%AND%.signal` <- function(x, y) {
   op <- as.name(.Generic)  
  .call <- substitute(op(x, y))

  X <- calc.signal(x, name="Signal.x")$data
  Y <- calc.signal(y, name="Signal.y")$data

  Z <- unique(setkey(rbind(X[Y, roll = T, rollends=FALSE],
                           Y[X, roll = T, rollends=FALSE],
                           use.names = TRUE),
                     Instrument, Date)
              )[,Signal := as.logical(Signal.x * Signal.y)]

  Z <- Z[, list(Instrument, Date, Signal)]

  return(signal(call = .call, data=Z))
}