[Blotter-commits] r588 - pkg/quantstrat/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 31 16:24:31 CEST 2011


Author: braverock
Date: 2011-03-31 16:24:31 +0200 (Thu, 31 Mar 2011)
New Revision: 588

Modified:
   pkg/quantstrat/R/signals.R
Log:
- fix sigPeak

Modified: pkg/quantstrat/R/signals.R
===================================================================
--- pkg/quantstrat/R/signals.R	2011-03-28 19:00:01 UTC (rev 587)
+++ pkg/quantstrat/R/signals.R	2011-03-31 14:24:31 UTC (rev 588)
@@ -209,14 +209,16 @@
 #' @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?
-    colNum<-match.names(column,colnames(data))
+    if(!is.numeric(column)){
+        colNum<-match.names(column,colnames(data))   
+    } else colNum<-column
     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[,colNum],2) < Lag(data[,colNum],1) & Lag(data[,colNum],1) > data[,colNum] } ,
-           "bottom","valley" = { Lag(data[,colNum],2) > Lag(data[,colNum],1) & Lag(data[,colNum],1) < data[,colNum] }
+           "peak"   = { ret_sig <- Lag(data[,colNum],2) < Lag(data[,colNum],1) & Lag(data[,colNum],1) > data[,colNum] } ,
+           "bottom","valley" = { ret_sig <- Lag(data[,colNum],2) > Lag(data[,colNum],1) & Lag(data[,colNum],1) < data[,colNum] }
     )
+    Lag(ret_sig,-1)
     colnames(ret_sig)<-paste(label,direction,"sig",sep='.')
     return(ret_sig)
 }



More information about the Blotter-commits mailing list