Hi,  I noticed an unexpected result when I used sigThreshold() with
relationship="eq" and cross=TRUE on a xts object primarily filled with NA's
and 1's for the value to be matched.  When I tried using cross=FALSE, it
worked as expected since the branch

    if (isTRUE(cross))
        ret_sig <- diff(ret_sig) == 1

is not executed.   My take away from this is that I should not be using
columns with NA's as the base value and 1's as the occasional interesting
value.   Instead I should use 0's as the base value.

Here's an example with both NA's and 0's, and a comment showing where I was
surprised.



library(quantstrat)
sNA = xts(rep(NA, 6), as.POSIXlt( "2014-01-01 06:30:00" ) + 1800 * 0:5 )
sNA[3,1] = 1
names(sNA) = "signal"


theSignalNA1 = sigThreshold(label="findOne", data=sNA, column=c("signal"),
relationship="eq", threshold=1, cross=TRUE)
theSignalNA2 = sigThreshold(label="findOne", data=sNA, column=c("signal"),
relationship="eq", threshold=1, cross=FALSE)

print(theSignalNA1$findOne)
#                     findOne
# 2014-01-01 06:30:00      NA
# 2014-01-01 07:00:00      NA
# 2014-01-01 07:30:00      NA  # I was expecting TRUE here.
# 2014-01-01 08:00:00      NA
# 2014-01-01 08:30:00      NA
# 2014-01-01 09:00:00      NA
print(theSignalNA2$findOne)
#                     findOne
# 2014-01-01 06:30:00      NA
# 2014-01-01 07:00:00      NA
# 2014-01-01 07:30:00    TRUE # Yea, it worked this time!
# 2014-01-01 08:00:00      NA
# 2014-01-01 08:30:00      NA
# 2014-01-01 09:00:00      NA


# Now try again with 0's as the base value

sZero = xts(rep(0, 6), as.POSIXlt( "2014-01-01 06:30:00" ) + 1800 * 0:5 )
sZero[3,1] = 1
names(sZero) = "signal"


theSignalZero1 = sigThreshold(label="findOne", data=sZero,
column=c("signal"), relationship="eq", threshold=1, cross=TRUE)
theSignalZero2 = sigThreshold(label="findOne", data=sZero,
column=c("signal"), relationship="eq", threshold=1, cross=FALSE)

print(theSignalZero1$findOne)
#                     findOne
# 2014-01-01 06:30:00      NA
# 2014-01-01 07:00:00   FALSE
# 2014-01-01 07:30:00    TRUE   # No problems here
# 2014-01-01 08:00:00   FALSE
# 2014-01-01 08:30:00   FALSE
# 2014-01-01 09:00:00   FALSE

print(theSignalZero2$findOne)
#                     findOne
# 2014-01-01 06:30:00   FALSE
# 2014-01-01 07:00:00   FALSE
# 2014-01-01 07:30:00    TRUE  # And, no problem here either.
# 2014-01-01 08:00:00   FALSE
# 2014-01-01 08:30:00   FALSE
# 2014-01-01 09:00:00   FALSE



--
sm
Stergios Marinopoulos

	[[alternative HTML version deleted]]

