[Blotter-commits] r377 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Aug 20 16:22:48 CEST 2010
Author: peter_carl
Date: 2010-08-20 16:22:48 +0200 (Fri, 20 Aug 2010)
New Revision: 377
Modified:
pkg/blotter/R/updatePortf.R
Log:
- adds portfolio summary calculations, but does not save them yet
- BROKEN
Modified: pkg/blotter/R/updatePortf.R
===================================================================
--- pkg/blotter/R/updatePortf.R 2010-08-17 21:03:50 UTC (rev 376)
+++ pkg/blotter/R/updatePortf.R 2010-08-20 14:22:48 UTC (rev 377)
@@ -27,6 +27,32 @@
tmp_instr<-try(getInstrument(symbol))
updatePosPL(Portfolio=pname, Symbol=as.character(symbol), Dates=Dates, Prices=Prices)
}
+ # Calculate and store portfolio summary table
+ Portfolio<-getPortfolio(pname) # refresh with an updated object
+ Symbols = names(Portfolio)
+ Attributes = c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value', 'Realized.PL', 'Unrealized.PL', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL')
+ summary = matrix()
+ for(attribute in Attributes) {
+ table = .getBySymbol(Portfolio = Portfolio, Attribute = attribute, Dates = Dates, Symbols = Symbols)
+ switch(attribute,
+ Gross.Value = {
+ result = xts(rowSums(abs(table), na.rm=TRUE), order.by=index(table))
+ },
+ Long.Value = {
+ tmat = apply(table,MARGIN=c(1,2),FUN=max,0)# comes out a matrix
+ result = xts(rowSums(tmat, na.rm=TRUE), order.by=index(table))
+ },
+ Short.Value = {
+ tmat = apply(table,MARGIN=c(1,2),FUN=min,0) # comes out a matrix
+ result = xts(rowSums(tmat, na.rm=TRUE), order.by=index(table))
+ },
+ { result = xts(rowSums(table, na.rm=TRUE), order.by=index(table))
+ }
+ )
+ colnames(result) = attribute
+ summary = merge(summary, result)
+ }
+ # TODO: Now store summary in the correct slot in the Portfolio object
return(pname) #not sure this is a good idea
}
More information about the Blotter-commits
mailing list