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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Oct 11 14:11:57 CEST 2010


Author: braverock
Date: 2010-10-11 14:11:57 +0200 (Mon, 11 Oct 2010)
New Revision: 414

Added:
   pkg/blotter/man/PortfReturns.Rd
Modified:
   pkg/blotter/DESCRIPTION
   pkg/blotter/NAMESPACE
   pkg/blotter/R/PortfReturns.R
   pkg/blotter/R/addTxn.R
Log:
- more updates to PortfReturns, documentation, export it

Modified: pkg/blotter/DESCRIPTION
===================================================================
--- pkg/blotter/DESCRIPTION	2010-10-11 08:54:36 UTC (rev 413)
+++ pkg/blotter/DESCRIPTION	2010-10-11 12:11:57 UTC (rev 414)
@@ -1,7 +1,7 @@
 Package: blotter
 Type: Package
 Title: Tools for transaction-oriented trading systems development.
-Version: 0.7
+Version: 0.7.1
 Date: $Date$
 Author: Peter Carl, Brian G. Peterson, Joshua Ulrich
 Maintainer: Brian G. Peterson <brian at braverock.com>
@@ -16,4 +16,4 @@
 Suggests: PerformanceAnalytics, PortfolioAnalytics, Hmisc, RUnit
 Contributors: Wolfgang Wu, Ben McCann
 URL: https://r-forge.r-project.org/projects/blotter/
-Copyright: (c) 2008-2010
\ No newline at end of file
+Copyright: (c) 2008-2010

Modified: pkg/blotter/NAMESPACE
===================================================================
--- pkg/blotter/NAMESPACE	2010-10-11 08:54:36 UTC (rev 413)
+++ pkg/blotter/NAMESPACE	2010-10-11 12:11:57 UTC (rev 414)
@@ -9,6 +9,7 @@
 export(getTxns)
 export(initAcct)
 export(initPortf)
+export(PortfReturns)
 export(updateAcct)
 export(updateEndEq)
 export(updatePortf)

Modified: pkg/blotter/R/PortfReturns.R
===================================================================
--- pkg/blotter/R/PortfReturns.R	2010-10-11 08:54:36 UTC (rev 413)
+++ pkg/blotter/R/PortfReturns.R	2010-10-11 12:11:57 UTC (rev 414)
@@ -1,3 +1,22 @@
+#' Calculate portfolio instrument returns
+#' 
+#' This function (for now) calculates return on initial equity for each instrument
+#' in the portfolio or portfolios that make up an account.  These columns will be additive
+#' to return on capital of each portfolio, or of the entire account.
+#' 
+#' TODO handle portfolio and account in different currencies (not hard, just not done)
+#' 
+#' TODO explicitly handle portfolio weights
+#' 
+#' TODO provide additionalcd  methods of calculating returns
+#' 
+#' This function exists because of R/Finance community requests by Mark Breman and Thomas Bolton 
+#' @param Account string name of the account to generate returns for
+#' @param method for now, only 'contribution' is supported
+#' @param \dots any other passthru parameters (like \code{native} for \code{\link{.getBySymbol}}
+#' @param Dates xts style ISO 8601 date subset to retrieve, default NULL (all dates)
+#' @param Portfolios concatenated string vector for portfolio names to retrieve returns on, default NULL (all portfolios)
+#' @export
 PortfReturns <- function (Account, method=c('contribution'),...,Dates=NULL,Portfolios=NULL) 
 { # @author Brian Peterson
 	aname<-Account
@@ -7,11 +26,13 @@
 		stop(paste("Account ",aname," not found, use initAcct() to create a new account"))
 	if(!inherits(Account,"account")) stop("Account ",aname," passed is not the name of an account object.")
 	
-	Portfolios = names(Account$portfolios)
+	if(is.null(Portfolios)) Portfolios = names(Account$portfolios)
+	
 	table=NULL
 	for(pname in Portfolios){
-		#Portfolio<-
-		ptable = .getBySymbol(Portfolio = pname, Attribute = "Net.Trading.PL", Dates = Dates,...)
+		Portfolio <- getPortfolio(pname)
+		if(is.null(Dates)) Dates <- paste("::",last(index(Portfolio$summary)),sep='')
+		ptable = .getBySymbol(Portfolio = Portfolio, Attribute = "Net.Trading.PL", Dates = Dates,...)
 		
 		#TODO check portfolio and account currencies and convert if necessary
 		
@@ -21,6 +42,7 @@
 		if(is.null(table)) table=ptable
 		else table=cbind(table,ptable)
 	}
+	return(table)
 }
 
 

Modified: pkg/blotter/R/addTxn.R
===================================================================
--- pkg/blotter/R/addTxn.R	2010-10-11 08:54:36 UTC (rev 413)
+++ pkg/blotter/R/addTxn.R	2010-10-11 12:11:57 UTC (rev 414)
@@ -4,8 +4,8 @@
 #' 
 #' @param Portfolio  a portfolio name that points to a portfolio object structured with initPortf()
 #' @param Symbol an instrument identifier for a symbol included in the portfolio,e.g., IBM
-#' @param TxnDate  transaction date as ISO 8106, e.g., '2008-09-01'
-#' @param TxnQty total units (such as shares) transacted.  Positive values indicate a 'buy'; negative values indicate a 'sell'
+#' @param TxnDate  transaction date as ISO 8601, e.g., '2008-09-01' or '2010-01-05 09:54:23.12345'
+#' @param TxnQty total units (such as shares or contracts) transacted.  Positive values indicate a 'buy'; negative values indicate a 'sell'
 #' @param TxnPrice  price at which the transaction was done
 #' @param \dots any other passthrough parameters
 #' @param TxnFees fees associated with the transaction, e.g. commissions., See Details

Added: pkg/blotter/man/PortfReturns.Rd
===================================================================
--- pkg/blotter/man/PortfReturns.Rd	                        (rev 0)
+++ pkg/blotter/man/PortfReturns.Rd	2010-10-11 12:11:57 UTC (rev 414)
@@ -0,0 +1,21 @@
+\name{PortfReturns}
+\alias{PortfReturns}
+\title{Calculate portfolio instrument returns...}
+\usage{PortfReturns(Account, method=c("contribution"), ..., Dates, Portfolios)}
+\description{Calculate portfolio instrument returns}
+\details{This function (for now) calculates return on initial equity for each instrument
+in the portfolio or portfolios that make up an account.  These columns will be additive
+to return on capital of each portfolio, or of the entire account.
+
+TODO handle portfolio and account in different currencies (not hard, just not done)
+
+TODO explicitly handle portfolio weights
+
+TODO provide additionalcd  methods of calculating returns
+
+This function exists because of R/Finance community requests by Mark Breman and Thomas Bolton}
+\arguments{\item{Account}{string name of the account to generate returns for}
+\item{method}{for now, only 'contribution' is supported}
+\item{\dots}{any other passthru parameters (like \code{native} for \code{\link{.getBySymbol}}}
+\item{Dates}{xts style ISO 8601 date subset to retrieve, default NULL (all dates)}
+\item{Portfolios}{concatenated string vector for portfolio names to retrieve returns on, default NULL (all portfolios)}}



More information about the Blotter-commits mailing list