[Blotter-commits] r1488 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Aug 13 16:42:19 CEST 2013
Author: braverock
Date: 2013-08-13 16:42:19 +0200 (Tue, 13 Aug 2013)
New Revision: 1488
Modified:
pkg/blotter/R/updateAcct.R
Log:
- merged back in changes from r 1484, not sure why svn didn't catch the conflict.
Modified: pkg/blotter/R/updateAcct.R
===================================================================
--- pkg/blotter/R/updateAcct.R 2013-08-13 14:22:09 UTC (rev 1487)
+++ pkg/blotter/R/updateAcct.R 2013-08-13 14:42:19 UTC (rev 1488)
@@ -75,7 +75,6 @@
#multiply by the currency multiplier
psummary<-psummary*CcyMult
}
-
# now bind it
Account$portfolios[[pname]] = rbind(Account$portfolios[[pname]],psummary)
}
@@ -86,9 +85,13 @@
table = .getByPortf(Account, 'Net.Trading.PL', Dates)
obsLength = length(index(table))
obsDates = index(table)
+ if(obsLength > 1) # can't estimate periodicity of one observation
+ on=periodicity(table)$units
+ else
+ on="none"
# Now aggregate the portfolio information into the $summary slot
- Attributes = c('Additions', 'Withdrawals', 'Realized.PL', 'Unrealized.PL', 'Int.Income', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL', 'Advisory.Fees', 'Net.Performance', 'End.Eq')
+ Attributes = c('Additions', 'Withdrawals', 'Realized.PL', 'Unrealized.PL', 'Interest', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL', 'Advisory.Fees', 'Net.Performance', 'End.Eq')
for(Attribute in Attributes) {
switch(Attribute,
@@ -100,9 +103,24 @@
table = .getByPortf(Account, Attribute, Dates)
result = xts(rowSums(table,na.rm=TRUE),order.by=index(table))
},
- Additions = ,
- Withdrawals = ,
- Int.Income = ,
+ 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
+ },
+ 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)
+ },
+ 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)
+ },
Advisory.Fees = ,
Net.Performance = ,
End.Eq = {
@@ -115,6 +133,9 @@
if(is.null(summary)) {summary=result}
else {summary=cbind(summary,result)}
}
+ summary[is.na(summary)] <- 0 # replace any NA's with zero
+ Account$summary <- rbind(Account$summary, summary)
+ # This function does not calculate End.Eq
Account$summary <- rbind(Account$summary, summary)
More information about the Blotter-commits
mailing list