0

I am trying to write my own signal function in quantstrat. The logic I am struggling with is the same as is used in other R operations.

data[,colNums[1]] etc. returns a vector of values.

sigPair <- function( label, data = mktdata, columns )
{
  ret_sig = FALSE
  colNums <- match.names(columns, colnames(data))
ratio_minus_dn <- data[, colNums[1]] - data[, colNums[3]]
    ret_sig <- do.call(">", list(data[, colNums[1]], data[, colNums[2]]))

    ret_sig <- ifelse( min(tail(ratio_minus_dn, 400)) < 0, ret_sig, FALSE    )

  colnames(ret_sig) <- label
  return(ret_sig)  
}

It is this line:

ret_sig <- ifelse( min(tail(ratio_minus_dn, 400)) < 0, ret_sig, FALSE    )

that is giving me problems.

The error I get is: Error in colnames<-(*tmp*, value = "cross.up") : attempt to set colnames on object with less than two dimensions

My intention is to check if ratio_minus_dn has been <0 in the last 400 elements and return true in that case.

What would be a good way to accomplish this task?

Thankful for all tips!

nikke
  • 111
  • 8

1 Answers1

2

Was not able to solve this, but got a great tip on a solution that enabled me to work around the issue. This enabled me to use higher timeframe calculations so I could kind almost get the same result:

getSymbols("SPY", src="yahoo")

SPY$wklyRSI <- xts:::by.period(SPY, RSI, period="weeks", n=2)
kleopatra
  • 51,061
  • 28
  • 99
  • 211
nikke
  • 111
  • 8