[Blotter-commits] r1492 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Aug 13 20:01:30 CEST 2013
Author: peter_carl
Date: 2013-08-13 20:01:30 +0200 (Tue, 13 Aug 2013)
New Revision: 1492
Modified:
pkg/blotter/R/updateAcct.R
Log:
- added tests for empty account transactions
- scoped Dates=NULL to ignore initDate to prevent row duplication of initDate
Modified: pkg/blotter/R/updateAcct.R
===================================================================
--- pkg/blotter/R/updateAcct.R 2013-08-13 17:23:04 UTC (rev 1491)
+++ pkg/blotter/R/updateAcct.R 2013-08-13 18:01:30 UTC (rev 1492)
@@ -14,7 +14,7 @@
Portfolios = names(Account$portfolios)
- if(is.null(Dates)) Dates<-index(getPortfolio(Portfolios[1])$summary)
+ if(is.null(Dates)) Dates<-index(getPortfolio(Portfolios[1])$summary)[-1]
#trim to only time prior to Dates
if(last(index(Account$summary))>.parseISO8601(Dates)$first.time){
@@ -106,20 +106,32 @@
Additions = {
result = if(on=="none")
as.xts(sum(Account$Additions[paste("::",obsDates, sep="")]), order.by=index(table))
- else
- period.apply(Account$Additions[obsDates], endpoints(Account$Additions[obsDates], on=on), sum) # aggregates multiple account txns
+ else{
+ if(length(Account$Additions[obsDates])>0) # catch empty sets
+ period.apply(Account$Additions[obsDates], endpoints(Account$Additions[obsDates], on=on), sum) # aggregates multiple account txns
+ else
+ xts(rep(0,obsLength),order.by=obsDates)
+ }
},
Withdrawals = {
result = if(on=="none")
as.xts(sum(Account$Withdrawals[paste("::",obsDates, sep="")]), order.by=index(table))
- else
- period.apply(Account$Withdrawals[obsDates], endpoints(Account$Withdrawals[obsDates], on=periodicity(table)$units), sum)
+ else{
+ if(length(Account$Additions[obsDates])>0) # catch empty sets
+ period.apply(Account$Withdrawals[obsDates], endpoints(Account$Withdrawals[obsDates], on=periodicity(table)$units), sum)
+ else
+ xts(rep(0,obsLength),order.by=obsDates)
+ }
},
Interest = {
result = if(on=="none")
as.xts(sum(Account$Interest[paste("::",obsDates, sep="")]),, order.by=index(table))
- else
- period.apply(Account$Interest[obsDates], endpoints(Account$Interest[obsDates], on=periodicity(table)$units), sum)
+ else{
+ if(length(Account$Additions[obsDates])>0) # catch empty sets
+ period.apply(Account$Interest[obsDates], endpoints(Account$Interest[obsDates], on=periodicity(table)$units), sum)
+ else
+ xts(rep(0,obsLength),order.by=obsDates)
+ }
},
Advisory.Fees = ,
Net.Performance = ,
More information about the Blotter-commits
mailing list