[Blotter-commits] r343 - in pkg/quantstrat: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Jun 16 17:39:36 CEST 2010
Author: braverock
Date: 2010-06-16 17:39:36 +0200 (Wed, 16 Jun 2010)
New Revision: 343
Modified:
pkg/quantstrat/R/signals.R
pkg/quantstrat/man/sigThreshold.Rd
Log:
- add 'cross'-over argument to sigThreshold
Modified: pkg/quantstrat/R/signals.R
===================================================================
--- pkg/quantstrat/R/signals.R 2010-06-15 17:47:23 UTC (rev 342)
+++ pkg/quantstrat/R/signals.R 2010-06-16 15:39:36 UTC (rev 343)
@@ -222,8 +222,9 @@
#' @param column named column to apply comparison to
#' @param threshold numeric threhold to test for
#' @param relationship one of c("gt","lt","eq","gte","lte") or reasonable alternatives
+#' @param cross if TRUE, will return TRUE only for the first observation to cross the threshold in a run
#' @export
-sigThreshold <- function(label, data, column, threshold=0, relationship=c("gt","lt","eq","gte","lte")) {
+sigThreshold <- function(label, data, column, threshold=0, relationship=c("gt","lt","eq","gte","lte"),cross=FALSE) {
relationship=relationship[1] #only use the first one
ret_sig=NULL
colNum <- match.names(column, colnames(data))
@@ -241,6 +242,7 @@
'le' = {ret_sig = data[,colNum] <= threshold}
)
colnames(ret_sig)<-label
+ if(isTRUE(cross)) ret_sig <- diff(ret_sig)==1
return(ret_sig)
}
Modified: pkg/quantstrat/man/sigThreshold.Rd
===================================================================
--- pkg/quantstrat/man/sigThreshold.Rd 2010-06-15 17:47:23 UTC (rev 342)
+++ pkg/quantstrat/man/sigThreshold.Rd 2010-06-16 15:39:36 UTC (rev 343)
@@ -2,7 +2,7 @@
\alias{sigThreshold}
\title{generate a threshold signal...}
\usage{sigThreshold(label, data, column, threshold=0, relationship=c("gt",
- "lt", "eq", "gte", "lte"))}
+ "lt", "eq", "gte", "lte"), cross=FALSE)}
\description{generate a threshold signal}
\details{Many strategies, including RSI or MACD styles, make trading decisions when an indicator
is over or under a specific threshold.
@@ -11,4 +11,5 @@
\item{data}{data to apply comparison to}
\item{column}{named column to apply comparison to}
\item{threshold}{numeric threhold to test for}
-\item{relationship}{one of c("gt","lt","eq","gte","lte") or reasonable alternatives}}
+\item{relationship}{one of c("gt","lt","eq","gte","lte") or reasonable alternatives}
+\item{cross}{if TRUE, will return TRUE only for the first observation to cross the threshold in a run}}
More information about the Blotter-commits
mailing list