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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jan 21 12:22:28 CET 2015


Author: michaelguan326
Date: 2015-01-21 12:22:28 +0100 (Wed, 21 Jan 2015)
New Revision: 1673

Modified:
   pkg/quantstrat/NAMESPACE
   pkg/quantstrat/R/signals.R
   pkg/quantstrat/demo/signal.RSI.R
   pkg/quantstrat/demo/signal.SMA.R
   pkg/quantstrat/man/ruleOrderProc.Rd
Log:
Exported necessary functions to make Signal Analysis demos work.

Modified: pkg/quantstrat/NAMESPACE
===================================================================
--- pkg/quantstrat/NAMESPACE	2015-01-19 23:30:42 UTC (rev 1672)
+++ pkg/quantstrat/NAMESPACE	2015-01-21 11:22:28 UTC (rev 1673)
@@ -1,6 +1,5 @@
 # Generated by roxygen2 (4.0.2): do not edit by hand
 
-S3method(plot,signal.path)
 export(add.distribution)
 export(add.distribution.constraint)
 export(add.indicator)
@@ -11,14 +10,17 @@
 export(addPosLimit)
 export(apply.paramset)
 export(apply.paramset.signal.analysis)
+export(applyIndicatorSignals)
 export(applyIndicators)
 export(applyRules)
 export(applySignals)
 export(applyStrategy)
 export(applyStrategy.rebalancing)
+export(beanplot.signals)
 export(chart.forward)
 export(chart.forward.training)
 export(delete.paramset)
+export(distributional.boxplot)
 export(enable.rule)
 export(get.orderbook)
 export(get.strategy)
@@ -34,6 +36,7 @@
 export(match.names)
 export(osMaxPos)
 export(osNoOp)
+export(post.signal.returns)
 export(put.orderbook)
 export(put.strategy)
 export(rm.strat)
@@ -48,6 +51,10 @@
 export(sigPeak)
 export(sigThreshold)
 export(sigTimestamp)
+export(signal.generate.statistics)
+export(signal.obj.slope)
+export(signal.path.plot)
+export(signal.plot)
 export(strategy)
 export(tradeGraphs)
 export(tradeOrderStats)

Modified: pkg/quantstrat/R/signals.R
===================================================================
--- pkg/quantstrat/R/signals.R	2015-01-19 23:30:42 UTC (rev 1672)
+++ pkg/quantstrat/R/signals.R	2015-01-21 11:22:28 UTC (rev 1673)
@@ -522,6 +522,7 @@
 #' \code{\link{apply.paramset.signal.analysis}}
 #' \code{\link{applyIndicators}}
 #' \code{\link{applySignals}}
+#' @export
 
 applyIndicatorSignals<-function(strategy, portfolio, mktdata, sigcol, ...){
   
@@ -560,6 +561,7 @@
 #' @return objective function values
 #' @seealso 
 #' \code{\link{apply.paramset.signal.analysis}}
+#' @export
 
 signal.generate.statistics<-function(post.ret, obj.fun=NULL, decreasing=TRUE){
   if(is.null(obj.fun)) stop("Must define an objective function for signal sorting.")
@@ -597,6 +599,7 @@
 #' @return \code{matrix} of post signal price changes; rows = nth signal, column = nth period since signal
 #' @seealso 
 #' \code{\link{apply.paramset.signal.analysis}}
+#' @export
 
 post.signal.returns<-function(signals,sigval,on=NULL,forward.days,cum.sum=TRUE,
                               include.day.of.signal=FALSE,mktdata=NULL){
@@ -750,6 +753,7 @@
 #' @return Single Objective Value
 #' @seealso 
 #' \code{\link{apply.paramset.signal.analysis}}
+#' @export
 
 signal.obj.slope<-function(x){
   mu = colMeans(x)
@@ -779,10 +783,9 @@
 #' @param h the y-value(s) for horizontal line(s).
 #' @param hlinecol A specification for the default plotting color. See section ‘Color Specification’.
 #' @author Michael Guan
-#' @return plot
-#' 
+#' @export
 
-plot.signals<-function(signals,rows=NULL,columns=NULL,mai = c(0.1,0.4,0.2,0.1), mgp = c(1,1,0),
+signal.plot<-function(signals,rows=NULL,columns=NULL,mai = c(0.1,0.4,0.2,0.1), mgp = c(1,1,0),
                        xlab='',ylab='',cex.main=0.6,xaxt='n',cex.axis=0.5,h=0,hlinecol='red',...){
   
   if(is.null(signals)) stop('No signals to plot')
@@ -825,6 +828,7 @@
 #' @param hlinecol A specification for the default plotting color. See section ‘Color Specification’.
 #' @author Michael Guan
 #' @return plot
+#' @export
  
 beanplot.signals<-function(signals,rows=NULL,columns=NULL,mai = c(0.1,0.4,0.2,0.1), mgp = c(1,1,0),
                            xlab='',ylab='',cex.main=0.6,xaxt='n',cex.axis=0.5,
@@ -863,6 +867,7 @@
 #' @param h the y-value(s) for horizontal line(s).
 #' @author Michael Guan
 #' @return plot
+#' @export
 
 distributional.boxplot<-function(signal,x.val=seq(1, 50, 5),val=10,ylim=c(-5, 5),
                                  xlim=c(0, 50),mai=c(1,1,0.3,0.5),h=0,...){
@@ -913,10 +918,10 @@
 #' @examples
 #' \dontrun{
 #' # signalAnalysisExample1.R
-#' plot.signal.path(results$sigret.by.asset$RTH$paramset.1.5[1:10,])
+#' plot.signal.path(results$sigret.by.asset$RTH$paramset.1.5[1:10,])s
 #' }
 #' @export
-plot.signal.path<-function(data,main='Cumulative Return Paths'){
+signal.path.plot<-function(data,main='Cumulative Return Paths'){
   require(rCharts) #TODO: Need to wrap around If statement
   require(reshape2)
   data = t(data)

Modified: pkg/quantstrat/demo/signal.RSI.R
===================================================================
--- pkg/quantstrat/demo/signal.RSI.R	2015-01-19 23:30:42 UTC (rev 1672)
+++ pkg/quantstrat/demo/signal.RSI.R	2015-01-21 11:22:28 UTC (rev 1673)
@@ -18,7 +18,7 @@
 #Data
 currency("USD")
 currency("EUR")
-symbols = c("XLF", "XLP")
+symbols = c("SPY")
 for(symbol in symbols){ # establish trade-able instruments
   stock(symbol, currency="USD",multiplier=1)
   getSymbols(symbol,src='yahoo')
@@ -67,7 +67,7 @@
                                         port.st, 
                                         sigcol = signal.label,
                                         sigval = 1,
-                                        on='days',
+                                        on=NULL,
                                         forward.days=10,
                                         cum.sum=TRUE,
                                         include.day.of.signal=F,
@@ -78,10 +78,10 @@
 
 
 # Plot Paramset Combined Barchart [Subset list to plot a sub portion if too large]
-plot.signals(results$sigret.by.asset$XLF, rows=2, columns = 5)
+signal.plot(results$sigret.by.asset$SPY, rows=2, columns = 5)
 
 # Distributional Box Plot via gamlss
-distributional.boxplot(results$sigret.by.asset$XLF$paramset.2)
+distributional.boxplot(results$sigret.by.asset$SPY$paramset.2)
 
 ###############################################################################
 # R (http://r-project.org/) Quantitative Strategy Model Framework

Modified: pkg/quantstrat/demo/signal.SMA.R
===================================================================
--- pkg/quantstrat/demo/signal.SMA.R	2015-01-19 23:30:42 UTC (rev 1672)
+++ pkg/quantstrat/demo/signal.SMA.R	2015-01-21 11:22:28 UTC (rev 1673)
@@ -105,9 +105,9 @@
                        x.val=seq(1, 50, 5),val=10,ylim=c(-20, 20),
                        xlim=c(0, 50),mai=c(1,1,0.3,0.5),h=0)
 
-plot.signals(results$sigret.by.asset$XLE, rows=5, columns = 4)
+signal.plot(results$sigret.by.asset$XLE, rows=5, columns = 4)
 beanplot.signals(results$sigret.by.asset$XLE, rows=5, columns = 4)
-plot.signal.path(results$sigret.by.asset$IYT$paramset.5.20)
+signal.path.plot(results$sigret.by.asset$IYT$paramset.5.20)
 
 
 # Daily Signal With Post Weekly Return Analysis

Modified: pkg/quantstrat/man/ruleOrderProc.Rd
===================================================================
--- pkg/quantstrat/man/ruleOrderProc.Rd	2015-01-19 23:30:42 UTC (rev 1672)
+++ pkg/quantstrat/man/ruleOrderProc.Rd	2015-01-21 11:22:28 UTC (rev 1673)
@@ -5,9 +5,6 @@
 \usage{
 ruleOrderProc(portfolio, symbol, mktdata, timestamp = NULL,
   ordertype = NULL, ..., slippageFUN = NULL)
-
-ruleOrderProc(portfolio, symbol, mktdata, timestamp = NULL,
-  ordertype = NULL, ..., slippageFUN = NULL)
 }
 \arguments{
 \item{portfolio}{text name of the portfolio to associate the order book with}
@@ -23,31 +20,12 @@
 \item{...}{any other passthru parameters}
 
 \item{slippageFUN}{default  NULL, not yet implemented}
-
-\item{portfolio}{text name of the portfolio to associate the order book with}
-
-\item{symbol}{identfier of the instrument to find orders for.  The name of any associated price objects (xts prices, usually OHLC or BBO) should match these}
-
-\item{mktdata}{an xts object containing market data.  depending on indicators, may need to be in OHLCV or BBO formats, default NULL}
-
-\item{timestamp}{timestamp coercible to POSIXct that will be the time the order will be processed on}
-
-\item{ordertype}{one of NULL, "market","limit","stoplimit", or "stoptrailing" default NULL}
-
-\item{...}{any other passthru parameters}
-
-\item{slippageFUN}{default  NULL, not yet implemented}
 }
 \description{
 The ruleOrderProc function is effectively the default fill simulator for quantstrat.
 This function is meant to be sufficient for backtesting most strategies,
 but would need to be replaced for production use.  It provides the interface
 for taking the order book and determining when orders become trades.
-
-The ruleOrderProc function is effectively the default fill simulator for quantstrat.
-This function is meant to be sufficient for backtesting most strategies,
-but would need to be replaced for production use.  It provides the interface
-for taking the order book and determining when orders become trades.
 }
 \details{
 In this version, in contrast with an earlier version,
@@ -71,28 +49,6 @@
 
 We would like to model slippage here via \code{slippageFUN}.  Code contributions, suggestions,
 and requests appreciated.
-
-In this version, in contrast with an earlier version,
-this function will allow a transaction to cross your current
-position through zero.  The accounting rules for realizing gains in such cases
-are quite complicated, so blotter will split this transaction into two transactions.
-Many brokers will break, revise, or split such transactions for the same reason.
-
-This function would need to be revised or replaced for connection to a live trading infrastructure.
-In a production mode, you would replace the \code{\link{addOrder}} function
-with a custom function to connect to your market infrastructure.
-In that case, you might need to add additional code to your strategy,
-or overload functions for checking position.
-
-Note that this function is called by default in the 'orders' slot of the
-\code{\link{applyRules}} processing.  If you have defined another order
-processing rule, it will \emph{replace} this function.  If you want your
-custom order rule and ruleOrderProc to both be called, you will need
-explicitly add a rule to call ruleOrderProc either before or after your
-custom order processing function.
-
-We would like to model slippage here via \code{slippageFUN}.  Code contributions, suggestions,
-and requests appreciated.
 }
 \seealso{
 add.rule
@@ -104,16 +60,6 @@
 addOrder
 
 updateOrders
-
-add.rule
-
-applyRules
-
-getOrderBook
-
-addOrder
-
-updateOrders
 }
 \concept{
 fill simulator
@@ -127,17 +73,5 @@
 This function is meant to be sufficient for backtesting many/most strategies,
 but would need to be replaced for production use.  It provides the interface
 for taking the order book and determining when orders become trades.
-
-fill simulator
-
-orders
-
-backtest
-
-fills
-
-This function is meant to be sufficient for backtesting many/most strategies,
-but would need to be replaced for production use.  It provides the interface
-for taking the order book and determining when orders become trades.
 }
 



More information about the Blotter-commits mailing list