[Blotter-commits] r224 - in pkg/quantstrat: . R demo man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Feb 3 22:32:54 CET 2010


Author: braverock
Date: 2010-02-03 22:32:54 +0100 (Wed, 03 Feb 2010)
New Revision: 224

Added:
   pkg/quantstrat/R/match.names.R
   pkg/quantstrat/R/signals.R
   pkg/quantstrat/man/add.signal.Rd
   pkg/quantstrat/man/applySignals.Rd
   pkg/quantstrat/man/match.names.Rd
   pkg/quantstrat/man/sigComparison.Rd
   pkg/quantstrat/man/sigCrossover.Rd
   pkg/quantstrat/man/sigPeak.Rd
   pkg/quantstrat/man/sigThreshold.Rd
Modified:
   pkg/quantstrat/DESCRIPTION
   pkg/quantstrat/NAMESPACE
   pkg/quantstrat/R/indicators.R
   pkg/quantstrat/R/strategy.R
   pkg/quantstrat/demo/00Index
   pkg/quantstrat/demo/simplestrat.R
   pkg/quantstrat/man/add.indicator.Rd
   pkg/quantstrat/man/applyIndicators.Rd
   pkg/quantstrat/man/applyStrategy.Rd
   pkg/quantstrat/man/getStrategy.Rd
   pkg/quantstrat/man/is.strategy.Rd
   pkg/quantstrat/man/strategy.Rd
Log:
- add code to add signals
- add arbitrary text labels to signals and indicators
- add to demo code

Modified: pkg/quantstrat/DESCRIPTION
===================================================================
--- pkg/quantstrat/DESCRIPTION	2010-02-02 12:47:13 UTC (rev 223)
+++ pkg/quantstrat/DESCRIPTION	2010-02-03 21:32:54 UTC (rev 224)
@@ -10,4 +10,4 @@
 Description: Specify, build, and backtest quantitative financial trading strategies
 LazyLoad: yes
 License: GPL-3
-Collate: 'indicators.R' 'strategy.R'
+Collate: 'indicators.R' 'match.names.R' 'signals.R' 'strategy.R'


Property changes on: pkg/quantstrat/DESCRIPTION
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Modified: pkg/quantstrat/NAMESPACE
===================================================================
--- pkg/quantstrat/NAMESPACE	2010-02-02 12:47:13 UTC (rev 223)
+++ pkg/quantstrat/NAMESPACE	2010-02-03 21:32:54 UTC (rev 224)
@@ -1,6 +1,12 @@
 export(add.indicator)
+export(applyIndicators)
+export(match.names)
+export(add.signal)
+export(applySignals)
+export(sigComparison)
+export(sigPeak)
+export(sigThreshold)
 export(strategy)
 export(applyStrategy)
-export(applyIndicators)
 export(is.strategy)
 export(getStrategy)


Property changes on: pkg/quantstrat/NAMESPACE
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Modified: pkg/quantstrat/R/indicators.R
===================================================================
--- pkg/quantstrat/R/indicators.R	2010-02-02 12:47:13 UTC (rev 223)
+++ pkg/quantstrat/R/indicators.R	2010-02-03 21:32:54 UTC (rev 224)
@@ -4,13 +4,17 @@
 #' @param name name of the indicator, must correspond to an R function
 #' @param arguments default arguments to be passed to an indicator function when executed
 #' @param ... any other passthru parameters
+#' @param enabled TRUE/FALSE whether the indicator is enabled for use in applying the strategy, default TRUE
 #' @param indexnum if you are updating a specific indicator, the index number in the $indicators list to update
 #' @param store TRUE/FALSE whether to store the strategy in the .strategy environment, or return it.  default FALSE
 #' @export
-add.indicator <- function(strategy, name, arguments, ..., indexnum=NULL,store=FALSE) {
+add.indicator <- function(strategy, name, arguments, label=NULL, ..., enabled=TRUE, indexnum=NULL, store=FALSE) {
     if(!is.strategy(strategy)) stop("You must pass in a strategy object to manipulate")
     tmp_indicator<-list()
     tmp_indicator$name<-name
+    if(is.null(label)) label = paste(name,"ind",sep='.')
+    tmp_indicator$label<-label
+    tmp_indicator$enabled=enabled
     if (!is.list(arguments)) stop("arguments must be passed as a named list")
     tmp_indicator$arguments<-arguments
     if(!hasArg(indexnum) | (hasArg(indexnum) & is.null(indexnum))) indexnum = length(strategy$indicators)+1
@@ -21,7 +25,73 @@
     else return(strategy)
 }
 
+#' apply the indicators in the strategy to arbitrary market data
+#' @param strategy an object of type 'strategy' to add the indicator to
+#' @param mktdata an xts object containing market data.  depending on indicators, may need to be in OHLCV or BBO formats
+#' @param ... any other passthru parameters
+#' @export
+applyIndicators <- function(strategy, mktdata, ...) {
+    #TODO add Date subsetting
+    
+    # TODO check for symbol name in mktdata using Josh's code:
+    # symbol <- strsplit(colnames(mktdata)[1],"\\.")[[1]][1]
+    
+    if (!is.strategy(strategy)) {
+        strategy<-try(getStrategy(strategy))
+        if(inherits(strategy,"try-error"))
+            stop ("You must supply an object of type 'strategy'.")
+    } 
+    ret <- NULL
+    nargs <-list(...)
+    if(length(nargs)==0) nargs=NULL
+    if (length('...')==0 | is.null('...')) {
+        #rm('...')
+        nargs=NULL
+    }
+    
+    for (indicator in strategy$indicators){
+        #TODO check to see if they've already been calculated
+        if(!is.function(get(indicator$name))) {
+            message(paste("Skipping indicator",indicator$name,"because there is no function by that name to call"))
+            next()
+        }
+        
+        # see 'S Programming p. 67 for this matching
+        fun<-match.fun(indicator$name)
+        .formals  <- formals(fun)
+        onames <- names(.formals)
+        
+        pm <- pmatch(names(indicator$arguments), onames, nomatch = 0L)
+        if (any(pm == 0L))
+            warning(paste("some arguments stored for",indicator$name,"do not match"))
+        names(indicator$arguments[pm > 0L]) <- onames[pm]
+        .formals[pm] <- indicator$arguments[pm > 0L]
+        #now add dots
+        if (length(nargs)) {
+            pm <- pmatch(names(nargs), onames, nomatch = 0L)
+            names(nargs[pm > 0L]) <- onames[pm]
+            .formals[pm] <- nargs[pm > 0L]
+        }
+        #.formals$... <- ''
+        
+        formals(fun) <- .formals
+        tmp_val<-do.call(fun,.formals)
+        if(is.null(names(tmp_val)) & ncol(tmp_val)==1) names(tmp_val)<-indicator$label
+        if (nrow(mktdata)==nrow(tmp_val) | length(mktdata)==length(tmp_val)) {
+            # the indicator returned a time series, so we'll name it and cbind it
+            mktdata<-cbind(mktdata,tmp_val)
+        } else {
+            # the indicator returned something else, add it to the ret list
+            if(is.null(ret)) ret<-list()
+            ret[[indicator$name]]<-tmp_val
+        }
+        #print(tmp_val)
+    } #end indicators loop
+    if(is.null(ret)) return(mktdata)
+    else return(list(mktdata=mktdata,indicator_ret=ret))
+}
 
+
 ###############################################################################
 # R (http://r-project.org/) Quantitative Strategy Model Framework
 #
@@ -31,6 +101,6 @@
 # This library is distributed under the terms of the GNU Public License (GPL)
 # for full details see the file COPYING
 #
-# $Id: strategy.R 217 2010-01-29 18:10:53Z braverock $
+# $Id$
 #
 ###############################################################################


Property changes on: pkg/quantstrat/R/indicators.R
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Added: pkg/quantstrat/R/match.names.R
===================================================================
--- pkg/quantstrat/R/match.names.R	                        (rev 0)
+++ pkg/quantstrat/R/match.names.R	2010-02-03 21:32:54 UTC (rev 224)
@@ -0,0 +1,38 @@
+#' match names in data to a list of partial name matches
+#' 
+#' Often, the generic definition of a signal or indicator will include 
+#' partial name matches.  In financial data, common partial matches include
+#' 'Close', 'Open', and 'Volume', but there are many more.  
+#' 
+#' In complex data, additional name information may be added to column names
+#' for example, a symbol or an indicator of some adjustment may be added.
+#' 
+#' This small utility exists to do the matching in a centralized location 
+#' so that more robust error handling and reporting can be conducted.
+#'    
+#' @param data_names names for the data to be matched to
+#' @param match_names names to match
+#' @export
+match.names <- function(data_names,match_names) {
+    loc<-vector()
+    for (mname in match_names){
+        loc <- c(loc,grep(mname,data_names))
+    }
+    if ( !identical(length(loc),length(match_names)) ) {
+        warning(paste("all columns not located in",as.character(match_names),"for",as.character(data_names)))  
+    }
+    return(loc)
+}
+
+###############################################################################
+# R (http://r-project.org/) Quantitative Strategy Model Framework
+#
+# Copyright (c) 2009-2010
+# Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, Jeffrey Ryan, and Joshua Ulrich 
+#
+# This library is distributed under the terms of the GNU Public License (GPL)
+# for full details see the file COPYING
+#
+# $Id$
+#
+###############################################################################


Property changes on: pkg/quantstrat/R/match.names.R
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Added: pkg/quantstrat/R/signals.R
===================================================================
--- pkg/quantstrat/R/signals.R	                        (rev 0)
+++ pkg/quantstrat/R/signals.R	2010-02-03 21:32:54 UTC (rev 224)
@@ -0,0 +1,194 @@
+
+#' add an signal to a strategy
+#' @param strategy an object of type 'strategy' to add the signal to
+#' @param name name of the signal, must correspond to an R function
+#' @param arguments default arguments to be passed to an signal function when executed
+#' @param label arbitrary text label for signal output, NULL default will be converted to '<name>.sig'
+#' @param ... any other passthru parameters
+#' @param enabled TRUE/FALSE whether the signal is enabled for use in applying the strategy, default TRUE
+#' @param indexnum if you are updating a specific signal, the index number in the $signals list to update
+#' @param store TRUE/FALSE whether to store the strategy in the .strategy environment, or return it.  default FALSE
+#' @export
+add.signal <- function(strategy, name, arguments, label=NULL, ..., enabled=TRUE, indexnum=NULL, store=FALSE) {
+    if(!is.strategy(strategy)) stop("You must pass in a strategy object to manipulate")
+    tmp_signal<-list()
+    tmp_signal$name<-name
+    if(is.null(label)) label = paste(name,"sig",sep='.')
+    tmp_signal$label<-label
+    tmp_signal$enabled<-enabled
+    if (!is.list(arguments)) stop("arguments must be passed as a named list")
+    arguments$label=label
+    tmp_signal$arguments<-arguments
+    if(!hasArg(indexnum) | (hasArg(indexnum) & is.null(indexnum))) indexnum = length(strategy$signals)+1
+    tmp_signal$call<-match.call()
+    strategy$signals[[indexnum]]<-tmp_signal
+    
+    if (store) assign(strategy$name,strategy,envir=as.environment(.strategy))
+    else return(strategy)
+}
+
+#' apply the signals in the strategy to arbitrary market data
+#' @param strategy an object of type 'strategy' to add the signal to
+#' @param mktdata an xts object containing market data.  depending on signals, may need to be in OHLCV or BBO formats
+#' @param indicators if indicator output is not contained in the mktdata object, it may be passed separately an xts object or a list.
+#' @param ... any other passthru parameters
+#' @export
+applySignals <- function(strategy, mktdata, indicators=NULL, ...) {
+    #TODO add Date subsetting
+    
+    # TODO check for symbol name in mktdata using Josh's code:
+    # symbol <- strsplit(colnames(mktdata)[1],"\\.")[[1]][1]
+    
+    if (!is.strategy(strategy)) {
+        strategy<-try(getStrategy(strategy))
+        if(inherits(strategy,"try-error"))
+            stop ("You must supply an object of type 'strategy'.")
+    } 
+    ret <- NULL
+    nargs <-list(...)
+    if(length(nargs)==0) nargs=NULL
+    if (length('...')==0 | is.null('...')) {
+        #rm('...')
+        nargs=NULL
+    }
+    
+    for (signal in strategy$signals){
+        #TODO check to see if they've already been calculated
+        if(!is.function(get(signal$name)) & !is.function(get(paste("sig",signal$name,sep='.')))) {
+            message(paste("Skipping signal",signal$name,"because there is no function by that name to call"))
+            next()
+        }
+        
+        # see 'S Programming p. 67 for this matching
+        fun<-try(match.fun(signal$name),silent=TRUE)
+        if(inherits(fun,,"try-error")) fun <- match.fun(paste(sig,signal$name,'.'))
+        .formals  <- formals(fun)
+        onames <- names(.formals)
+        
+        pm <- pmatch(names(signal$arguments), onames, nomatch = 0L)
+        if (any(pm == 0L))
+            warning(paste("some arguments stored for",signal$name,"do not match"))
+        names(signal$arguments[pm > 0L]) <- onames[pm]
+        .formals[pm] <- signal$arguments[pm > 0L]
+        #now add dots
+        if (length(nargs)) {
+            pm <- pmatch(names(nargs), onames, nomatch = 0L)
+            names(nargs[pm > 0L]) <- onames[pm]
+            .formals[pm] <- nargs[pm > 0L]
+        }
+        .formals$... <- NULL
+        
+        formals(fun) <- .formals
+        tmp_val<-do.call(fun,.formals)
+        if(is.null(names(tmp_val)) & ncol(tmp_val)==1) names(tmp_val)<-signal$label
+        if (nrow(mktdata)==nrow(tmp_val) | length(mktdata)==length(tmp_val)) {
+            # the signal returned a time series, so we'll name it and cbind it
+            mktdata<-cbind(mktdata,tmp_val)
+        } else {
+            # the signal returned something else, add it to the ret list
+            if(is.null(ret)) ret<-list()
+            ret[[signal$name]]<-tmp_val
+        }
+        #print(tmp_val)
+    } #end signals loop
+    if(is.null(ret)) return(mktdata)
+    else return(list(mktdata=mktdata,signal_ret=ret))
+}
+
+
+#' signal function for comparisons
+#' @param label text label to apply to the output
+#' @param data data to apply comparison to
+#' @param columns named columns to apply comparison to
+#' @param relationship one of c("gt","lt","eq","gte","lte") or reasonable alternatives
+#' @export
+sigComparison <- function(label,data, columns, relationship=c("gt","lt","eq","gte","lte")) {
+    relationship=relationship[1] #only use the first one
+    if (length(columns==2)){
+        ret_sig=NULL
+        columns <- match.names(colnames(data),columns)
+        switch(relationship,
+                '>'  =,
+                'gt' = {ret_sig = data[,columns[1]] > data[,columns[2]]},
+                '<'  =,
+                'lt' = {ret_sig = data[,columns[1]] < data[,columns[2]]},
+                'eq'     = {ret_sig = data[,columns[1]] == data[,columns[2]]}, #FIXME any way to specify '='?
+                'gte' =,
+                'gteq'=,
+                'ge'     = {ret_sig = data[,columns[1]] >= data[,columns[2]]}, #FIXME these fail with an 'unexpected =' error if you use '>=' 
+                'lte' =,
+                'lteq'=,
+                'le' 	 = {ret_sig = data[,columns[1]] <= data[,columns[2]]}
+        )
+    } else {
+        stop("comparison of more than two columns not supported yet, patches welcome")
+    }
+    colnames(ret_sig)<-label
+    return(ret_sig)
+}
+
+sigCrossover <- sigComparison <- function(label,data, columns, relationship=c("gt","lt","eq","gte","lte")) {
+    # TODO should call sigComparison and then do a diff so we only have the signal in the period it actually changes
+}
+
+#' signal function for peak/valley signals
+#' @param label text label to apply to the output
+#' @param data data to apply comparison to
+#' @param column named column to apply comparison to
+#' @param direction one of "peak" or "bottom" to calculate  peaks for
+#' @export
+sigPeak <- function(label,data,column, direction=c("peak","bottom")){
+    #should we only do this for one column?
+    column<-match.names(colnames(data),columns)
+    direction=direction[1] # only use the first]
+    #(Lag(IBM[,4],2)<Lag(IBM[,4],1)) & Lag(IBM[,4],1) >IBM[,4]
+    switch(direction,
+           "peak"   = { Lag(data[,column],2) < Lag(data[,column],1) & Lag(data[,column],1) > data[,column] } ,
+           "bottom","valley" = { Lag(data[,column],2) > Lag(data[,column],1) & Lag(data[,column],1) < data[,column] }
+    )
+    colnames(ret_sig)<-paste(label,direction,"sig",sep='.')
+    return(ret_sig)
+}
+
+#' signal function for threshold signal
+#' @param label text label to apply to the output
+#' @param data data to apply comparison to
+#' @param column named column to apply comparison to
+#' @param relationship one of c("gt","lt","eq","gte","lte") or reasonable alternatives
+#' @export
+sigThreshold <- function(label, data, column, threshold=0, relationship=c("gt","lt","eq","gte","lte")) {
+    relationship=relationship[1] #only use the first one
+    ret_sig=NULL
+    column <- match.names(colnames(data),column)
+    switch(relationship,
+            '>' =,
+            'gt' = {ret_sig = data[,column] > threshold},
+            '<' =,
+            'lt' = {ret_sig = data[,column] < threshold},
+            'eq'     = {ret_sig = data[,columns[1]] == threshold}, #FIXME any way to specify '='?
+            'gte' =,
+            'gteq'=,
+            'ge'     = {ret_sig = data[,columns[1]] >= threshold}, #FIXME these fail with an 'unexpected =' error if you use '>='
+            'lte' =,
+            'lteq'=,
+            'le'     = {ret_sig = data[,columns[1]] <= threshold}
+    )
+    colnames(ret_sig)<-label
+    return(ret_sig)
+}
+
+#TODO Going Up/Going Down maybe better implemented as slope/diff() indicator, then coupled with threshold signal 
+#TODO set/reset indicator/signal for n-periods since some other signal is set, or signal set for n periods
+
+###############################################################################
+# R (http://r-project.org/) Quantitative Strategy Model Framework
+#
+# Copyright (c) 2009-2010
+# Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, Jeffrey Ryan, and Joshua Ulrich 
+#
+# This library is distributed under the terms of the GNU Public License (GPL)
+# for full details see the file COPYING
+#
+# $Id$
+#
+###############################################################################


Property changes on: pkg/quantstrat/R/signals.R
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Modified: pkg/quantstrat/R/strategy.R
===================================================================
--- pkg/quantstrat/R/strategy.R	2010-02-02 12:47:13 UTC (rev 223)
+++ pkg/quantstrat/R/strategy.R	2010-02-03 21:32:54 UTC (rev 224)
@@ -58,7 +58,7 @@
 #' @param mktdata an xts object containing market data.  depending on indicators, may need to be in OHLCV or BBO formats
 #' @param ... any other passthru parameters
 #' @export
-applyStrategy <- function(strategy,mktdata, ... ) {
+applyStrategy <- function(strategy , mktdata , ... ) {
     #TODO add Date subsetting
     
     ret<-list()
@@ -70,79 +70,16 @@
     } 
     
     #loop over indicators
-    ret$indicators <- applyIndicators(strategy,mktdata, ... )
+    ret$indicators <- applyIndicators(strategy , mktdata , ... )
      
     #loop over signal generators
-    
+    ret$signals <- applySignals(strategy, mktdata, indicators, ... )
+
     #loop over rules 
     
-    return(ret)
-}
-
-#' apply the indicators in the strategy to arbitrary market data
-#' @param strategy an object of type 'strategy' to add the indicator to
-#' @param mktdata an xts object containing market data.  depending on indicators, may need to be in OHLCV or BBO formats
-#' @param ... any other passthru parameters
-#' @export
-applyIndicators <- function(strategy, mktdata, ...) {
-    #TODO add Date subsetting
     
-    # TODO check for symbol name in mktdata using Josh's code:
-    # symbol <- strsplit(colnames(mktdata)[1],"\\.")[[1]][1]
     
-    if (!is.strategy(strategy)) {
-        strategy<-try(getStrategy(strategy))
-        if(inherits(strategy,"try-error"))
-            stop ("You must supply an object of type 'strategy'.")
-    } 
-    ret <- NULL
-    nargs <-list(...)
-    if(length(nargs)==0) nargs=NULL
-    if (length('...')==0 | is.null('...')) {
-        rm('...')
-        nargs=NULL
-    }
-    
-    for (indicator in strategy$indicators){
-        #TODO check to see if they've already been calculated
-        if(!is.function(get(indicator$name))) {
-            message(paste("Skipping indicator",indicator$name,"because there is no function by that name to call"))
-            next()
-        }
-        
-        # see 'S Programming p. 67 for this matching
-        fun<-match.fun(indicator$name)
-        .formals  <- formals(fun)
-        onames <- names(.formals)
-        
-        pm <- pmatch(names(indicator$arguments), onames, nomatch = 0L)
-        if (any(pm == 0L))
-            warning(paste("some arguments stored for",indicator$name,"do not match"))
-        names(indicator$arguments[pm > 0L]) <- onames[pm]
-        .formals[pm] <- indicator$arguments[pm > 0L]
-        #now add dots
-        if (length(nargs)) {
-            pm <- pmatch(names(nargs), onames, nomatch = 0L)
-            names(nargs[pm > 0L]) <- onames[pm]
-            .formals[pm] <- nargs[pm > 0L]
-        }
-        .formals$... <- NULL
-        
-        formals(fun) <- .formals
-        tmp_val<-do.call(fun,.formals)
-        if(is.null(names(tmp_val)) & ncol(tmp_val)==1) names(tmp_val)<-indicator$name
-        if (nrow(mktdata)==nrow(tmp_val) | length(mktdata)==length(tmp_val)) {
-            # the indicator returned a time series, so we'll name it and cbind it
-            mktdata<-cbind(mktdata,tmp_val)
-        } else {
-            # the indicator returned something else, add it to the ret list
-            if(is.null(ret)) ret<-list()
-            ret[[indicator$name]]<-tmp_val
-        }
-        #print(tmp_val)
-    } #end indicators loop
-    if(is.null(ret)) return(mktdata)
-    else return(list(mktdata=mktdata,indicator_ret=ret))
+    return(ret)
 }
 
 #' test to see if object is of type 'strategy'
@@ -179,6 +116,6 @@
 # This library is distributed under the terms of the GNU Public License (GPL)
 # for full details see the file COPYING
 #
-# $Id: strategy.R 217 2010-01-29 18:10:53Z braverock $
+# $Id$
 #
 ###############################################################################


Property changes on: pkg/quantstrat/R/strategy.R
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author


Property changes on: pkg/quantstrat/demo/00Index
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Modified: pkg/quantstrat/demo/simplestrat.R
===================================================================
--- pkg/quantstrat/demo/simplestrat.R	2010-02-02 12:47:13 UTC (rev 223)
+++ pkg/quantstrat/demo/simplestrat.R	2010-02-03 21:32:54 UTC (rev 224)
@@ -1,7 +1,16 @@
 
 s <- strategy("simplestrat")
-s <- add.indicator(strategy = s, name = "EMA", arguments = list(x = quote(Cl(mktdata)), n=10))
-s <- add.indicator(strategy = s, name = "BBands", arguments = list(HLC = quote(HLC(mktdata)), sd = 1.8,maType=quote(SMA)))
+s <- add.indicator(strategy = s, name = "SMA", arguments = list(x = quote(Cl(mktdata)), n=10), label="SMA10")
 
+# this indicator fails on dots, so we'll not enable it for now
+#s <- add.indicator(strategy = s, name = "BBands", arguments = list(HLC = quote(HLC(mktdata)), sd = 1.8,maType=quote(SMA)))
+
 getSymbols("IBM")
-applyIndicators(s,IBM)
\ No newline at end of file
+IBM.mod=applyIndicators(s,mktdata=IBM)
+
+#manually apply a signal function for demonstration
+IBM.mod = cbind(IBM.mod,sigComparison(label="Close.gt.Open",data=IBM.mod,columns=c("Close","Open"),">"))
+IBM.mod = cbind(IBM.mod,sigComparison(label="Adjusted.gt.SMA",data=IBM.mod,columns=c("Adjusted","SMA10"),">"))
+
+#or, do it properly and add it to the strategy:
+s<- add.indicator(s,name="sigComparison",arguments = list(data=quote(mktdata),columns=c("Close","Open"),relationship=">"))label="Close.gt.Open")
\ No newline at end of file


Property changes on: pkg/quantstrat/demo/simplestrat.R
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Modified: pkg/quantstrat/man/add.indicator.Rd
===================================================================
--- pkg/quantstrat/man/add.indicator.Rd	2010-02-02 12:47:13 UTC (rev 223)
+++ pkg/quantstrat/man/add.indicator.Rd	2010-02-03 21:32:54 UTC (rev 224)
@@ -1,11 +1,12 @@
 \name{add.indicator}
 \alias{add.indicator}
 \title{add an indicator to a strategy...}
-\usage{add.indicator(strategy, name, arguments, ..., indexnum, store=FALSE)}
+\usage{add.indicator(strategy, name, arguments, label, ..., enabled=TRUE, indexnum, store=FALSE)}
 \description{add an indicator to a strategy}
 \arguments{\item{strategy}{an object of type 'strategy' to add the indicator to}
 \item{name}{name of the indicator, must correspond to an R function}
 \item{arguments}{default arguments to be passed to an indicator function when executed}
 \item{...}{any other passthru parameters}
+\item{enabled}{TRUE/FALSE whether the indicator is enabled for use in applying the strategy, default TRUE}
 \item{indexnum}{if you are updating a specific indicator, the index number in the $indicators list to update}
 \item{store}{TRUE/FALSE whether to store the strategy in the .strategy environment, or return it.  default FALSE}}


Property changes on: pkg/quantstrat/man/add.indicator.Rd
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Added: pkg/quantstrat/man/add.signal.Rd
===================================================================
--- pkg/quantstrat/man/add.signal.Rd	                        (rev 0)
+++ pkg/quantstrat/man/add.signal.Rd	2010-02-03 21:32:54 UTC (rev 224)
@@ -0,0 +1,13 @@
+\name{add.signal}
+\alias{add.signal}
+\title{add an signal to a strategy...}
+\usage{add.signal(strategy, name, arguments, label, ..., enabled=TRUE, indexnum, store=FALSE)}
+\description{add an signal to a strategy}
+\arguments{\item{strategy}{an object of type 'strategy' to add the signal to}
+\item{name}{name of the signal, must correspond to an R function}
+\item{arguments}{default arguments to be passed to an signal function when executed}
+\item{label}{arbitrary text label for signal output, NULL default will be converted to '<name>.sig'}
+\item{...}{any other passthru parameters}
+\item{enabled}{TRUE/FALSE whether the signal is enabled for use in applying the strategy, default TRUE}
+\item{indexnum}{if you are updating a specific signal, the index number in the $signals list to update}
+\item{store}{TRUE/FALSE whether to store the strategy in the .strategy environment, or return it.  default FALSE}}


Property changes on: pkg/quantstrat/man/add.signal.Rd
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author


Property changes on: pkg/quantstrat/man/applyIndicators.Rd
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Added: pkg/quantstrat/man/applySignals.Rd
===================================================================
--- pkg/quantstrat/man/applySignals.Rd	                        (rev 0)
+++ pkg/quantstrat/man/applySignals.Rd	2010-02-03 21:32:54 UTC (rev 224)
@@ -0,0 +1,9 @@
+\name{applySignals}
+\alias{applySignals}
+\title{apply the signals in the strategy to arbitrary market data...}
+\usage{applySignals(strategy, mktdata, indicators, ...)}
+\description{apply the signals in the strategy to arbitrary market data}
+\arguments{\item{strategy}{an object of type 'strategy' to add the signal to}
+\item{mktdata}{an xts object containing market data.  depending on signals, may need to be in OHLCV or BBO formats}
+\item{indicators}{if indicator output is not contained in the mktdata object, it may be passed separately an xts object or a list.}
+\item{...}{any other passthru parameters}}


Property changes on: pkg/quantstrat/man/applySignals.Rd
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author


Property changes on: pkg/quantstrat/man/applyStrategy.Rd
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author


Property changes on: pkg/quantstrat/man/getStrategy.Rd
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author


Property changes on: pkg/quantstrat/man/is.strategy.Rd
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Added: pkg/quantstrat/man/match.names.Rd
===================================================================
--- pkg/quantstrat/man/match.names.Rd	                        (rev 0)
+++ pkg/quantstrat/man/match.names.Rd	2010-02-03 21:32:54 UTC (rev 224)
@@ -0,0 +1,16 @@
+\name{match.names}
+\alias{match.names}
+\title{match names in data to a list of partial name matches...}
+\usage{match.names(data_names, match_names)}
+\description{match names in data to a list of partial name matches}
+\details{Often, the generic definition of a signal or indicator will include 
+partial name matches.  In financial data, common partial matches include
+'Close', 'Open', and 'Volume', but there are many more.  
+
+In complex data, additional name information may be added to column names
+for example, a symbol or an indicator of some adjustment may be added.
+
+This small utility exists to do the matching in a centralized location 
+so that more robust error handling and reporting can be conducted.}
+\arguments{\item{data_names}{names for the data to be matched to}
+\item{match_names}{names to match}}


Property changes on: pkg/quantstrat/man/match.names.Rd
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Added: pkg/quantstrat/man/sigComparison.Rd
===================================================================
--- pkg/quantstrat/man/sigComparison.Rd	                        (rev 0)
+++ pkg/quantstrat/man/sigComparison.Rd	2010-02-03 21:32:54 UTC (rev 224)
@@ -0,0 +1,9 @@
+\name{sigComparison}
+\alias{sigComparison}
+\title{signal function for comparisons...}
+\usage{sigComparison(label, data, columns, relationship=c("gt", "lt", "eq", "gte", "lte"))}
+\description{signal function for comparisons}
+\arguments{\item{label}{text label to apply to the output}
+\item{data}{data to apply comparison to}
+\item{columns}{named columns to apply comparison to}
+\item{relationship}{one of c("gt","lt","eq","gte","lte") or reasonable alternatives}}


Property changes on: pkg/quantstrat/man/sigComparison.Rd
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Added: pkg/quantstrat/man/sigCrossover.Rd
===================================================================
--- pkg/quantstrat/man/sigCrossover.Rd	                        (rev 0)
+++ pkg/quantstrat/man/sigCrossover.Rd	2010-02-03 21:32:54 UTC (rev 224)
@@ -0,0 +1,3 @@
+\name{sigCrossover}
+\alias{sigCrossover}
+\title{sigCrossover}


Property changes on: pkg/quantstrat/man/sigCrossover.Rd
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Added: pkg/quantstrat/man/sigPeak.Rd
===================================================================
--- pkg/quantstrat/man/sigPeak.Rd	                        (rev 0)
+++ pkg/quantstrat/man/sigPeak.Rd	2010-02-03 21:32:54 UTC (rev 224)
@@ -0,0 +1,9 @@
+\name{sigPeak}
+\alias{sigPeak}
+\title{signal function for peak/valley signals...}
+\usage{sigPeak(label, data, column, direction=c("peak", "bottom"))}
+\description{signal function for peak/valley signals}
+\arguments{\item{label}{text label to apply to the output}
+\item{data}{data to apply comparison to}
+\item{column}{named column to apply comparison to}
+\item{direction}{one of "peak" or "bottom" to calculate  peaks for}}


Property changes on: pkg/quantstrat/man/sigPeak.Rd
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author

Added: pkg/quantstrat/man/sigThreshold.Rd
===================================================================
--- pkg/quantstrat/man/sigThreshold.Rd	                        (rev 0)
+++ pkg/quantstrat/man/sigThreshold.Rd	2010-02-03 21:32:54 UTC (rev 224)
@@ -0,0 +1,9 @@
+\name{sigThreshold}
+\alias{sigThreshold}
+\title{signal function for threshold signal...}
+\usage{sigThreshold(label, data, column, threshold=0, relationship=c("gt", "lt", "eq", "gte", "lte"))}
+\description{signal function for threshold signal}
+\arguments{\item{label}{text label to apply to the output}
+\item{data}{data to apply comparison to}
+\item{column}{named column to apply comparison to}
+\item{relationship}{one of c("gt","lt","eq","gte","lte") or reasonable alternatives}}


Property changes on: pkg/quantstrat/man/sigThreshold.Rd
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author


Property changes on: pkg/quantstrat/man/strategy.Rd
___________________________________________________________________
Name: svn:keywords
   + Revision Id Date Author



More information about the Blotter-commits mailing list