[Blotter-commits] r1181 - in pkg/blotter: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Sep 15 00:37:01 CEST 2012


Author: opentrades
Date: 2012-09-15 00:37:01 +0200 (Sat, 15 Sep 2012)
New Revision: 1181

Modified:
   pkg/blotter/R/chart.ME.R
   pkg/blotter/man/chart.ME.Rd
   pkg/blotter/man/perTradeStats.Rd
Log:
- added includeOpenTrades parameter to perTradeStats()



Modified: pkg/blotter/R/chart.ME.R
===================================================================
--- pkg/blotter/R/chart.ME.R	2012-09-14 13:38:25 UTC (rev 1180)
+++ pkg/blotter/R/chart.ME.R	2012-09-14 22:37:01 UTC (rev 1181)
@@ -8,14 +8,14 @@
 #' @param Symbol string identifying the symbol to chart. If missing, the first symbol found in the \code{Portfolio} portfolio will be used
 #' @param type string specifying MAE (Adverse) or MFE (Favourable) chart type
 #' @param scale string specifying 'cash', or 'percent' for percentage of investment, or 'tick'
-#' @param \dots any other passthrough parameters
+#' @param \dots any other passthrough parameters, in particular includeOpenTrades (see perTradeStats())
 #' @author Jan Humme
 #' @references Tomasini, E. and Jaekle, U. \emph{Trading Systems - A new approach to system development and portfolio optimisation} (ISBN 978-1-905641-79-6), section 3.5
 #' @export
-chart.ME <- function(Portfolio, Symbol, type=c('MAE', 'MFE'), scale=c('cash', 'percent', 'tick'), ...)
+chart.ME <- function(Portfolio, Symbol, type=c('MAE','MFE'), scale=c('cash','percent','tick'), ...)
 {   # @author Jan Humme
 
-    trades <- perTradeStats(Portfolio,Symbol)
+    trades <- perTradeStats(Portfolio, Symbol, ...)
     
     #multiply Pcct numbers for prettier charting
     trades$Pct.Net.Trading.PL <- 100 * trades$Pct.Net.Trading.PL
@@ -106,11 +106,12 @@
 #'  
 #' @param Portfolio string identifying the portfolio to chart
 #' @param Symbol string identifying the symbol to chart. If missing, the first symbol found in the \code{Portfolio} portfolio will be used
+#' @param includeOpenTrades: whether to process only finished trades, or the last trade if it is still open
 #' @param \dots any other passthrough parameters
 #' @author Brian G. Peterson, Jan Humme
 #' @references Tomasini, E. and Jaekle, U. \emph{Trading Systems - A new approach to system development and portfolio optimisation} (ISBN 978-1-905641-79-6)
 #' @export
-perTradeStats <- function(Portfolio, Symbol,...) {
+perTradeStats <- function(Portfolio, Symbol, includeOpenTrades=FALSE, ...) {
     portf <- getPortfolio(Portfolio)
     
     if(missing(Symbol)) Symbol <- names(portf$symbols)[[1]]
@@ -126,9 +127,19 @@
     trades$Start <- index(posPL[which(posPL$Pos.Value!=0 & lag(posPL$Pos.Value)==0),])
     trades$End <- index(posPL[which(posPL$Pos.Value==0 & lag(posPL$Pos.Value)!=0),])
     
-    # if trade is still open at end of series, set end of open trade to the end of the series instead
-    if(length(trades$Start)>length(trades$End)){
-        trades$End <- c(trades$End,last(index(posPL)))
+    # if the last trade is still open, adjust depending on whether wants open trades or not
+    if(length(trades$Start)>length(trades$End))
+    {
+        if(includeOpenTrades)
+{
+print('========== including open trade')
+            trades$End <- c(trades$End,last(index(posPL)))
+}
+        else
+{
+print('========== excluding open trade')
+            trades$Start <- head(trades$Start, -1)
+}
     }
     
     # calculate information about each trade
@@ -179,6 +190,7 @@
         trades$tick.MAE[i] <- min(0,trade$tick.PL)
         trades$tick.MFE[i] <- max(0,trade$tick.PL)
     }
+#print(trades)
 
     return(as.data.frame(trades))
 }

Modified: pkg/blotter/man/chart.ME.Rd
===================================================================
--- pkg/blotter/man/chart.ME.Rd	2012-09-14 13:38:25 UTC (rev 1180)
+++ pkg/blotter/man/chart.ME.Rd	2012-09-14 22:37:01 UTC (rev 1181)
@@ -3,7 +3,7 @@
 \title{Chart Maximum Adverse/Forward Excursion}
 \usage{
   chart.ME(Portfolio, Symbol, type = c("MAE", "MFE"),
-    scale = c("cash", "percent"), ...)
+    scale = c("cash", "percent", "tick"), ...)
 }
 \arguments{
   \item{Portfolio}{string identifying the portfolio to
@@ -17,9 +17,10 @@
   (Favourable) chart type}
 
   \item{scale}{string specifying 'cash', or 'percent' for
-  percentage of investment}
+  percentage of investment, or 'tick'}
 
-  \item{\dots}{any other passthrough parameters}
+  \item{\dots}{any other passthrough parameters, in
+  particular includeOpenTrades (see perTradeStats())}
 }
 \description{
   Produces a scatterplot with one point per trade, with

Modified: pkg/blotter/man/perTradeStats.Rd
===================================================================
--- pkg/blotter/man/perTradeStats.Rd	2012-09-14 13:38:25 UTC (rev 1180)
+++ pkg/blotter/man/perTradeStats.Rd	2012-09-14 22:37:01 UTC (rev 1181)
@@ -2,7 +2,8 @@
 \alias{perTradeStats}
 \title{calculate flat to flat per-trade statistics}
 \usage{
-  perTradeStats(Portfolio, Symbol, ...)
+  perTradeStats(Portfolio, Symbol,
+    includeOpenTrades = FALSE, ...)
 }
 \arguments{
   \item{Portfolio}{string identifying the portfolio to
@@ -12,6 +13,9 @@
   missing, the first symbol found in the \code{Portfolio}
   portfolio will be used}
 
+  \item{includeOpenTrades:}{whether to process only
+  finished trades, or the last trade if it is still open}
+
   \item{\dots}{any other passthrough parameters}
 }
 \description{



More information about the Blotter-commits mailing list