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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Mar 27 00:38:48 CET 2010


Author: peter_carl
Date: 2010-03-27 00:38:48 +0100 (Sat, 27 Mar 2010)
New Revision: 307

Modified:
   pkg/blotter/R/calcPortfAttr.R
   pkg/blotter/R/calcPortfSummary.R
   pkg/blotter/R/initAcct.R
   pkg/blotter/R/updateAcct.R
Log:
- added Gross and Net PL to Account structure


Modified: pkg/blotter/R/calcPortfAttr.R
===================================================================
--- pkg/blotter/R/calcPortfAttr.R	2010-03-26 21:19:51 UTC (rev 306)
+++ pkg/blotter/R/calcPortfAttr.R	2010-03-26 23:38:48 UTC (rev 307)
@@ -7,17 +7,23 @@
 #    else Dates = time(Portfolio[[1]]$posPL[Dates])
 
     switch(Attribute,
-        Trading.PL = {
-            table = .getBySymbol(Portfolio = Portfolio, Attribute = 'Trading.PL', Dates = Dates, Symbols = Symbols)
+        Gross.Trading.PL = {
+            table = .getBySymbol(Portfolio = Portfolio, Attribute = 'Gross.Trading.PL', Dates = Dates, Symbols = Symbols)
 #            result = xts(apply(table, FUN='sum', MARGIN=1), Dates)
             result = xts(rowSums(table), na.rm=TRUE ,order.by=index(table))
-            colnames(result) = 'Trading.PL'
+            colnames(result) = 'Gross.Trading.PL'
         },
         Txn.Fees = {
             table = .getBySymbol(Portfolio = Portfolio, Attribute = 'Txn.Fees', Dates = Dates, Symbols = Symbols)
             result = xts(rowSums(table), na.rm=TRUE ,order.by=index(table))
             colnames(result) = 'Txn.Fees'
         },
+        Net.Trading.PL = {
+            table = .getBySymbol(Portfolio = Portfolio, Attribute = 'Net.Trading.PL', Dates = Dates, Symbols = Symbols)
+#            result = xts(apply(table, FUN='sum', MARGIN=1), Dates)
+            result = xts(rowSums(table), na.rm=TRUE ,order.by=index(table))
+            colnames(result) = 'Net.Trading.PL'
+        },
         Realized.PL = {
             table = .getBySymbol(Portfolio = Portfolio, Attribute = 'Realized.PL', Dates = Dates, Symbols = Symbols)
             result = xts(rowSums(table), na.rm=TRUE ,order.by=index(table))

Modified: pkg/blotter/R/calcPortfSummary.R
===================================================================
--- pkg/blotter/R/calcPortfSummary.R	2010-03-26 21:19:51 UTC (rev 306)
+++ pkg/blotter/R/calcPortfSummary.R	2010-03-26 23:38:48 UTC (rev 307)
@@ -9,7 +9,8 @@
         Dates = time(Portfolio[[1]]$posPL )
 #    else Dates = time(Portfolio[[1]]$posPL[Dates])
     
-    TradingPL = calcPortfAttr(Portfolio, 'Trading.PL', Dates)
+    GrossTradingPL = calcPortfAttr(Portfolio, 'Gross.Trading.PL', Dates)
+    NetTradingPL = calcPortfAttr(Portfolio, 'Net.Trading.PL', Dates)
     RealizedPL = calcPortfAttr(Portfolio, 'Realized.PL', Dates)
     UnrealizedPL = calcPortfAttr(Portfolio, 'Unrealized.PL', Dates)
     # UnrealizedPL = TradingPL - RealizedPL
@@ -19,9 +20,8 @@
     LongValue = calcPortfAttr(Portfolio, 'Long.Value', Dates)
     ShortValue = calcPortfAttr(Portfolio, 'Short.Value', Dates)
 
-    summary=merge(LongValue, ShortValue, NetValue, GrossValue, TxnFees, RealizedPL, UnrealizedPL, TradingPL)
-#     colnames(summary)=c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value', 'Txn.Fees','Realized.PL', 'Unrealized.PL', 'Trading.PL')
-# Needed?
+    summary=merge(LongValue, ShortValue, NetValue, GrossValue, RealizedPL, UnrealizedPL, GrossTradingPL, TxnFees, NetTradingPL)
+#     colnames(summary)=c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value', 'Realized.PL', 'Unrealized.PL', 'Gross.Trading.PL','Txn.Fees','Net.Trading.PL')
     return(summary)
 }
 

Modified: pkg/blotter/R/initAcct.R
===================================================================
--- pkg/blotter/R/initAcct.R	2010-03-26 21:19:51 UTC (rev 306)
+++ pkg/blotter/R/initAcct.R	2010-03-26 23:38:48 UTC (rev 307)
@@ -55,11 +55,11 @@
     # FUNCTION
     account=vector("list",length=(length(portfolios)+1))
     names(account)=c("TOTAL",paste("portfolio",portfolios,sep='.'))
-    account[["TOTAL"]] = xts( as.matrix(t(c(0,0,0,0,0,0,0,0,0,initEq))), order.by=as.POSIXct(initDate) )
-    colnames(account[["TOTAL"]]) = c('Additions', 'Withdrawals', 'Txn.Fees', 'Realized.PL', 'Unrealized.PL', 'Int.Income', 'Trading.PL', 'Advisory.Fees', 'Net.Performance', 'End.Eq')
+    account[["TOTAL"]] = xts( as.matrix(t(c(0,0,0,0,0,0,0,0,0,0,initEq))), order.by=as.POSIXct(initDate) )
+    colnames(account[["TOTAL"]]) = 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[[paste("portfolio",portfolio,sep=".")]] = xts( as.matrix(t(c(0,0,0,0,0,0,0,0))), order.by=as.POSIXct(initDate) )
-        colnames(account[[paste("portfolio",portfolio,sep=".")]]) = c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value', 'Txn.Fees','Realized.PL', 'Unrealized.PL', 'Trading.PL')
+        account[[paste("portfolio",portfolio,sep=".")]] = xts( as.matrix(t(c(0,0,0,0,0,0,0,0,0))), order.by=as.POSIXct(initDate) )
+        colnames(account[[paste("portfolio",portfolio,sep=".")]]) = c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value', 'Realized.PL', 'Unrealized.PL', 'Gross.Trading.PL','Txn.Fees','Net.Trading.PL')
     }
     # return(account)
     class(account)<-c("portfolio_account","account")

Modified: pkg/blotter/R/updateAcct.R
===================================================================
--- pkg/blotter/R/updateAcct.R	2010-03-26 21:19:51 UTC (rev 306)
+++ pkg/blotter/R/updateAcct.R	2010-03-26 23:38:48 UTC (rev 307)
@@ -63,9 +63,10 @@
         EndEq = Additions
         RealizedPL = calcAcctAttr(Account, 'Realized.PL', CurrentSpan)
         UnrealizedPL = calcAcctAttr(Account, 'Unrealized.PL', CurrentSpan)
-        TradingPL = calcAcctAttr(Account, 'Trading.PL', CurrentSpan)
-        rows = cbind(Additions, Withdrawals, TxnFees, RealizedPL, UnrealizedPL, IntIncome, TradingPL, AdvisoryFees,NetPerformance, EndEq)
-        colnames(rows) = c('Additions', 'Withdrawals', 'Txn.Fees', 'Realized.PL', 'Unrealized.PL', 'Int.Income', 'Trading.PL', 'Advisory.Fees', 'Net.Performance', 'End.Eq')
+        GrossTradingPL = calcAcctAttr(Account, 'Gross.Trading.PL', CurrentSpan)
+        NetTradingPL = calcAcctAttr(Account, 'Net.Trading.PL', CurrentSpan)
+        rows = cbind(Additions, Withdrawals, RealizedPL, UnrealizedPL, IntIncome, GrossTradingPL, TxnFees, NetTradingPL, AdvisoryFees, NetPerformance, EndEq)
+        colnames(rows) = c('Additions', 'Withdrawals', 'Realized.PL', 'Unrealized.PL', 'Int.Income', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL', 'Advisory.Fees', 'Net.Performance', 'End.Eq')
         Account[['TOTAL']] <- rbind(Account[['TOTAL']], rows)
     # This function does not calculate End.Eq 
     }



More information about the Blotter-commits mailing list