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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 22 23:21:13 CEST 2013


Author: peter_carl
Date: 2013-07-22 23:21:12 +0200 (Mon, 22 Jul 2013)
New Revision: 1484

Modified:
   pkg/blotter/R/updateAcct.R
Log:
- fixed condition where periodicity cannot be determined in account summary of attributes

Modified: pkg/blotter/R/updateAcct.R
===================================================================
--- pkg/blotter/R/updateAcct.R	2013-07-22 01:27:14 UTC (rev 1483)
+++ pkg/blotter/R/updateAcct.R	2013-07-22 21:21:12 UTC (rev 1484)
@@ -85,6 +85,10 @@
     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', 'Interest', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL', 'Advisory.Fees', 'Net.Performance', 'End.Eq')
@@ -100,13 +104,22 @@
                 result = xts(rowSums(table,na.rm=TRUE),order.by=index(table))
             },
             Additions = {
-                result = period.apply(Account$Additions[obsDates], endpoints(Account$Additions[obsDates], on=periodicity(table)$units), sum) # aggregates multiple account txns 
+                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 = period.apply(Account$Withdrawals[obsDates], endpoints(Account$Withdrawals[obsDates], on=periodicity(table)$units), sum)
+              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 = period.apply(Account$Interest[obsDates], endpoints(Account$Interest[obsDates], on=periodicity(table)$units), sum)
+              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 = ,



More information about the Blotter-commits mailing list