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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Nov 4 17:14:21 CET 2010


Author: braverock
Date: 2010-11-04 17:14:20 +0100 (Thu, 04 Nov 2010)
New Revision: 438

Removed:
   pkg/blotter/R/calcUnrealizedPL.R
   pkg/blotter/R/getRealizedPL.R
   pkg/blotter/R/getTxnFees.R
   pkg/blotter/R/getTxnValue.R
Modified:
   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/calcPosAvgCost.R
   pkg/blotter/R/calcTxnAvgCost.R
   pkg/blotter/R/calcTxnValue.R
   pkg/blotter/R/chart.Posn.R
   pkg/blotter/R/chart.Spread.R
   pkg/blotter/R/getAccount.R
   pkg/blotter/R/getByPortf.R
   pkg/blotter/R/getBySymbol.R
   pkg/blotter/R/getEndEq.R
   pkg/blotter/R/getPortfAcct.R
   pkg/blotter/R/getPortfolio.R
   pkg/blotter/R/getPos.R
   pkg/blotter/R/getPosAvgCost.R
   pkg/blotter/R/getPosQty.R
   pkg/blotter/R/getTxn.R
   pkg/blotter/R/initAcct.R
   pkg/blotter/R/initPortf.R
   pkg/blotter/R/initPosPL.R
   pkg/blotter/R/initSummary.R
   pkg/blotter/R/initTxn.R
   pkg/blotter/R/updateAcct.R
   pkg/blotter/R/updateEndEq.R
   pkg/blotter/R/updatePortf.R
   pkg/blotter/R/updatePosPL.R
Log:
- stub/update roxygen comments for all functions
- update @export tags
- remove obsolete functions
- convert private fns to .fns where appropriate

Modified: pkg/blotter/R/PortfReturns.R
===================================================================
--- pkg/blotter/R/PortfReturns.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/PortfReturns.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -8,8 +8,10 @@
 #' 
 #' 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 
 #' @param Account string name of the account to generate returns for
 #' @param method for now, only 'contribution' is supported
@@ -36,8 +38,12 @@
 		
 		#TODO check portfolio and account currencies and convert if necessary
 		
+		#TODO handle additions and withdrawals in equity
+		
 		if(!is.null(attr(Account,'initEq'))){
-			ptable = ptable/as.numeric(attr(Account,'initEq'))
+			initEq<-as.numeric(attr(Account,'initEq'))
+			if(initEq==0) stop("Initial equity of zero would produce div by zero NaN,Inf,-Inf returns, please fix in initAcct().")
+			ptable = ptable/initEq
 		}
 		if(is.null(table)) table=ptable
 		else table=cbind(table,ptable)

Modified: pkg/blotter/R/addPortfInstr.R
===================================================================
--- pkg/blotter/R/addPortfInstr.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/addPortfInstr.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,3 +1,8 @@
+#' 
+#' @param Portfolio 
+#' @param symbols 
+#' @param ... 
+#' @export
 addPortfInstr <- function(Portfolio,symbols,...) 
 {
     pname<-Portfolio
@@ -7,8 +12,8 @@
 	initDate <- attr(portfolio, "initDate")    
 	currency <- attr(portfolio, "currency")
     for(instrument in symbols){
-        portfolio$symbols[[instrument]]$txn = initTxn(initDate = initDate, initPosQty = 0)
-        portfolio$symbols[[instrument]]$posPL = initPosPL(initDate = initDate, initPosQty = 0)
+        portfolio$symbols[[instrument]]$txn = .initTxn(initDate = initDate, initPosQty = 0)
+        portfolio$symbols[[instrument]]$posPL = .initPosPL(initDate = initDate, initPosQty = 0)
 		portfolio$symbols[[instrument]][[paste('posPL',currency,sep='.')]] = portfolio$symbols[[instrument]]$posPL		
     }
 

Modified: pkg/blotter/R/addTxn.R
===================================================================
--- pkg/blotter/R/addTxn.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/addTxn.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -55,7 +55,7 @@
     PosQty = PrevPosQty + TxnQty
 
     # Calculate the resulting position's average cost
-    PrevPosAvgCost = getPosAvgCost(pname, Symbol, TxnDate)
+    PrevPosAvgCost = .getPosAvgCost(pname, Symbol, TxnDate)
     PosAvgCost = calcPosAvgCost(PrevPosQty, PrevPosAvgCost, TxnValue, PosQty, ConMult)
 
 	
@@ -87,6 +87,13 @@
     return(TxnQty * -0.01)
 }
 
+#' 
+#' @param Portfolio 
+#' @param Symbol 
+#' @param TxnData 
+#' @param verbose 
+#' @param ... 
+#' @param ConMult 
 #' @export
 addTxns<- function(Portfolio, Symbol, TxnData , verbose=TRUE, ..., ConMult=NULL)
 {
@@ -106,7 +113,7 @@
     for (row in 1:nrow(TxnData)) {
         if(row==1) {
             PrevPosQty     <- getPosQty(pname, Symbol, index(TxnData[row,]))
-            PrevPosAvgCost <- getPosAvgCost(pname, Symbol, index(TxnData[row,]))
+            PrevPosAvgCost <- .getPosAvgCost(pname, Symbol, index(TxnData[row,]))
         }
         #TODO create vectorized versions of all these functions so we don't have to loop
         TxnQty         <- as.numeric(TxnData[row,'Quantity'])
@@ -149,6 +156,16 @@
     assign(paste("portfolio",pname,sep='.'),Portfolio,envir=.blotter)    
 }
 
+#' 
+#' @param Portfolio 
+#' @param Symbol 
+#' @param TxnDate 
+#' @param DivPerShare 
+#' @param ... 
+#' @param TxnFees 
+#' @param ConMult 
+#' @param verbose 
+#' @export
 addDiv <- function(Portfolio, Symbol, TxnDate, DivPerShare, ..., TxnFees=0, ConMult=NULL, verbose=TRUE)
 { # @author Peter Carl
     pname<-Portfolio
@@ -184,7 +201,7 @@
     TxnAvgCost = DivPerShare
 
     # No change to the the resulting position's average cost
-    PrevPosAvgCost = getPosAvgCost(pname, Symbol, TxnDate)
+    PrevPosAvgCost = .getPosAvgCost(pname, Symbol, TxnDate)
     PosAvgCost = PrevPosAvgCost # but carry it forward in $txn
 
     # Calculate any realized profit or loss (net of fees) from the transaction

Modified: pkg/blotter/R/calcPortfSummary.R
===================================================================
--- pkg/blotter/R/calcPortfSummary.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/calcPortfSummary.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,3 +1,6 @@
+#' Create portfolio summary
+#' @param Portfolio 
+#' @param Dates 
 calcPortfSummary <- function(Portfolio, Dates=NULL)
 { # @ author Peter Carl
     if(!inherits(Portfolio,"portfolio")) stop("Portfolio passed is not a portfolio object.")
@@ -2,3 +5,3 @@
     # DESCRIPTION
-    # Create portfolio summary with the following columns
+    # 
     # Long.Value, Short.Value, Net.Value, Trading.PL

Modified: pkg/blotter/R/calcPortfWgt.R
===================================================================
--- pkg/blotter/R/calcPortfWgt.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/calcPortfWgt.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,19 +1,16 @@
+#' Calculates the portfolio weights for positions within a given portfolio.
+#' 
+#' Portfolio weights may be calculated differently depending on their use.
+#' 
+#' @return xts timeseries object with weights by date in rows and symbolname in columns
+#' @param Portfolio a portfolio object structured with initPortf()
+#' @param Symbols an instrument identifier for a symbol included in the portfolio
+#' @param Dates dates to return the calculation over formatted as xts range
+#' @param denominator 
+#' @param Account 
 calcPortfWgt <- function(Portfolio, Symbols = NULL, Dates = NULL, denominator = c('Gross.Value', 'Net.Value', 'Long.Value', 'Short.Value'), Account = NULL)
 { # @author Peter Carl
 
-    # DESCRIPTION
-    # Calculates the portfolio weights for positions within a given portfolio.
-    # Portfolio weights may be calculated differently depending on their use.
-
-    # Inputs
-    # Portfolio: a portfolio object structured with initPortf()
-    # Symbol: an instrument identifier for a symbol included in the portfolio,
-    #   e.g., IBM
-    # Dates: dates to return the calculation over formatted as xts range
-
-    # Outputs
-    # Timeseries object with weights by date in rows and symbolname in columns
-
     # FUNCTION
 
     pos.value = .getBySymbol(Portfolio = Portfolio, Dates = Dates, Attribute = "Pos.Value", Symbols = Symbols)

Modified: pkg/blotter/R/calcPosAvgCost.R
===================================================================
--- pkg/blotter/R/calcPosAvgCost.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/calcPosAvgCost.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,20 +1,13 @@
-`calcPosAvgCost` <-
-function(PrevPosQty, PrevPosAvgCost, TxnValue, PosQty, ConMult=1)
+#' Calculates the average cost of a resulting position from a transaction
+#' 
+#' @return PosAvgCost: average cost of the resulting position
+#' @param PrevPosQty quantity of the previous position
+#' @param PrevPosAvgCost average position cost of the previous position
+#' @param TxnValue total value of the transaction, including fees
+#' @param PosQty total units (shares) of the resulting position
+#' @param ConMult multiplier from instrument data
+calcPosAvgCost <- function(PrevPosQty, PrevPosAvgCost, TxnValue, PosQty, ConMult=1)
 { # @author Peter Carl
-
-    # DESCRIPTION:
-    # Calculates the average cost of a resulting position from a transaction
-
-    # Inputs
-    # PrevPosQty: quantity of the previous position
-    # PrevPosAvgCost: average position cost of the previous position
-    # TxnValue: total value of the transaction, including fees
-    # PosQty: total units (shares) of the resulting position
-    # Note that the multiplier is missing for other types of instruments
-
-    # Outputs
-    # PosAvgCost: average cost of the resulting position
-
     if(PosQty == 0)
         PosAvgCost = 0
     else {

Modified: pkg/blotter/R/calcTxnAvgCost.R
===================================================================
--- pkg/blotter/R/calcTxnAvgCost.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/calcTxnAvgCost.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,19 +1,10 @@
-`calcTxnAvgCost` <-
-function(TxnValue, TxnQty, ConMult=1)
+#' Calculates a per share or per contract cost of the transaction to match the units the price is quoted in
+#' @param TxnValue total value of the transaction, including fees
+#' @param TxnQty total units (shares) of the transaction
+#' @param ConMult multiplier from instrument data
+#' @return TxnAvgCost: unit normalized (per share) cost implied by the transaction
+calcTxnAvgCost <- function(TxnValue, TxnQty, ConMult=1)
 { # @author Peter Carl
-
-    # DESCRIPTION:
-    # Calculates a per share or per contract cost of the transaction 
-    # to match the units the price is quoted in
-
-    # Inputs
-    # TxnValue: total value of the transaction, including fees
-    # TxnQty: total units (shares) of the transaction
-    # Note that the multiplier is missing for other types of instruments
-
-    # Outputs
-    # TxnAvgCost: unit normalized (per share) cost implied by the transaction
-
     TxnAvgCost = TxnValue/(TxnQty*ConMult)
     return(TxnAvgCost)
 }

Modified: pkg/blotter/R/calcTxnValue.R
===================================================================
--- pkg/blotter/R/calcTxnValue.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/calcTxnValue.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,19 +1,11 @@
-`calcTxnValue` <-
-function(TxnQty, TxnPrice, TxnFees, ConMult=1)
+#' Calculates the total value of a transaction or trade
+#' @param TxnQty total units (shares) of the transaction
+#' @param TxnPrice price at which the transaction was done
+#' @param TxnFees fees associated with the transaction, e.g. commissions
+#' @param ConMult multiplier from instrument data
+#' @return TxnValue: total dollar value of the transaction, including fees
+calcTxnValue <- function(TxnQty, TxnPrice, TxnFees, ConMult=1)
 { # @author Peter Carl
-
-    # DESCRIPTION:
-    # Calculates the total value of a transaction or trade
-
-    # Inputs
-    # TxnQty: total units (shares) of the transaction
-    # TxnPrice: price at which the transaction was done
-    # TxnFees: fees associated with the transaction, e.g. commissions
-    # Note that the multiplier is missing for other types of instruments
-
-    # Outputs
-    # TxnValue: total dollar value of the transaction, including fees
-
     TxnValue = TxnQty * TxnPrice * ConMult - TxnFees
     return(TxnValue)
 }

Deleted: pkg/blotter/R/calcUnrealizedPL.R
===================================================================
--- pkg/blotter/R/calcUnrealizedPL.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/calcUnrealizedPL.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,4 +0,0 @@
-calcUnrealizedPL <- function(TradingPL, RealizedPL) {
-  UnrealizedPL <- TradingPL - RealizedPL
-  return(UnrealizedPL)
-}

Modified: pkg/blotter/R/chart.Posn.R
===================================================================
--- pkg/blotter/R/chart.Posn.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/chart.Posn.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -9,23 +9,11 @@
     pname<-Portfolio
     Portfolio<-getPortfolio(pname)
 
-    # DESCRIPTION
-    # Charts the transaction series of a symbol against prices
-
-    # Inputs
-    # Portfolio: a portfolio object structured with initPortf()
-    # Symbol: an instrument identifier for a symbol included in the portfolio,
-    #   e.g., IBM
-    # Dates: dates to return the calculation over formatted as xts range
-
-    # Outputs
-    # Timeseries object with weights by date in rows and symbolname in columns
-
     # FUNCTION
 
     require(quantmod)
     Prices=get(Symbol)
-	Prices=getPrice(Prices,...)
+	Prices=getPrice(Prices)
     freq = periodicity(Prices)
     switch(freq$scale,
             seconds = { mult=1 },

Modified: pkg/blotter/R/chart.Spread.R
===================================================================
--- pkg/blotter/R/chart.Spread.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/chart.Spread.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,3 +1,10 @@
+#' Charts the transaction series, positions, and P&L of a spread against prices
+#' @param Account 
+#' @param Portfolio string identifying the portfolio to chart
+#' @param Symbols string identifying the symbols to chart for positions
+#' @param Dates date range, currently not used
+#' @param ... any other passthru parameters (typically parameters to \code{chart_Series})
+#' @author brian
 #' @export
 chart.Spread <- function(Account, Portfolio, Spread=NULL, Symbols = NULL, Dates = NULL, ...)
 { # @author Peter Carl
@@ -10,20 +17,7 @@
     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."))
     
-    # DESCRIPTION
-    # Charts the transaction series of a symbol against prices
 
-    # Inputs
-    # Portfolio: a portfolio object structured with initPortf()
-    # Symbol: an instrument identifier for a symbol included in the portfolio,
-    #   e.g., IBM
-    # Dates: dates to return the calculation over formatted as xts range
-
-    # Outputs
-    # Timeseries object with weights by date in rows and symbolname in columns
-
-    # FUNCTION
-
     require(quantmod)
     Prices=get(Spread)
     #buys and sells will be done on the first positive ratio instrument in a spread

Modified: pkg/blotter/R/getAccount.R
===================================================================
--- pkg/blotter/R/getAccount.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/getAccount.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,3 +1,7 @@
+#' get an account object from the environment for examination or manipulation
+#' @param Account string identifier for the account
+#' @param Dates 
+#' @return Account object
 getAccount <- function(Account, Dates=NULL) #should symbol subsets be supported too?  probably not.
 { # @author Brian Peterson
     aname<-Account

Modified: pkg/blotter/R/getByPortf.R
===================================================================
--- pkg/blotter/R/getByPortf.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/getByPortf.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,21 +1,20 @@
+#' get attributes from each portfolio in an account
+#' 
+#' 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'
+#' @param Account an Account object containing Portfolio summaries
+#' @param Attribute column name to be assembled for each symbol
+#' @param Dates 
+#' @return regular xts object of values by portfolio
 .getByPortf <- function(Account, Attribute, Dates=NULL)
 { # @author Peter Carl
     
-    # DESCRIPTION:
-    # 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 
-
-    # Inputs
-    # Account: an Account object containing Portfolio summaries
-    # Attribute: column name to be assembled for each symbol, any of:
-    # 'Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value', 'Txn.Fees',
-    # 'Realized.PL', 'Unrealized.PL', or 'Trading.PL'
-
-    # Outputs
-    # regular xts object of values by portfolio
-
-    # FUNCTION
     zerofill <- function (x) 
     { # kind of like PerformanceAnalytics, but not quite
         for (column in 1:NCOL(x)) {

Modified: pkg/blotter/R/getBySymbol.R
===================================================================
--- pkg/blotter/R/getBySymbol.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/getBySymbol.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,20 +1,20 @@
+#' Retrieves calculated attributes for each position in the portfolio
+#' 
+#' 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'
+#' @param Portfolio a portfolio object containing transactions
+#' @param Attribute column name to be assembled for each symbol
+#' @param Dates 
+#' @param Symbols 
+#' @param native 
+#' @return regular xts object of values by symbol
 .getBySymbol <- function(Portfolio, Attribute, Dates=NULL, Symbols=NULL, native=FALSE)
 { # @author Peter Carl
 
-    # DESCRIPTION:
-    # 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
-
-    # Inputs
-    # Portfolio: a portfolio object containing transactions
-    # Item: column name to be assembled for each symbol, any of:
-    #   'Pos.Qty', 'Pos.Value', 'Txn.Value', 'Realized.PL', 'Unrealized.PL',
-    #    or 'Trading.PL'
-
-    # Outputs
-    # regular xts object of values by symbol
-
     # FUNCTION
     if(is.null(Dates) | is.na(Dates)) # if no date is specified, get all available dates
         Dates = time(Portfolio$symbols[[1]]$posPL)

Modified: pkg/blotter/R/getEndEq.R
===================================================================
--- pkg/blotter/R/getEndEq.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/getEndEq.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,3 +1,7 @@
+#' Retrieves the most recent value of the capital account
+#' @param Account string identifier of account
+#' @param Date last date to retrieve calculated equity for, as string
+#' @return Numeric value of the equity account
 #' @export
 getEndEq <- function(Account, Date)
 { # @author Peter Carl
@@ -5,18 +9,7 @@
     Account<-try(get(paste("account",aname,sep='.'), envir=.blotter))
     if(inherits(Account,"try-error"))
         stop(paste("Account",aname," not found, use initAcct() to create a new account"))
-    
-    # DESCRIPTION:
-    # Retrieves the most recent value of the capital account
 
-    # Inputs
-    # Date: most recent date of last calculated equity
-    # AcctData: location of the ACCOUNT data
-
-    # Outputs
-    # Numeric value of the equity account
-     
-    # FUNCTION
     toDate = paste('::', Date, sep="")
     EndEq = as.numeric(tail(Account$summary[toDate,], n=1)[,"End.Eq"])
     return(EndEq)

Modified: pkg/blotter/R/getPortfAcct.R
===================================================================
--- pkg/blotter/R/getPortfAcct.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/getPortfAcct.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,3 +1,7 @@
+#' 
+#' @param Account 
+#' @param Portfolio 
+#' @param Dates 
 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)

Modified: pkg/blotter/R/getPortfolio.R
===================================================================
--- pkg/blotter/R/getPortfolio.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/getPortfolio.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,3 +1,8 @@
+#' 
+#' @param Portfolio 
+#' @param Dates 
+#' @returnType 
+#' @export
 getPortfolio <- function(Portfolio, Dates=NULL) #should symbol subsets be supported too?  probably not.
 { # @author Brian Peterson
     pname<-Portfolio

Modified: pkg/blotter/R/getPos.R
===================================================================
--- pkg/blotter/R/getPos.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/getPos.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,18 +1,15 @@
+#' 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.
+#' @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)
 { # @author Peter Carl
     Portfolio<-getPortfolio(Portfolio)    
-    # DESCRIPTION:
-    # Retrieves all information about the position as of a date
-
-    # Inputs
-    # Portfolio: a portfolio object containing transactions
-    # Symbol: an instrument identifier for a symbol included in the portfolio
-    # Date: timestamp as of which to have the most recent position
-
-    # Outputs
-    # All data elements related to position in a row of an xts object
-    # This should get much more complicated from here, particularly when it's conditional on symbol, etc.
-    
     # FUNCTION
     PosData = Portfolio$symbols[[Symbol]]$txn
     toDate = paste('::', Date, sep="")

Modified: pkg/blotter/R/getPosAvgCost.R
===================================================================
--- pkg/blotter/R/getPosAvgCost.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/getPosAvgCost.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,22 +1,13 @@
-`getPosAvgCost` <-
-function(Portfolio, Symbol, Date)
+
+#' Retrieves the most recent average cost of the position
+#' 
+#' @param Portfolio 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
+#' @return Numeric value of the average cost of the current position
+.getPosAvgCost <- function(Portfolio, Symbol, Date)
 { # @author Peter Carl
     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 account"))
-    
-    # DESCRIPTION:
-    # Retrieves the most recent average cost of the position
-
-    # Inputs
-    # Portfolio: a portfolio object containing transactions
-    # Symbol: an instrument identifier for a symbol included in the portfolio
-    # Date: timestamp as of which to have the most recent position
-
-    # Outputs
-    # Numeric value of the average cost of the current position
- 
     # FUNCTION
     PosAvgCost = as.numeric(getPos(pname, Symbol, Date)[,"Pos.Avg.Cost"])
     return(PosAvgCost)

Modified: pkg/blotter/R/getPosQty.R
===================================================================
--- pkg/blotter/R/getPosQty.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/getPosQty.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,4 +1,9 @@
-#' @export
+#' gets position at Date
+#' @param Portfolio a 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
+#' @return Numeric value of the most recent position.
+#' @export 
 getPosQty <- function(Portfolio, Symbol, Date)
 { # @author Peter Carl
     pname<-Portfolio
@@ -11,12 +16,12 @@
     # Gets the previous position 
 
     # Inputs
-    # Portfolio: a portfolio object containing transactions
-    # Symbol: an instrument identifier for a symbol included in the portfolio
-    # Date: timestamp as of which to have the most recent position
+    # Portfolio: 
+    # Symbol: 
+    # Date: 
 
     # Outputs
-    # Numeric value of the most recent position.
+    # 
 
     # FUNCTION
     PosQty = as.numeric(getPos(pname, Symbol, Date)[,"Pos.Qty"])

Deleted: pkg/blotter/R/getRealizedPL.R
===================================================================
--- pkg/blotter/R/getRealizedPL.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/getRealizedPL.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,37 +0,0 @@
-`getRealizedPL` <-
-function(Portfolio, Symbol, Date)
-{ # @author Peter Carl
-    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 account"))
-    
-    # DESCRIPTION:
-    # Retrieves realized PL for a period
-
-    # Inputs
-    # Portfolio: a portfolio object containing transactions
-    # Symbol: an instrument identifier for a symbol included in the portfolio
-    # Date: date for which to get realized PL.  Use xts subsetting for best 
-    # results, e.g., '1980-01-01' for a whole day, '1980-01' for a month
-
-    # Outputs
-    # Realized PL calculated for the transaction
-
-    # FUNCTION
-    PosData = Portfolio$symbols[[Symbol]]$txn
-    RealizedPL = sum(as.numeric(PosData[Date, 'Realized.PL', drop=FALSE]))
-    return(RealizedPL)
-}
-
-###############################################################################
-# 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$
-#
-###############################################################################

Modified: pkg/blotter/R/getTxn.R
===================================================================
--- pkg/blotter/R/getTxn.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/getTxn.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,3 +1,9 @@
+#' Gets the transactions and returns 
+#' @param Portfolio a 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 get transactions
+#' @return xts of transactions made in the Symbol during the time period given
+#' @export
 getTxns <- function(Portfolio, Symbol, Date)
 { # @author Peter Carl
     pname<-Portfolio
@@ -5,16 +11,6 @@
     if(inherits(Portfolio,"try-error"))
         stop(paste("Portfolio",name," not found, use initPortf() to create a new portfolio first"))
     
-    # DESCRIPTION:
-    # Gets the transactions and returns 
-
-    # Inputs
-    # Portfolio: a portfolio object containing transactions
-    # Symbol: an instrument identifier for a symbol included in the portfolio
-    # Date: timestamp as of which to have the most recent position
-
-    # Outputs
-    # Table of transactions made in the Symbol during the time period given
     TxnData = Portfolio$symbols[[Symbol]]$txn
     Txns = TxnData[Date,c('Txn.Qty', 'Txn.Price', 'Txn.Fees', 'Txn.Value', 'Txn.Avg.Cost', 'Net.Txn.Realized.PL')]
     return(Txns)

Deleted: pkg/blotter/R/getTxnFees.R
===================================================================
--- pkg/blotter/R/getTxnFees.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/getTxnFees.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,24 +0,0 @@
-`getTxnFees` <-
-function(Portfolio, Symbol, Date)
-{
-    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 account"))
-    
-    TxnData = Portfolio$symbols[[Symbol]]$txn
-    TxnFees = sum(TxnData[Date,'Txn.Fees'])
-    return(TxnFees)
-}
-
-###############################################################################
-# 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$
-#
-###############################################################################

Deleted: pkg/blotter/R/getTxnValue.R
===================================================================
--- pkg/blotter/R/getTxnValue.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/getTxnValue.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,36 +0,0 @@
-`getTxnValue` <-
-function(Portfolio, Symbol, Date)
-{ # @author Peter Carl
-    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 account"))
-    
-    # DESCRIPTION:
-    # Gets the value of that period's transactions and returns the sum 
-
-    # Inputs
-    # Portfolio: a portfolio object containing transactions
-    # Symbol: an instrument identifier for a symbol included in the portfolio
-    # Date: timestamp as of which to have the most recent position
-
-    # Outputs
-    # Numeric value of the most recent position.
-
-    # FUNCTION
-    TxnData = Portfolio$symbols[[Symbol]]$txn
-    TxnValue = sum(TxnData[Date,'Txn.Value'])
-    return(TxnValue)
-}
-
-###############################################################################
-# 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$
-#
-###############################################################################

Modified: pkg/blotter/R/initAcct.R
===================================================================
--- pkg/blotter/R/initAcct.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/initAcct.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -25,20 +25,20 @@
 #' No reason to persist Period.ROR, and Beg.Eq = Previous End.Eq,
 #' So we're left with four columns.  Note that Period.ROR can be calc'd 
 #' several different ways and is best left as a function.
-
+#' 
 #' To get to the CFTC thirteen columns add:
 #' Gross.Realized, Commission, Net.Realized, Int.Income, Ch.Unrealized,
 #' Advisory.Fees, Wealth.Index 
 #' Again, no need to add Wealth.Index. Eventually, these additional 
 #' columns will be useful.  
 #' Gross.Realized will be calculated as (Net) Realized.PL + Txn.Fees
-
+#' 
 #' TODO Add calcPeriodROR function
 #' TODO Adddd functions addCapital, drawCapital, addFees
 #' initDate and initEq can be used in addCapital to initalize the account?
 #' Track cash at this level???
 #' Calc gross PL and subtract fees? Or calc net PL and add fees.
-
+#' 
 #' @param name 
 #' @param portfolios 
 #' @param initDate 
@@ -58,7 +58,7 @@
     account$summary = xts( as.matrix(t(c(0,0,0,0,0,0,0,0,0,0,initEq))), order.by=as.POSIXct(initDate) )
     colnames(account$summary) = c('Additions', 'Withdrawals', 'Realized.PL', 'Unrealized.PL', 'Int.Income', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL', 'Advisory.Fees', 'Net.Performance', 'End.Eq')
     for(portfolio in portfolios){
-        account$portfolios[[portfolio]] = initSummary(initDate=initDate)
+        account$portfolios[[portfolio]] = .initSummary(initDate=initDate)
     }
     # return(account)
     attr(account,'currency')<-currency

Modified: pkg/blotter/R/initPortf.R
===================================================================
--- pkg/blotter/R/initPortf.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/initPortf.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -33,11 +33,11 @@
 	stop("The length of initPosQty is unequal to the number of symbols in the portfolio.")
     for(instrument in symbols){
     	i = match(instrument, symbols)
-        portfolio$symbols[[instrument]]$txn = initTxn(initDate = initDate, initPosQty = initPosQty[i])
-        portfolio$symbols[[instrument]]$posPL = initPosPL(initDate = initDate, initPosQty = initPosQty[i])
+        portfolio$symbols[[instrument]]$txn = .initTxn(initDate = initDate, initPosQty = initPosQty[i])
+        portfolio$symbols[[instrument]]$posPL = .initPosPL(initDate = initDate, initPosQty = initPosQty[i])
         portfolio$symbols[[instrument]][[paste('posPL',currency,sep='.')]] = portfolio$symbols[[instrument]]$posPL
     }
-	portfolio$summary<-initSummary(initDate=initDate)
+	portfolio$summary<-.initSummary(initDate=initDate)
     class(portfolio)<-c("blotter_portfolio", "portfolio")
     attr(portfolio,'currency')<-currency
 	attr(portfolio,'initDate')<-initDate

Modified: pkg/blotter/R/initPosPL.R
===================================================================
--- pkg/blotter/R/initPosPL.R	2010-11-02 20:08:59 UTC (rev 437)
+++ pkg/blotter/R/initPosPL.R	2010-11-04 16:14:20 UTC (rev 438)
@@ -1,22 +1,16 @@
 #' initializes position P&L for a portfolio instrument
+#' 
+#' 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
 #' @param initDate date prior to the first close price given, used to contain initial account equity and initial position
 #' @param \dots any other passthrough parameters  
 #' @param initPosQty initial position, default is zero
 #' @param initConMult initial contract multiplier, default is one(1)
 #' @param initCcyMult initial currency multiplier, default is one(1)
[TRUNCATED]

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


More information about the Blotter-commits mailing list