[Blotter-commits] r379 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Aug 23 17:44:54 CEST 2010
Author: braverock
Date: 2010-08-23 17:44:54 +0200 (Mon, 23 Aug 2010)
New Revision: 379
Modified:
pkg/blotter/R/updatePortf.R
Log:
- fix bug for all summary attributes that use Pos.Value to calc
- limit duplicate .getBySymbol calls
Modified: pkg/blotter/R/updatePortf.R
===================================================================
--- pkg/blotter/R/updatePortf.R 2010-08-20 18:12:00 UTC (rev 378)
+++ pkg/blotter/R/updatePortf.R 2010-08-23 15:44:54 UTC (rev 379)
@@ -33,23 +33,38 @@
#Symbols = names(Portfolio$symbols)
Attributes = c('Long.Value', 'Short.Value', 'Net.Value', 'Gross.Value', 'Realized.PL', 'Unrealized.PL', 'Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL')
summary = NULL
+ tmp.attr=NULL
for(attribute in Attributes) {
result=NULL
- 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))
+ Net.Value =,
+ Gross.Value =,
+ Long.Value =,
+ Short.Value =,{
+ # all these use Pos.Value
+ if(is.null(tmp.attr)){
+ table = .getBySymbol(Portfolio = Portfolio, Attribute = "Pos.Value", Dates = Dates, Symbols = Symbols)
+ tmp.attr="Pos.Value"
+ }
+ 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))
+ },
+ Net.Value = { result = xts(rowSums(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))
+ Realized.PL =,
+ Unrealized.PL =,
+ Gross.Trading.PL =,
+ Txn.Fees =,
+ Net.Trading.PL = {
+ table = .getBySymbol(Portfolio = Portfolio, Attribute = attribute, Dates = Dates, Symbols = Symbols)
+ tmp.attr = NULL
+ result = xts(rowSums(table, na.rm=TRUE), order.by=index(table))
}
)
More information about the Blotter-commits
mailing list