[Blotter-commits] r440 - in pkg/blotter: . R demo man tests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 4 19:05:33 CET 2010


Author: braverock
Date: 2010-11-04 19:05:32 +0100 (Thu, 04 Nov 2010)
New Revision: 440

Added:
   pkg/blotter/R/calcPortfAttr.R
   pkg/blotter/man/.calcPortfAttr.Rd
   pkg/blotter/man/.getByPortf.Rd
   pkg/blotter/man/.getBySymbol.Rd
   pkg/blotter/man/.getPortfAcct.Rd
   pkg/blotter/man/.getPosAvgCost.Rd
   pkg/blotter/man/.initPosPL.Rd
   pkg/blotter/man/.initSummary.Rd
   pkg/blotter/man/.initTxn.Rd
   pkg/blotter/man/.onLoad.Rd
   pkg/blotter/man/.updatePosPL.Rd
   pkg/blotter/man/addDiv.Rd
   pkg/blotter/man/addPortfInstr.Rd
   pkg/blotter/man/addTxns.Rd
   pkg/blotter/man/calcPortfSummary.Rd
   pkg/blotter/man/getAccount.Rd
   pkg/blotter/man/getPortfolio.Rd
   pkg/blotter/man/getPos.Rd
   pkg/blotter/man/getPosQty.Rd
   pkg/blotter/man/getTxns.Rd
   pkg/blotter/man/pennyPerShare.Rd
   pkg/blotter/man/updateEndEq.Rd
   pkg/blotter/man/updatePortf.Rd
Removed:
   pkg/blotter/man/calcAcctAttr.Rd
   pkg/blotter/man/calcPortfAttr.Rd
   pkg/blotter/man/calcPosValue.Rd
   pkg/blotter/man/calcRealizedPL.Rd
   pkg/blotter/man/getByPortf.Rd
   pkg/blotter/man/getBySymbol.Rd
   pkg/blotter/man/getTxn.Rd
   pkg/blotter/man/updatePosPL.Rd
Modified:
   pkg/blotter/.project
   pkg/blotter/DESCRIPTION
   pkg/blotter/NAMESPACE
   pkg/blotter/R/PortfReturns.R
   pkg/blotter/R/addPortfInstr.R
   pkg/blotter/R/addTxn.R
   pkg/blotter/R/calcPortfSummary.R
   pkg/blotter/R/calcPortfWgt.R
   pkg/blotter/R/chart.Spread.R
   pkg/blotter/R/extractTests.R
   pkg/blotter/R/getAccount.R
   pkg/blotter/R/getPortfAcct.R
   pkg/blotter/R/getPortfolio.R
   pkg/blotter/R/getPos.R
   pkg/blotter/R/getTxn.R
   pkg/blotter/R/initPortf.R
   pkg/blotter/R/initSummary.R
   pkg/blotter/R/updateAcct.R
   pkg/blotter/demo/longtrend.R
   pkg/blotter/demo/turtles.R
   pkg/blotter/man/PortfReturns.Rd
   pkg/blotter/man/addTxn.Rd
   pkg/blotter/man/calcPortfWgt.Rd
   pkg/blotter/man/calcPosAvgCost.Rd
   pkg/blotter/man/calcTxnAvgCost.Rd
   pkg/blotter/man/calcTxnValue.Rd
   pkg/blotter/man/chart.Posn.Rd
   pkg/blotter/man/chart.Spread.Rd
   pkg/blotter/man/getEndEq.Rd
   pkg/blotter/man/initAcct.Rd
   pkg/blotter/man/initPortf.Rd
   pkg/blotter/man/updateAcct.Rd
   pkg/blotter/tests/runitUpdatePortf.R
Log:
- roxygenize (almost) all docs
- updates to come closer to passing R CMD check



Modified: pkg/blotter/.project
===================================================================
--- pkg/blotter/.project	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/.project	2010-11-04 18:05:32 UTC (rev 440)
@@ -3,9 +3,9 @@
 	<name>blotter</name>
 	<comment></comment>
 	<projects>
-		<project>FinancialInstrument</project>
 		<project>PerformanceAnalytics</project>
-		<project>PortfolioAnalytics</project>
+		<project>quantmod</project>
+		<project>quantstrat</project>
 	</projects>
 	<buildSpec>
 		<buildCommand>

Modified: pkg/blotter/DESCRIPTION
===================================================================
--- pkg/blotter/DESCRIPTION	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/DESCRIPTION	2010-11-04 18:05:32 UTC (rev 440)
@@ -7,13 +7,21 @@
 Maintainer: Brian G. Peterson <brian at braverock.com>
 Description: Transaction infrastructure for defining instruments,
     transactions, portfolios and accounts for trading systems and
-    simulation.  Intends to provide portfolio support for multi-asset
-    class and multi-currency portfolios.  Still in heavy development.
+    simulation.  Provides portfolio support for multi-asset class and
+    multi-currency portfolios.  Still in heavy development.
 License: GPL
 LazyLoad: yes
-Depends: R (>= 2.9.0), xts (>= 0.7-6.1), quantmod (>= 0.3-14),
+Depends: R (>= 2.11.1), xts (>= 0.7-6.1), quantmod (>= 0.3-14),
     FinancialInstrument
 Suggests: PerformanceAnalytics, PortfolioAnalytics, Hmisc, RUnit
 Contributors: Wolfgang Wu, Ben McCann
 URL: https://r-forge.r-project.org/projects/blotter/
 Copyright: (c) 2008-2010
+Collate: 'addPortfInstr.R' 'addTxn.R' 'calcPortfAttr.R'
+    'calcPortfSummary.R' 'calcPortfWgt.R' 'calcPosAvgCost.R'
+    'calcTxnAvgCost.R' 'calcTxnValue.R' 'chart.Posn.R' 'chart.Spread.R'
+    'extractTests.R' 'getAccount.R' 'getByPortf.R' 'getBySymbol.R'
+    'getEndEq.R' 'getPortfAcct.R' 'getPortfolio.R' 'getPosAvgCost.R'
+    'getPosQty.R' 'getPos.R' 'getTxn.R' 'initAcct.R' 'initPortf.R'
+    'initPosPL.R' 'initSummary.R' 'initTxn.R' 'PortfReturns.R'
+    'updateAcct.R' 'updateEndEq.R' 'updatePortf.R' 'updatePosPL.R'

Modified: pkg/blotter/NAMESPACE
===================================================================
--- pkg/blotter/NAMESPACE	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/NAMESPACE	2010-11-04 18:05:32 UTC (rev 440)
@@ -1,11 +1,15 @@
+export(addPortfInstr)
 export(addTxn)
-export(addTxns)
+export(pennyPerShare)
+export(addDiv)
 export(chart.Posn)
+export(chart.Spread)
+export(extractTxns)
 export(getAccount)
 export(getEndEq)
+export(getPortfolio)
 export(getPosQty)
-export(getPortfAcct)
-export(getPortfolio)
+export(getPos)
 export(getTxns)
 export(initAcct)
 export(initPortf)
@@ -13,4 +17,3 @@
 export(updateAcct)
 export(updateEndEq)
 export(updatePortf)
-#export(updatePosPL)
\ No newline at end of file

Modified: pkg/blotter/R/PortfReturns.R
===================================================================
--- pkg/blotter/R/PortfReturns.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/PortfReturns.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -15,7 +15,7 @@
 #' 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 \dots any other passthru parameters (like \code{native} for \code{.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

Modified: pkg/blotter/R/addPortfInstr.R
===================================================================
--- pkg/blotter/R/addPortfInstr.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/addPortfInstr.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -1,7 +1,10 @@
+#' add an instrument to a portfolio
 #' 
-#' @param Portfolio 
-#' @param symbols 
-#' @param ... 
+#' thanks to WolfGang Wu for making this function more usable
+#' 
+#' @param Portfolio portfolio identifier string
+#' @param symbols character vector of symbols to add to the portfolio
+#' @param \dots any other passthru parameters
 #' @export
 addPortfInstr <- function(Portfolio,symbols,...) 
 {

Modified: pkg/blotter/R/addTxn.R
===================================================================
--- pkg/blotter/R/addTxn.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/addTxn.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -37,9 +37,6 @@
 		Portfolio<-get(paste("portfolio",pname,sep='.'),envir=.blotter)
 	}
 
-    # Outputs:
-    # Portfolio: hands back the entire portfolio object with the additional
-    # transaction in the correct slot: Portfolio$symbols[[Symbol]]$txn
 
     # FUNCTION
     # Compute transaction fees if a function was supplied
@@ -82,19 +79,23 @@
     assign(paste("portfolio",pname,sep='.'),Portfolio,envir=.blotter)
 }
 
-## example cost function
+#' example TxnFee cost function
+#' @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
+#' @export
 pennyPerShare <- function(TxnQty, TxnPrice) {
     return(TxnQty * -0.01)
 }
 
+#' add multiple transactions to a portfolio, partially vectorized
 #' 
-#' @param Portfolio 
-#' @param Symbol 
-#' @param TxnData 
-#' @param verbose 
-#' @param ... 
+#' TODO figure out if we can fully vectorize this function to make it faster
+#' @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 TxnData  a n xts object containing all required txn fields
+#' @param \dots any other passthrough parameters
+#' @param verbose TRUE/FALSE
 #' @param ConMult 
-#' @export
 addTxns<- function(Portfolio, Symbol, TxnData , verbose=TRUE, ..., ConMult=NULL)
 {
     pname<-Portfolio
@@ -156,13 +157,20 @@
     assign(paste("portfolio",pname,sep='.'),Portfolio,envir=.blotter)    
 }
 
+#' add cash dividend transactions to a portfolio
 #' 
-#' @param Portfolio 
-#' @param Symbol 
-#' @param TxnDate 
+#' Adding a cash Dividend does not affect position
+#' 
+#' # TODO add TxnTypes to $txn table
+#' 
+#' # TODO add AsOfDate 
+#' 
+#' @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 8601, e.g., '2008-09-01' or '2010-01-05 09:54:23.12345'
 #' @param DivPerShare 
-#' @param ... 
-#' @param TxnFees 
+#' @param \dots any other passthrough parameters
+#' @param TxnFees fees associated with the transaction, e.g. commissions., See Details
 #' @param ConMult 
 #' @param verbose 
 #' @export
@@ -180,12 +188,9 @@
             ConMult<-tmp_instr$multiplier
         }
     }
-    # Outputs:
-    # Portfolio: hands back the entire portfolio object with the additional
-    # transaction in the correct slot: Portfolio$symbols[[Symbol]]$txn
 
     # FUNCTION
-    # Adding a Dividend does not affect position
+    # 
     TxnQty = 0
     TxnPrice = 0
 #     TxnType = "Dividend"

Added: pkg/blotter/R/calcPortfAttr.R
===================================================================
--- pkg/blotter/R/calcPortfAttr.R	                        (rev 0)
+++ pkg/blotter/R/calcPortfAttr.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -0,0 +1,81 @@
+#' calculate summary attributes for a portfolio
+#' 
+#' supported values are:
+#' Gross.Trading.PL, Txn.Fee, Net.Trading.PL, Realized.PL, Unrealized.PL, Gross.Value, Long.Value, Short.Value  
+#' @param Portfolio portfolio object
+#' @param Attribute attribute to calculate
+#' @param Dates date subset
+#' @param Symbols symbols to calculate for
+.calcPortfAttr <- function(Portfolio, Attribute, Dates=NULL, Symbols = NULL)
+{
+    if(!inherits(Portfolio,"portfolio")) stop("Portfolio passed is not a portfolio object.")
+    symbols = names(Portfolio)
+    if(is.null(Dates)|is.na(Dates)) # if no date is specified, get all available dates
+        Dates = time(Portfolio[[1]]$posPL)
+#    else Dates = time(Portfolio[[1]]$posPL[Dates])
+
+    switch(Attribute,
+        Gross.Trading.PL = {
+            table = .getBySymbol(Portfolio = Portfolio, Attribute = 'Gross.Trading.PL', Dates = Dates, Symbols = Symbols)
+#            result = xts(apply(table, FUN='sum', MARGIN=1), Dates)
+            result = xts(rowSums(table), na.rm=TRUE ,order.by=index(table))
+            colnames(result) = 'Gross.Trading.PL'
+        },
+        Txn.Fees = {
+            table = .getBySymbol(Portfolio = Portfolio, Attribute = 'Txn.Fees', Dates = Dates, Symbols = Symbols)
+            result = xts(rowSums(table), na.rm=TRUE ,order.by=index(table))
+            colnames(result) = 'Txn.Fees'
+        },
+        Net.Trading.PL = {
+            table = .getBySymbol(Portfolio = Portfolio, Attribute = 'Net.Trading.PL', Dates = Dates, Symbols = Symbols)
+#            result = xts(apply(table, FUN='sum', MARGIN=1), Dates)
+            result = xts(rowSums(table), na.rm=TRUE ,order.by=index(table))
+            colnames(result) = 'Net.Trading.PL'
+        },
+        Realized.PL = {
+            table = .getBySymbol(Portfolio = Portfolio, Attribute = 'Realized.PL', Dates = Dates, Symbols = Symbols)
+            result = xts(rowSums(table), na.rm=TRUE ,order.by=index(table))
+            colnames(result) = 'Realized.PL'
+        },
+        Unrealized.PL = {
+            table = .getBySymbol(Portfolio = Portfolio, Attribute = 'Unrealized.PL', Dates = Dates, Symbols = Symbols)
+            result = xts(rowSums(table), na.rm=TRUE ,order.by=index(table))
+            colnames(result) = 'Unrealized.PL'
+        },
+        Net.Value = {
+            table = .getBySymbol(Portfolio = Portfolio, Attribute = 'Pos.Value', Dates = Dates, Symbols = Symbols)
+            result = xts(rowSums(table), na.rm=TRUE ,order.by=index(table))
+            colnames(result) = 'Net.Value'
+        },
+        Gross.Value = {
+            table = .getBySymbol(Portfolio = Portfolio, Attribute = 'Pos.Value', Dates = Dates, Symbols = Symbols)
+            result = xts(rowSums(abs(table)), na.rm=TRUE ,order.by=index(table))
+            colnames(result) = 'Gross.Value'
+        },
+        Long.Value = {
+            table = .getBySymbol(Portfolio = Portfolio, Attribute = 'Pos.Value', Dates = Dates, Symbols = Symbols)
+            tmat = apply(table,MARGIN=c(1,2),FUN=max,0)# comes out a matrix
+            result = xts(rowSums(tmat), na.rm=TRUE ,order.by=index(table))
+            colnames(result) = 'Long.Value'
+        },
+        Short.Value = {
+            table = .getBySymbol(Portfolio = Portfolio, Attribute = 'Pos.Value', Dates = Dates, Symbols = Symbols)
+            tmat = apply(table,MARGIN=c(1,2),FUN=min,0) # comes out a matrix
+            result = xts(rowSums(tmat), na.rm=TRUE ,order.by=index(table))
+            colnames(result) = 'Short.Value'
+        }
+    )
+    return(result)
+}
+
+###############################################################################
+# Blotter: Tools for transaction-oriented trading systems development
+# for R (see http://r-project.org/) 
+# Copyright (c) 2008-2010 Peter Carl and Brian G. Peterson
+#
+# This library is distributed under the terms of the GNU Public License (GPL)
+# for full details see the file COPYING
+#
+# $Id: calcPortfAttr.R 307 2010-03-26 23:38:48Z peter_carl $
+#
+###############################################################################

Modified: pkg/blotter/R/calcPortfSummary.R
===================================================================
--- pkg/blotter/R/calcPortfSummary.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/calcPortfSummary.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -12,16 +12,16 @@
         Dates = time(Portfolio$symbols[[1]]$posPL )
 #    else Dates = time(Portfolio$symbols[[1]]$posPL[Dates])
     
-    GrossTradingPL = calcPortfAttr(Portfolio, 'Gross.Trading.PL', Dates)
-    NetTradingPL = calcPortfAttr(Portfolio, 'Net.Trading.PL', Dates)
-    RealizedPL = calcPortfAttr(Portfolio, 'Period.Realized.PL', Dates)
-    UnrealizedPL = calcPortfAttr(Portfolio, 'Period.Unrealized.PL', Dates)
+    GrossTradingPL = .calcPortfAttr(Portfolio, 'Gross.Trading.PL', Dates)
+    NetTradingPL = .calcPortfAttr(Portfolio, 'Net.Trading.PL', Dates)
+    RealizedPL = .calcPortfAttr(Portfolio, 'Period.Realized.PL', Dates)
+    UnrealizedPL = .calcPortfAttr(Portfolio, 'Period.Unrealized.PL', Dates)
     # UnrealizedPL = TradingPL - RealizedPL
-    TxnFees = calcPortfAttr(Portfolio, 'Txn.Fees', Dates)
-    NetValue = calcPortfAttr(Portfolio, 'Net.Value', Dates)
-    GrossValue = calcPortfAttr(Portfolio, 'Gross.Value', Dates)
-    LongValue = calcPortfAttr(Portfolio, 'Long.Value', Dates)
-    ShortValue = calcPortfAttr(Portfolio, 'Short.Value', Dates)
+    TxnFees = .calcPortfAttr(Portfolio, 'Txn.Fees', Dates)
+    NetValue = .calcPortfAttr(Portfolio, 'Net.Value', Dates)
+    GrossValue = .calcPortfAttr(Portfolio, 'Gross.Value', Dates)
+    LongValue = .calcPortfAttr(Portfolio, 'Long.Value', Dates)
+    ShortValue = .calcPortfAttr(Portfolio, 'Short.Value', Dates)
 
     summary=merge(LongValue, ShortValue, NetValue, GrossValue, RealizedPL, UnrealizedPL, GrossTradingPL, TxnFees, NetTradingPL)
 #     colnames(summary)=c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value', 'Realized.PL', 'Unrealized.PL', 'Gross.Trading.PL','Txn.Fees','Net.Trading.PL')

Modified: pkg/blotter/R/calcPortfWgt.R
===================================================================
--- pkg/blotter/R/calcPortfWgt.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/calcPortfWgt.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -14,7 +14,7 @@
     # FUNCTION
 
     pos.value = .getBySymbol(Portfolio = Portfolio, Dates = Dates, Attribute = "Pos.Value", Symbols = Symbols)
-    portf.value = calcPortfAttr(Portfolio = Portfolio, Date = Dates, Attribute = denominator[1])
+    portf.value = .calcPortfAttr(Portfolio = Portfolio, Date = Dates, Attribute = denominator[1])
     weights = apply(pos.value, MARGIN = 2, FUN = function(x,y){return(x/y)}, y=portf.value) 
 
     return(weights)

Modified: pkg/blotter/R/chart.Spread.R
===================================================================
--- pkg/blotter/R/chart.Spread.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/chart.Spread.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -1,10 +1,10 @@
 #' Charts the transaction series, positions, and P&L of a spread against prices
-#' @param Account 
+#' @param Account string identifying the account
 #' @param Portfolio string identifying the portfolio to chart
-#' @param Symbols string identifying the symbols to chart for positions
+#' @param Symbols string identifying the underlying symbols to chart for positions
+#' @param Spread identifier of a spread instrument
 #' @param Dates date range, currently not used
-#' @param ... any other passthru parameters (typically parameters to \code{chart_Series})
-#' @author brian
+#' @param \dots any other passthru parameters (typically parameters to \code{chart_Series})
 #' @export
 chart.Spread <- function(Account, Portfolio, Spread=NULL, Symbols = NULL, Dates = NULL, ...)
 { # @author Peter Carl
@@ -12,7 +12,7 @@
     pname<-Portfolio
     Portfolio<-getPortfolio(pname,Dates)
 
-    pacctdata<-getPortfAcct(Account,Portfolio=pname, Dates=NULL)
+    pacctdata<-.getPortfAcct(Account,Portfolio=pname, Dates=NULL)
     
     tmp_instr<-getInstrument(Spread)
     if(!inherits(tmp_instr,"spread")) stop (paste("Instrument",Spread," is not a spread, please use the primary_id of a spread."))

Modified: pkg/blotter/R/extractTests.R
===================================================================
--- pkg/blotter/R/extractTests.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/extractTests.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -17,7 +17,7 @@
 	pname <- Portfolio	
 	Portfolio<-get(paste("portfolio",pname,sep='.'),envir=.blotter)
 	if(inherits(Portfolio,"try-error"))
-		stop(paste("Portfolio",name," not found, use initPortf() to create a new portfolio first"))
+		stop(paste("Portfolio",pname," not found, use initPortf() to create a new portfolio first"))
 	out<-NULL
 	symbolnames<-names(Portfolio[['symbols']])
 	for (Symbol in symbolnames) {

Modified: pkg/blotter/R/getAccount.R
===================================================================
--- pkg/blotter/R/getAccount.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/getAccount.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -2,6 +2,7 @@
 #' @param Account string identifier for the account
 #' @param Dates 
 #' @return Account object
+#' @export
 getAccount <- function(Account, Dates=NULL) #should symbol subsets be supported too?  probably not.
 { # @author Brian Peterson
     aname<-Account

Modified: pkg/blotter/R/getPortfAcct.R
===================================================================
--- pkg/blotter/R/getPortfAcct.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/getPortfAcct.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -1,8 +1,8 @@
-#' 
-#' @param Account 
-#' @param Portfolio 
-#' @param Dates 
-getPortfAcct <- function(Account,Portfolio, Dates=NULL) #should symbol subsets be supported too?  probably not.
+#' get a protfolio in an account
+#' @param Account account string
+#' @param Portfolio portfolio string
+#' @param Dates date subset as an xts style ISO 8601 string
+.getPortfAcct <- function(Account,Portfolio, Dates=NULL) #should symbol subsets be supported too?  probably not.
 { # @author Brian Peterson
     acct<-try(get(paste("account",Account,sep='.'),envir=.blotter),silent=TRUE)
     if(inherits(acct,"try-error"))

Modified: pkg/blotter/R/getPortfolio.R
===================================================================
--- pkg/blotter/R/getPortfolio.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/getPortfolio.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -1,7 +1,6 @@
-#' 
-#' @param Portfolio 
-#' @param Dates 
-#' @returnType 
+#' get a portfolio object
+#' @param Portfolio string identifying portfolio
+#' @param Dates dates subset, not yet supported
 #' @export
 getPortfolio <- function(Portfolio, Dates=NULL) #should symbol subsets be supported too?  probably not.
 { # @author Brian Peterson

Modified: pkg/blotter/R/getPos.R
===================================================================
--- pkg/blotter/R/getPos.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/getPos.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -1,10 +1,9 @@
 #' Retrieves all information about the position as of a date
 #' 
-#' NOTE This should get much more complicated from here, particularly when it's conditional on symbol, etc.
+#' NOTE This could get much more complicated from here, particularly when it's conditional on symbol, etc.
 #' @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
-#' @returnType 
 #' @return All data elements related to position in a row of an xts object
 #' @export
 getPos <- function(Portfolio, Symbol, Date)

Modified: pkg/blotter/R/getTxn.R
===================================================================
--- pkg/blotter/R/getTxn.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/getTxn.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -9,7 +9,7 @@
     pname<-Portfolio
     Portfolio<-get(paste("portfolio",pname,sep='.'),envir=.blotter)
     if(inherits(Portfolio,"try-error"))
-        stop(paste("Portfolio",name," not found, use initPortf() to create a new portfolio first"))
+        stop(paste("Portfolio",pname," not found, use initPortf() to create a new portfolio first"))
     
     TxnData = Portfolio$symbols[[Symbol]]$txn
     Txns = TxnData[Date,c('Txn.Qty', 'Txn.Price', 'Txn.Fees', 'Txn.Value', 'Txn.Avg.Cost', 'Net.Txn.Realized.PL')]

Modified: pkg/blotter/R/initPortf.R
===================================================================
--- pkg/blotter/R/initPortf.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/initPortf.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -1,11 +1,11 @@
 #' Initializes a portfolio object, 
 #' 
 #' Initializes a portfolio object, which is constructed from is constructed of the following:
-#' symbols: the identifier used for each instrument contained in the portfolio.
-#'   Use names(Portfolio$symbols) to get a list of symbols.
+#' $symbols: the identifier used for each instrument contained in the portfolio. Use names(Portfolio$symbols) to get a list of symbols.
 #' $[symbol]$txn: irregular xts object of transactions data 
-#' $[symbol]$posPL: regular xts object of positions P&L calculated from 
-#'   transactions
+#' $[symbol]$posPL: regular xts object of positions P&L calculated from transactions
+#' $[symbol]$posPL.ccy: regular xts object of positions P&L converted to portfolio currency
+#' $summary: summary slot
 #' 
 #' TODO: add $account: name of the (one) affiliated account
 #
@@ -16,6 +16,7 @@
 #' @param symbols  instrument identifiers of those instruments contained in the portfolio 
 #' @param initPosQty initial position, default is zero
 #' @param initDate date prior to the first close price given, used to contain initial account equity and initial position
+#' @param currency ISO currency idenifier used to locate the portfolio currency
 #' @author Peter Carl
 #' @export
 initPortf <- function(name="default", symbols, initPosQty = 0, initDate = '1950-01-01', currency='USD')

Modified: pkg/blotter/R/initSummary.R
===================================================================
--- pkg/blotter/R/initSummary.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/initSummary.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -1,9 +1,5 @@
 #' initialize the summary table used in portfolio and account lists
-#' @param initDate 
-#' @returnType 
-#' @return 
-#' @author brian
-#' @export
+#' @param initDate date prior to the first close price given, used to contain initial account equity and initial position
 .initSummary <- function(initDate="1950-01-01")
 { # @author Brian Peterson
     summary <- xts( as.matrix(t(rep(0,9))), order.by=as.POSIXct(initDate) )

Modified: pkg/blotter/R/updateAcct.R
===================================================================
--- pkg/blotter/R/updateAcct.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/R/updateAcct.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -42,10 +42,10 @@
 				warning("Currency",p.ccy.str," not found, using currency multiplier of 1")
 				CcyMult<-1
 			} else {
-				FXrate.str<-paste(tmp_instr$currency,p.ccy.str,sep='')
+				FXrate.str<-paste(a.ccy.str,p.ccy.str,sep='')
 				FXrate<-try(get(FXrate.str))
 				if(inherits(FXrate,"try-error")){
-					FXrate.str<-paste(p.ccy.str,tmp_instr$currency,sep='')
+					FXrate.str<-paste(p.ccy.str,a.ccy.str,sep='')
 					FXrate<-try(get(FXrate.str))
 					if(inherits(FXrate,"try-error")){ 
 						warning("Exchange Rate",FXrate.str," not found for symbol,',Symbol,' using currency multiplier of 1")

Modified: pkg/blotter/demo/longtrend.R
===================================================================
--- pkg/blotter/demo/longtrend.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/demo/longtrend.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -115,7 +115,8 @@
 chart.Posn(ltportfolio, Symbol = 'GSPC', Dates = '1998::')
 plot(add_SMA(n=10,col='darkgreen', on=1))
 
-getTxns(Portfolio="longtrend", Symbol="GSPC", Date="2000::2004")
+#look at a transaction summary
+getTxns(Portfolio="longtrend", Symbol="GSPC")
 
 # Copy the results into the local environment
 print("Retrieving resulting portfolio and account")

Modified: pkg/blotter/demo/turtles.R
===================================================================
--- pkg/blotter/demo/turtles.R	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/demo/turtles.R	2010-11-04 18:05:32 UTC (rev 440)
@@ -182,7 +182,9 @@
 }
 
 if(require(PerformanceAnalytics)){
-    return = Delt(getAccount(account)[["TOTAL"]]$End.Eq)
+    return = Delt(getAccount(account)$summary$End.Eq)
 	dev.new()
     charts.PerformanceSummary(as.zoo(return),main="Turtle Demo Performance")   
+	dev.new()
+	charts.PerformanceSummary(PortfReturns('turtles'),main='Turtle Demo Instrument Return on Equity')
 }

Added: pkg/blotter/man/.calcPortfAttr.Rd
===================================================================
--- pkg/blotter/man/.calcPortfAttr.Rd	                        (rev 0)
+++ pkg/blotter/man/.calcPortfAttr.Rd	2010-11-04 18:05:32 UTC (rev 440)
@@ -0,0 +1,11 @@
+\name{.calcPortfAttr}
+\alias{.calcPortfAttr}
+\title{calculate summary attributes for a portfolio...}
+\usage{.calcPortfAttr(Portfolio, Attribute, Dates, Symbols)}
+\description{calculate summary attributes for a portfolio}
+\details{supported values are:
+Gross.Trading.PL, Txn.Fee, Net.Trading.PL, Realized.PL, Unrealized.PL, Gross.Value, Long.Value, Short.Value}
+\arguments{\item{Portfolio}{portfolio object}
+\item{Attribute}{attribute to calculate}
+\item{Dates}{date subset}
+\item{Symbols}{symbols to calculate for}}

Added: pkg/blotter/man/.getByPortf.Rd
===================================================================
--- pkg/blotter/man/.getByPortf.Rd	                        (rev 0)
+++ pkg/blotter/man/.getByPortf.Rd	2010-11-04 18:05:32 UTC (rev 440)
@@ -0,0 +1,17 @@
+\name{.getByPortf}
+\alias{.getByPortf}
+\title{get attributes from each portfolio in an account...}
+\usage{.getByPortf(Account, Attribute, Dates)}
+\description{get attributes from each portfolio in an account}
+\details{Retrieves calculated attributes for each portfolio in the account
+from the portfolio summary table.  Assembles into a portfolio-by-time table,
+normalized to the Account currency 
+
+
+Attribute: typically any of:
+'Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value', 'Txn.Fees',
+'Realized.PL', 'Unrealized.PL', or 'Trading.PL'}
+\value{regular xts object of values by portfolio}
+\arguments{\item{Account}{an Account object containing Portfolio summaries}
+\item{Attribute}{column name to be assembled for each symbol}
+\item{Dates}{}}

Added: pkg/blotter/man/.getBySymbol.Rd
===================================================================
--- pkg/blotter/man/.getBySymbol.Rd	                        (rev 0)
+++ pkg/blotter/man/.getBySymbol.Rd	2010-11-04 18:05:32 UTC (rev 440)
@@ -0,0 +1,17 @@
+\name{.getBySymbol}
+\alias{.getBySymbol}
+\title{Retrieves calculated attributes for each position in the portfolio...}
+\usage{.getBySymbol(Portfolio, Attribute, Dates, Symbols, native=FALSE)}
+\description{Retrieves calculated attributes for each position in the portfolio}
+\details{Retrieves calculated attributes for each position in the portfolio
+from the posPL table.  Assembles into a symbol-by-time table useful
+for graphing or calculations
+
+items typically include things like
+'Pos.Qty', 'Pos.Value', 'Txn.Value', 'Realized.PL', 'Unrealized.PL',or 'Trading.PL'}
+\value{regular xts object of values by symbol}
+\arguments{\item{Portfolio}{a portfolio object containing transactions}
+\item{Attribute}{column name to be assembled for each symbol}
+\item{Dates}{}
+\item{Symbols}{}
+\item{native}{}}

Added: pkg/blotter/man/.getPortfAcct.Rd
===================================================================
--- pkg/blotter/man/.getPortfAcct.Rd	                        (rev 0)
+++ pkg/blotter/man/.getPortfAcct.Rd	2010-11-04 18:05:32 UTC (rev 440)
@@ -0,0 +1,8 @@
+\name{.getPortfAcct}
+\alias{.getPortfAcct}
+\title{get a protfolio in an account...}
+\usage{.getPortfAcct(Account, Portfolio, Dates)}
+\description{get a protfolio in an account}
+\arguments{\item{Account}{account string}
+\item{Portfolio}{portfolio string}
+\item{Dates}{date subset as an xts style ISO 8601 string}}

Added: pkg/blotter/man/.getPosAvgCost.Rd
===================================================================
--- pkg/blotter/man/.getPosAvgCost.Rd	                        (rev 0)
+++ pkg/blotter/man/.getPosAvgCost.Rd	2010-11-04 18:05:32 UTC (rev 440)
@@ -0,0 +1,9 @@
+\name{.getPosAvgCost}
+\alias{.getPosAvgCost}
+\title{Retrieves the most recent average cost of the position...}
+\usage{.getPosAvgCost(Portfolio, Symbol, Date)}
+\description{Retrieves the most recent average cost of the position}
+\value{Numeric value of the average cost of the current position}
+\arguments{\item{Portfolio}{a portfolio object containing transactions}
+\item{Symbol}{an instrument identifier for a symbol included in the portfolio}
+\item{Date}{timestamp as of which to have the most recent position}}

Added: pkg/blotter/man/.initPosPL.Rd
===================================================================
--- pkg/blotter/man/.initPosPL.Rd	                        (rev 0)
+++ pkg/blotter/man/.initPosPL.Rd	2010-11-04 18:05:32 UTC (rev 440)
@@ -0,0 +1,15 @@
+\name{.initPosPL}
+\alias{.initPosPL}
+\title{initializes position P&L for a portfolio instrument...}
+\usage{.initPosPL(initDate="1950-01-01", ..., initPosQty=0, initConMult=1,
+    initCcyMult=1)}
+\description{initializes position P&L for a portfolio instrument}
+\details{Constructs the data container used to store calculated P&L values from
+transactions and close prices.
+
+Constructs multi-column xts object used to store derived position information}
+\arguments{\item{initDate}{date prior to the first close price given, used to contain initial account equity and initial position}
+\item{\dots}{any other passthrough parameters}
+\item{initPosQty}{initial position, default is zero}
+\item{initConMult}{initial contract multiplier, default is one(1)}
+\item{initCcyMult}{initial currency multiplier, default is one(1)}}

Added: pkg/blotter/man/.initSummary.Rd
===================================================================
--- pkg/blotter/man/.initSummary.Rd	                        (rev 0)
+++ pkg/blotter/man/.initSummary.Rd	2010-11-04 18:05:32 UTC (rev 440)
@@ -0,0 +1,6 @@
+\name{.initSummary}
+\alias{.initSummary}
+\title{initialize the summary table used in portfolio and account lists...}
+\usage{.initSummary(initDate="1950-01-01")}
+\description{initialize the summary table used in portfolio and account lists}
+\arguments{\item{initDate}{date prior to the first close price given, used to contain initial account equity and initial position}}

Added: pkg/blotter/man/.initTxn.Rd
===================================================================
--- pkg/blotter/man/.initTxn.Rd	                        (rev 0)
+++ pkg/blotter/man/.initTxn.Rd	2010-11-04 18:05:32 UTC (rev 440)
@@ -0,0 +1,9 @@
+\name{.initTxn}
+\alias{.initTxn}
+\title{Constructs the data container used to store transactions and resulting positions.}
+\usage{.initTxn(initDate="1950-01-01", initPosQty=0)}
+\description{Constructs the data container used to store transactions and resulting positions.}
+\details{The data series stored here will be an irregular time series.}
+\value{Constructs multi-column xts object used to store transactions}
+\arguments{\item{initDate}{date prior to the first close price given, used to contain initial account equity and initial position}
+\item{initPosQty}{initial position, default is zero}}

Added: pkg/blotter/man/.onLoad.Rd
===================================================================
--- pkg/blotter/man/.onLoad.Rd	                        (rev 0)
+++ pkg/blotter/man/.onLoad.Rd	2010-11-04 18:05:32 UTC (rev 440)
@@ -0,0 +1,4 @@
+\name{.onLoad}
+\alias{.onLoad}
+\title{.onLoad}
+\usage{.onLoad(lib, pkg)}

Added: pkg/blotter/man/.updatePosPL.Rd
===================================================================
--- pkg/blotter/man/.updatePosPL.Rd	                        (rev 0)
+++ pkg/blotter/man/.updatePosPL.Rd	2010-11-04 18:05:32 UTC (rev 440)
@@ -0,0 +1,12 @@
+\name{.updatePosPL}
+\alias{.updatePosPL}
+\title{Calculates position PL from the position data and corresponding close price data.}
+\usage{.updatePosPL(Portfolio, Symbol, Dates, Prices, ConMult, ...)}
+\description{Calculates position PL from the position data and corresponding close price data.}
+\value{Regular time series of position information and PL}
+\author{Peter Carl, Brian Peterson}
+\arguments{\item{Portfolio}{a portfolio name to a portfolio structured with initPortf()}
+\item{Symbol}{an instrument identifier for a symbol included in the portfolio}
+\item{Dates}{xts subset of dates, e.g., "2007-01::2008-04-15". These dates must appear in the price stream}
+\item{Prices}{periodic prices in an xts object with a columnname compatible with \code{getPrice}}
+\item{ConMult}{if necessary, numeric contract multiplier, not needed if instrument is defined.}}

Modified: pkg/blotter/man/PortfReturns.Rd
===================================================================
--- pkg/blotter/man/PortfReturns.Rd	2010-11-04 16:16:54 UTC (rev 439)
+++ pkg/blotter/man/PortfReturns.Rd	2010-11-04 18:05:32 UTC (rev 440)
@@ -11,11 +11,13 @@
 
 TODO explicitly handle portfolio weights
 
-TODO provide additionalcd  methods of calculating returns
+TODO provide additional  methods of calculating returns
 
+TODO support additions and withdrawals to available capital 
+
 This function exists because of R/Finance community requests by Mark Breman and Thomas Bolton}
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/blotter -r 440


More information about the Blotter-commits mailing list