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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Dec 22 19:11:51 CET 2010


Author: braverock
Date: 2010-12-22 19:11:51 +0100 (Wed, 22 Dec 2010)
New Revision: 507

Modified:
   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
Log:
- make sure dots pass through to all .init* functions, primarily for timezone handling

Modified: pkg/blotter/R/initAcct.R
===================================================================
--- pkg/blotter/R/initAcct.R	2010-12-22 17:42:52 UTC (rev 506)
+++ pkg/blotter/R/initAcct.R	2010-12-22 18:11:51 UTC (rev 507)
@@ -38,6 +38,7 @@
 #' @param initDate A date prior to the first close price given, used to contain initial account equity and initial position
 #' @param currency ISO currency identifier used to locate the portfolio currency
 #' @param initEq initial account equity in the currency of the portfolio, as a floating point number.
+#' @param \dots any other passthrough parameters  
 #' @export
 #' TODO Add calcPeriodROR function
 #' 
@@ -46,7 +47,7 @@
 #' 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.
-initAcct <- function(name='default', portfolios, initDate="1950-01-01", initEq=0, currency='USD')
+initAcct <- function(name='default', portfolios, initDate="1950-01-01", initEq=0, currency='USD', ...)
 { # @author Peter Carl
 
     if(exists(paste("account",name,sep='.'), envir=.blotter,inherits=TRUE)) 
@@ -56,7 +57,7 @@
     account=list()
     account$portfolios=vector("list",length=length(portfolios))
     names(account$portfolios)=portfolios
-    account$summary = xts( as.matrix(t(c(0,0,0,0,0,0,0,0,0,0,initEq))), order.by=as.POSIXct(initDate) )
+    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)

Modified: pkg/blotter/R/initPortf.R
===================================================================
--- pkg/blotter/R/initPortf.R	2010-12-22 17:42:52 UTC (rev 506)
+++ pkg/blotter/R/initPortf.R	2010-12-22 18:11:51 UTC (rev 507)
@@ -54,9 +54,10 @@
 #' @param initPosQty Initial position quantity, default is zero
 #' @param initDate A date prior to the first close price given, used to contain initial account equity and initial position
 #' @param currency ISO currency identifier used to locate the portfolio currency
+#' @param \dots any other passthrough parameters  
 #' @author Peter Carl
 #' @export
-initPortf <- function(name="default", symbols, initPosQty = 0, initDate = '1950-01-01', currency='USD')
+initPortf <- function(name="default", symbols, initPosQty = 0, initDate = '1950-01-01', currency='USD', ...)
 { # @author Peter Carl
     if(exists(paste("portfolio",name,sep='.'), envir=.blotter,inherits=TRUE))
         stop(paste("Portfolio",name,"already exists, use updatePortf() or addPortfInstr() to update it."))
@@ -71,8 +72,8 @@
 	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)

Modified: pkg/blotter/R/initPosPL.R
===================================================================
--- pkg/blotter/R/initPosPL.R	2010-12-22 17:42:52 UTC (rev 506)
+++ pkg/blotter/R/initPosPL.R	2010-12-22 18:11:51 UTC (rev 507)
@@ -11,7 +11,7 @@
 #' @param initCcyMult initial currency multiplier, default is one(1)
 .initPosPL <- function(initDate="1950-01-01", ..., initPosQty=0, initConMult=1, initCcyMult=1) #TODO add other init values to function as well for cost basis
 { # @author Peter Carl
-    posPL <- xts( as.matrix(t(c(initPosQty,initConMult,initCcyMult,0,0,0,0,0,0,0,0))), order.by=as.POSIXct(initDate) )
+    posPL <- xts( as.matrix(t(c(initPosQty,initConMult,initCcyMult,0,0,0,0,0,0,0,0))), order.by=as.POSIXct(initDate, ...=...), ...=... )
     colnames(posPL) <- c('Pos.Qty', 'Con.Mult', 'Ccy.Mult', 'Pos.Value', 'Pos.Avg.Cost', 'Txn.Value',  'Period.Realized.PL', 'Period.Unrealized.PL','Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL')
     class(posPL)<- c("posPL",class(posPL))
     return(posPL)

Modified: pkg/blotter/R/initSummary.R
===================================================================
--- pkg/blotter/R/initSummary.R	2010-12-22 17:42:52 UTC (rev 506)
+++ pkg/blotter/R/initSummary.R	2010-12-22 18:11:51 UTC (rev 507)
@@ -1,8 +1,9 @@
 #' initialize the summary table used in portfolio and account lists
 #' @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")
+#' @param \dots any other passthrough parameters  
+.initSummary <- function(initDate="1950-01-01",...)
 { # @author Brian Peterson
-    summary <- xts( as.matrix(t(rep(0,9))), order.by=as.POSIXct(initDate) )
+    summary <- xts( as.matrix(t(rep(0,9))), order.by=as.POSIXct(initDate,...=...), ...=... )
     colnames(summary) <- c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value', 'Realized.PL', 'Unrealized.PL', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL')
     class(summary)<-c("portfolio_summary",class(summary))
     return(summary)

Modified: pkg/blotter/R/initTxn.R
===================================================================
--- pkg/blotter/R/initTxn.R	2010-12-22 17:42:52 UTC (rev 506)
+++ pkg/blotter/R/initTxn.R	2010-12-22 18:11:51 UTC (rev 507)
@@ -3,12 +3,13 @@
 #' The data series stored here will be an irregular time series.
 #' @param initDate date prior to the first close price given, used to contain initial account equity and initial position
 #' @param initPosQty initial position, default is zero
+#' @param \dots any other passthrough parameters  
 #' @return Constructs multi-column xts object used to store transactions
-.initTxn <- function(initDate="1950-01-01", initPosQty=0)
+.initTxn <- function(initDate="1950-01-01", initPosQty=0, ...)
 { # @author Peter Carl
     ## TODO: Add 'Txn.Type' column
     ## TODO: DIVIDEND Txn.Type creates a realized gain
-    txn <- xts( as.matrix(t(c(0,0,0,0,initPosQty,0,0,0,0,0))), order.by=as.POSIXct(initDate) )
+    txn <- xts( as.matrix(t(c(0,0,0,0,initPosQty,0,0,0,0,0))), order.by=as.POSIXct(initDate, ...=...), ...=... )
     colnames(txn) <- c('Txn.Qty', 'Txn.Price', 'Txn.Value', 'Txn.Avg.Cost', 'Pos.Qty', 'Pos.Avg.Cost', 'Gross.Txn.Realized.PL', 'Txn.Fees', 'Net.Txn.Realized.PL', 'Con.Mult')
     class(txn)<-c("transactions",class(txn))
     return(txn)



More information about the Blotter-commits mailing list