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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 24 00:23:04 CEST 2013


Author: braverock
Date: 2013-04-24 00:23:04 +0200 (Wed, 24 Apr 2013)
New Revision: 1445

Added:
   pkg/quantstrat/R/tradeOrderStats.R
   pkg/quantstrat/man/tradeOrderStats.Rd
Modified:
   pkg/quantstrat/DESCRIPTION
   pkg/quantstrat/NAMESPACE
   pkg/quantstrat/R/orders.R
   pkg/quantstrat/R/paramsets.R
   pkg/quantstrat/R/ruleRevoke.R
   pkg/quantstrat/R/tradeGraphs.R
   pkg/quantstrat/R/walk.forward.R
   pkg/quantstrat/demo/maCross.R
   pkg/quantstrat/man/addOrder.Rd
   pkg/quantstrat/man/getOrderBook.Rd
   pkg/quantstrat/man/ruleRevoke.Rd
   pkg/quantstrat/man/ruleSignal.Rd
Log:
- add tradeOrderStats
- update roxygen docs
- update NAMESPACE


Modified: pkg/quantstrat/DESCRIPTION
===================================================================
--- pkg/quantstrat/DESCRIPTION	2013-04-22 01:34:03 UTC (rev 1444)
+++ pkg/quantstrat/DESCRIPTION	2013-04-23 22:23:04 UTC (rev 1445)
@@ -1,7 +1,7 @@
 Package: quantstrat
 Type: Package
 Title: Quantitative Strategy Model Framework
-Version: 0.7.7
+Version: 0.7.8
 Date: $Date$
 Author: Peter Carl, Brian G. Peterson, Joshua Ulrich, Jan Humme
 Depends:
@@ -42,3 +42,4 @@
     'utils.R'
     'walk.forward.R'
     'wrapup.R'
+    'tradeOrderStats.R'

Modified: pkg/quantstrat/NAMESPACE
===================================================================
--- pkg/quantstrat/NAMESPACE	2013-04-22 01:34:03 UTC (rev 1444)
+++ pkg/quantstrat/NAMESPACE	2013-04-23 22:23:04 UTC (rev 1445)
@@ -1,3 +1,5 @@
+export(actually)
+export(add)
 export(add.constraint)
 export(add.distribution)
 export(add.indicator)
@@ -13,25 +15,36 @@
 export(applySignals)
 export(applyStrategy)
 export(applyStrategy.rebalancing)
+export(are)
 export(chart.forward.testing)
 export(chart.forward.training)
+export(closing)
+export(columns)
+export(decide)
 export(delete.paramset)
+export("for")
 export(getOrderBook)
 export(getOrders)
 export(getParameterTable)
 export(getPosLimit)
 export(getStrategy)
+export(important)
 export(initOrders)
 export(initStrategy)
 export(is.strategy)
 export(load.strategy)
 export(match.names)
+export(of)
+export(opening)
+export(option)
+export("order/trade")
 export(osMaxPos)
 export(osNoOp)
+export(pairing)
 export(put.orderbook)
 export(put.strategy)
+export(rather)
 export(rm.strat)
-export(ruleCancel)
 export(ruleOrderProc)
 export(rulePctEquity)
 export(ruleRevoke)
@@ -45,7 +58,11 @@
 export(sigPeak)
 export(sigThreshold)
 export(strategy)
+export(than)
+export(these)
+export("TODO:")
 export(tradeGraphs)
 export(updateOrders)
 export(updateStrategy)
 export(walk.forward)
+export(which)

Modified: pkg/quantstrat/R/orders.R
===================================================================
--- pkg/quantstrat/R/orders.R	2013-04-22 01:34:03 UTC (rev 1444)
+++ pkg/quantstrat/R/orders.R	2013-04-23 22:23:04 UTC (rev 1445)
@@ -1,12 +1,26 @@
 #' get the order book object
 #' 
-#' I don't think this should be exported, but it is for now while we're in test mode.
-#' 
 #' @param portfolio text name of the portfolio the order book is associated with
 #' @param envir the environment to retrieve the orderbook object from, defaults to .strategy
 #' @seealso addOrder
 #' @seealso getOrders
 #' @concept order book
+#' @return 
+#' A \code{data.frame} containing:
+#' 
+#' \describe{
+#'      \item{Order.Qty}{}
+#' 		\item{Order.Price}{}
+#' 		\item{Order.Type}{}
+#' 		\item{Order.Side}{}
+#' 		\item{Order.Threshold}{}
+#' 		\item{Order.Status}{}
+#' 		\item{Order.StatusTime}{}
+#' 		\item{Prefer}{}
+#' 		\item{Order.Set}{}
+#' 		\item{Txn.Fees}{}
+#' 		\item{Rule}{}
+#' }         
 #' @export
 getOrderBook <- function(portfolio, envir=.strategy) #should symbol subsets be supported too?  probably not.
 { 

Modified: pkg/quantstrat/R/paramsets.R
===================================================================
--- pkg/quantstrat/R/paramsets.R	2013-04-22 01:34:03 UTC (rev 1444)
+++ pkg/quantstrat/R/paramsets.R	2013-04-23 22:23:04 UTC (rev 1445)
@@ -7,7 +7,7 @@
 # This library is distributed under the terms of the GNU Public License (GPL)
 # for full details see the file COPYING
 #
-# $Id: parameters.R 1218 2012-10-11 20:47:44Z opentrades $
+# $Id$
 #
 ###############################################################################
 #


Property changes on: pkg/quantstrat/R/paramsets.R
___________________________________________________________________
Added: svn:keywords
   + Id Date Author

Modified: pkg/quantstrat/R/ruleRevoke.R
===================================================================
--- pkg/quantstrat/R/ruleRevoke.R	2013-04-22 01:34:03 UTC (rev 1444)
+++ pkg/quantstrat/R/ruleRevoke.R	2013-04-23 22:23:04 UTC (rev 1445)
@@ -2,11 +2,11 @@
 #' 
 #' As described elsewhere in the documentation, quantstrat models 
 #' \emph{orders}.  All orders in quantstrat are GTC orders, which means that
-#' unfilled limit orders have to be revokeled manually or replaced by other orders.
+#' unfilled limit orders have to be canceled manually or replaced by other orders.
 #' 
 #' This function is used for revoking or canceling the orders based on a signal.  
 #' Order status will be changed to 'revoked', to separate it from cancelations or
-#' replacements from other causes.  THis may make it easier it decipher the order book 
+#' replacements from other causes.  This may make it easier it decipher the order book 
 #' to figure out what the strategy ewas doing.
 #' 
 #' @param data an xts object containing market data.  depending on rules, may need to be in OHLCV or BBO formats, and may include indicator and signal information

Modified: pkg/quantstrat/R/tradeGraphs.R
===================================================================
--- pkg/quantstrat/R/tradeGraphs.R	2013-04-22 01:34:03 UTC (rev 1444)
+++ pkg/quantstrat/R/tradeGraphs.R	2013-04-23 22:23:04 UTC (rev 1445)
@@ -69,6 +69,6 @@
 # This library is distributed under the terms of the GNU Public License (GPL)
 # for full details see the file COPYING
 #
-# $Id: wrapup.R 849 2011-11-16 17:47:25Z gsee $
+# $Id$
 #
 ###############################################################################


Property changes on: pkg/quantstrat/R/tradeGraphs.R
___________________________________________________________________
Added: svn:keywords
   + Id Date Author

Added: pkg/quantstrat/R/tradeOrderStats.R
===================================================================
--- pkg/quantstrat/R/tradeOrderStats.R	                        (rev 0)
+++ pkg/quantstrat/R/tradeOrderStats.R	2013-04-23 22:23:04 UTC (rev 1445)
@@ -0,0 +1,64 @@
+#' get order information associated with closing positions
+#' 
+#' 
+#' @param portfolio text name of the portfolio the order book is associated with
+#' @param symbol text string defining the symbol to get trades and orders for
+#' @param ... any other passthrough parameters
+#' @return 
+#' A \code{xts} object containing:
+#' 
+#' \describe{
+#'      \item{Order.Qty}{}
+#' 		\item{Order.Price}{}
+#' 		\item{Order.Type}{}
+#' 		\item{Order.Side}{}
+#' 		\item{Order.Threshold}{}
+#' 		\item{Order.Status}should be 'closed' only{}
+#' 		\item{Order.StatusTime}{time of the closing trade, should match 'End' column}
+#' 		\item{Prefer}{prefer argument for \code{getPrice}}
+#' 		\item{Order.Set}{order set of the closing trade}
+#' 		\item{Txn.Fees}{and fees applied to the closing trade}
+#' 		\item{Rule}{the name of the rule that generated the order which closed the position}
+#'      \item{Start}{the \code{POSIXct} timestamp of the start of the trade}
+#'      \item{Init.Pos}{the initial position on opening the trade}
+#'      \item{Max.Pos}{the maximum (largest) position held during the open trade}
+#'      \item{Num.Txns}{ the number of transactions included in this trade}
+#'      \item{Max.Notional.Cost}{ the largest notional investment cost of this trade}
+#'      \item{Net.Trading.PL}{ net trading P&L in the currency of \code{Symbol}}
+#'      \item{MAE}{ Maximum Adverse Excursion (MAE), in the currency of \code{Symbol}}
+#'      \item{MFE}{ Maximum Favorable Excursion (MFE), in the currency of \code{Symbol}}
+#'      \item{Pct.Net.Trading.PL}{ net trading P&L in percent of invested \code{Symbol} price gained or lost}
+#'      \item{Pct.MAE}{ Maximum Adverse Excursion (MAE), in percent}
+#'      \item{Pct.MFE}{ Maximum Favorable Excursion (MFE), in percent}
+#'      \item{tick.Net.Trading.PL}{  net trading P&L in ticks}
+#'      \item{tick.MAE}{ Maximum Adverse Excursion (MAE) in ticks}
+#'      \item{tick.MFE}{ Maximum Favorable Excursion (MFE) in ticks} 
+#' }
+#' @export
+#' TODO: decide which of these columns are actually important
+#' TODO: add option for opening order/trade pairing rather than closing
+tradeOrderStats <- function(portfolio, symbol, ...) {
+	stats.table <- perTradeStats(Portfolio=portfolio,Symbol=symbol,...)
+	stats.xts <- as.xts(stats_table, order.by=stats.table$End)
+	orderbook <- getOrderBook(portfolio=Portfolio)[[Portfolio]][[symbol]]
+	closed <- orderbook[which(orderbook$Order.Status=='closed'),]
+	closed.xts <- xts(closed, as.POSIXct(as.vector(closed$Order.StatusTime), format='%Y-%m-%d %H:%M:%OS'))
+	merged.table <- merge(closed.xts,stats.xts)
+	merged.closed <- merged.table[index(stats.xts)]
+	return(merged.closed)
+}
+
+
+###############################################################################
+# R (http://r-project.org/) Quantitative Strategy Model Framework
+#
+# Copyright (c) 2009-2012
+# Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, 
+# Jeffrey Ryan, Joshua Ulrich, and Garrett See 
+#
+# This library is distributed under the terms of the GNU Public License (GPL)
+# for full details see the file COPYING
+#
+# $Id: ruleOrderProc.R 1435 2013-04-16 15:23:34Z bodanker $
+#
+###############################################################################


Property changes on: pkg/quantstrat/R/tradeOrderStats.R
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Modified: pkg/quantstrat/R/walk.forward.R
===================================================================
--- pkg/quantstrat/R/walk.forward.R	2013-04-22 01:34:03 UTC (rev 1444)
+++ pkg/quantstrat/R/walk.forward.R	2013-04-23 22:23:04 UTC (rev 1445)
@@ -7,7 +7,7 @@
 # This library is distributed under the terms of the GNU Public License (GPL)
 # for full details see the file COPYING
 #
-# $Id: parameters.R 1218 2012-10-11 20:47:44Z opentrades $
+# $Id$
 #
 ###############################################################################
 #


Property changes on: pkg/quantstrat/R/walk.forward.R
___________________________________________________________________
Added: svn:keywords
   + Id Date Author

Modified: pkg/quantstrat/demo/maCross.R
===================================================================
--- pkg/quantstrat/demo/maCross.R	2013-04-22 01:34:03 UTC (rev 1444)
+++ pkg/quantstrat/demo/maCross.R	2013-04-23 22:23:04 UTC (rev 1445)
@@ -22,11 +22,11 @@
 
 ##### PLACE DEMO AND TEST DATES HERE #################
 #
-if(isTRUE(options('in_test')$in_test))
+if(isTRUE(options('in_test')$in_test)){
   # use test dates
-  {initDate="2011-01-01" 
+  initDate="2011-01-01" 
   endDate="2012-12-31"   
-  } else {
+} else {
   # use demo defaults
   initDate="1999-12-31"
   endDate=Sys.Date()
@@ -36,7 +36,7 @@
 portfolio.st='macross'
 account.st='macross'
 initPortf(portfolio.st,symbols=stock.str, initDate=initDate)
-initAcct(account.st,portfolios=portfolio.st, initDate=initDate)
+initAcct(account.st,portfolios=portfolio.st, initDate=initDate,initEq=initEq)
 initOrders(portfolio=portfolio.st,initDate=initDate)
 
 stratMACROSS<- strategy(portfolio.st)
@@ -74,6 +74,12 @@
 add_SMA(n=50 , on=1,col='blue')
 add_SMA(n=200, on=1)
 
+book    = getOrderBook('macross')
+stats   = tradeStats('macross')
+ptstats = perTradeStats('macross')
+rets    = PortfReturns('macross')
+txns    = getTxns('macross', stock.str)
+
 #Date workaround, remove later
 Sys.setenv(TZ=ttz)
 

Modified: pkg/quantstrat/man/addOrder.Rd
===================================================================
--- pkg/quantstrat/man/addOrder.Rd	2013-04-22 01:34:03 UTC (rev 1444)
+++ pkg/quantstrat/man/addOrder.Rd	2013-04-23 22:23:04 UTC (rev 1445)
@@ -48,8 +48,10 @@
 
   \item{tmult}{if TRUE, threshold is a percent multiplier
   for \code{price}, not a scalar. Threshold is converted to
-  a scalar by multiplying it with the price, then added to
-  the price just like a scalar threshold.}
+  a scalar by multiplying it with the price at the time of
+  order entry (i.e. the scalar will not change if the order
+  is updated, as in the case of a trailing stop), then it
+  is added to the price just like a scalar threshold.}
 
   \item{replace}{TRUE/FALSE, whether to replace any other
   open order(s) on this symbol with the same properties as
@@ -145,10 +147,15 @@
   order types are the only order types that make use of the
   order \code{threshold}. Thresholds may be specified in
   one of 2 ways: as a scalar (\code{tmult=FALSE}) or as a
-  multiplier for the current price (\code{tmult=TRUE}). The
-  threshold is then added to the prefered order price upon
-  order entry. The correct sign for the threshold (pos or
-  neg, ie. add or subtract) is automagically figured out
+  multiplier for the current price (\code{tmult=TRUE}). If
+  \code{tmult=TRUE}, \code{threshold} is converted to a
+  scalar by multiplying it with the price at the time of
+  order entry, and the scalar will not change if the order
+  is updated.
+
+  The threshold is then added to the prefered order price
+  upon order entry. The correct sign for the threshold (pos
+  or neg, ie. add or subtract) is automagically figured out
   from the order side and the order quantity (buy or sell);
   if the user provides the wrong sign for the threshold,
   then it will be reversed. In other words, the user may

Modified: pkg/quantstrat/man/getOrderBook.Rd
===================================================================
--- pkg/quantstrat/man/getOrderBook.Rd	2013-04-22 01:34:03 UTC (rev 1444)
+++ pkg/quantstrat/man/getOrderBook.Rd	2013-04-23 22:23:04 UTC (rev 1445)
@@ -11,9 +11,17 @@
   \item{envir}{the environment to retrieve the orderbook
   object from, defaults to .strategy}
 }
+\value{
+  A \code{data.frame} containing:
+
+  \describe{ \item{Order.Qty}{} \item{Order.Price}{}
+  \item{Order.Type}{} \item{Order.Side}{}
+  \item{Order.Threshold}{} \item{Order.Status}{}
+  \item{Order.StatusTime}{} \item{Prefer}{}
+  \item{Order.Set}{} \item{Txn.Fees}{} \item{Rule}{} }
+}
 \description{
-  I don't think this should be exported, but it is for now
-  while we're in test mode.
+  get the order book object
 }
 \seealso{
   addOrder

Modified: pkg/quantstrat/man/ruleRevoke.Rd
===================================================================
--- pkg/quantstrat/man/ruleRevoke.Rd	2013-04-22 01:34:03 UTC (rev 1444)
+++ pkg/quantstrat/man/ruleRevoke.Rd	2013-04-23 22:23:04 UTC (rev 1445)
@@ -37,13 +37,13 @@
   As described elsewhere in the documentation, quantstrat
   models \emph{orders}.  All orders in quantstrat are GTC
   orders, which means that unfilled limit orders have to be
-  revokeled manually or replaced by other orders.
+  canceled manually or replaced by other orders.
 }
 \details{
   This function is used for revoking or canceling the
   orders based on a signal. Order status will be changed to
   'revoked', to separate it from cancelations or
-  replacements from other causes.  THis may make it easier
+  replacements from other causes.  This may make it easier
   it decipher the order book to figure out what the
   strategy ewas doing.
 }

Modified: pkg/quantstrat/man/ruleSignal.Rd
===================================================================
--- pkg/quantstrat/man/ruleSignal.Rd	2013-04-22 01:34:03 UTC (rev 1444)
+++ pkg/quantstrat/man/ruleSignal.Rd	2013-04-23 22:23:04 UTC (rev 1445)
@@ -40,9 +40,11 @@
   mktdata, default NULL, see Details}
 
   \item{tmult}{if TRUE, threshold is a percent multiplier
-  for \code{price}, not a scalar to be added/subtracted
-  from price.  threshold will be dynamically converted to a
-  scalar at time of order entry}
+  for \code{price}, not a scalar. Threshold is converted to
+  a scalar by multiplying it with the price at the time of
+  order entry (i.e. the scalar will not change if the order
+  is updated, as in the case of a trailing stop), then it
+  is added to the price just like a scalar threshold.}
 
   \item{replace}{TRUE/FALSE, whether to replace any other
   open order(s) on this portfolio symbol, default TRUE}

Added: pkg/quantstrat/man/tradeOrderStats.Rd
===================================================================
--- pkg/quantstrat/man/tradeOrderStats.Rd	                        (rev 0)
+++ pkg/quantstrat/man/tradeOrderStats.Rd	2013-04-23 22:23:04 UTC (rev 1445)
@@ -0,0 +1,52 @@
+\name{tradeOrderStats}
+\alias{tradeOrderStats}
+\title{get order information associated with closing positions}
+\usage{
+  tradeOrderStats(portfolio, symbol, ...)
+}
+\arguments{
+  \item{portfolio}{text name of the portfolio the order
+  book is associated with}
+
+  \item{symbol}{text string defining the symbol to get
+  trades and orders for}
+
+  \item{...}{any other passthrough parameters}
+}
+\value{
+  A \code{xts} object containing:
+
+  \describe{ \item{Order.Qty}{} \item{Order.Price}{}
+  \item{Order.Type}{} \item{Order.Side}{}
+  \item{Order.Threshold}{} \item{Order.Status}should be
+  'closed' only{} \item{Order.StatusTime}{time of the
+  closing trade, should match 'End' column}
+  \item{Prefer}{prefer argument for \code{getPrice}}
+  \item{Order.Set}{order set of the closing trade}
+  \item{Txn.Fees}{and fees applied to the closing trade}
+  \item{Rule}{the name of the rule that generated the order
+  which closed the position} \item{Start}{the
+  \code{POSIXct} timestamp of the start of the trade}
+  \item{Init.Pos}{the initial position on opening the
+  trade} \item{Max.Pos}{the maximum (largest) position held
+  during the open trade} \item{Num.Txns}{ the number of
+  transactions included in this trade}
+  \item{Max.Notional.Cost}{ the largest notional investment
+  cost of this trade} \item{Net.Trading.PL}{ net trading
+  P&L in the currency of \code{Symbol}} \item{MAE}{ Maximum
+  Adverse Excursion (MAE), in the currency of
+  \code{Symbol}} \item{MFE}{ Maximum Favorable Excursion
+  (MFE), in the currency of \code{Symbol}}
+  \item{Pct.Net.Trading.PL}{ net trading P&L in percent of
+  invested \code{Symbol} price gained or lost}
+  \item{Pct.MAE}{ Maximum Adverse Excursion (MAE), in
+  percent} \item{Pct.MFE}{ Maximum Favorable Excursion
+  (MFE), in percent} \item{tick.Net.Trading.PL}{ net
+  trading P&L in ticks} \item{tick.MAE}{ Maximum Adverse
+  Excursion (MAE) in ticks} \item{tick.MFE}{ Maximum
+  Favorable Excursion (MFE) in ticks} }
+}
+\description{
+  get order information associated with closing positions
+}
+



More information about the Blotter-commits mailing list