[Blotter-commits] r535 - pkg/blotter/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jan 22 15:50:00 CET 2011


Author: braverock
Date: 2011-01-22 15:50:00 +0100 (Sat, 22 Jan 2011)
New Revision: 535

Modified:
   pkg/blotter/R/getPos.R
Log:
- allow Columns to be specified, default is as the function previously worked, so change is legacy-code-compatible.

Modified: pkg/blotter/R/getPos.R
===================================================================
--- pkg/blotter/R/getPos.R	2011-01-18 14:15:55 UTC (rev 534)
+++ pkg/blotter/R/getPos.R	2011-01-22 14:50:00 UTC (rev 535)
@@ -4,9 +4,11 @@
 #' @param Portfolio string identifying a portfolio object containing transactions
 #' @param Symbol an instrument identifier for a symbol included in the portfolio
 #' @param Date timestamp as of which to have the most recent position
+#' @param Columns which columns to return from the \code{txn} slot in the portfolio
+#' @param n number of periods to return, default 1
 #' @return All data elements related to position in a row of an xts object
 #' @export
-getPos <- function(Portfolio, Symbol, Date)
+getPos <- function(Portfolio, Symbol, Date, Columns=c('Pos.Qty','Pos.Avg.Cost'),n=1)
 { # @author Peter Carl
     Portfolio<-getPortfolio(Portfolio)    
     # FUNCTION
@@ -14,7 +16,8 @@
     toDate = paste('::', Date, sep="")
     # It may not make sense to return realized P&L with the position information, so only position and 
     # position average cost are returned.
-    Pos = last(PosData[toDate,c('Pos.Qty','Pos.Avg.Cost')])
+    if(nrow(PosData)>1) Pos = last(PosData[toDate][,Columns],n=n)
+    else Pos <- PosData[,Columns]
     return(Pos)
 }
 



More information about the Blotter-commits mailing list