[Blotter-commits] r547 - pkg/blotter/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jan 31 21:40:16 CET 2011
Author: braverock
Date: 2011-01-31 21:40:16 +0100 (Mon, 31 Jan 2011)
New Revision: 547
Modified:
pkg/blotter/R/updatePosPL.R
Log:
- apply patch from Wolfgang Wu to deal with changes in currency exchange rates to portfolio value even when there are no transactions
Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R 2011-01-31 20:39:07 UTC (rev 546)
+++ pkg/blotter/R/updatePosPL.R 2011-01-31 20:40:16 UTC (rev 547)
@@ -189,12 +189,23 @@
CcyMult<-1/CcyMult
}
- #multiply the correct columns
- columns<-c('Pos.Value', 'Txn.Value', 'Period.Realized.PL', 'Period.Unrealized.PL','Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL')
+
+ #multiply the correct columns
+ columns<-c('Pos.Value', 'Txn.Value', 'Pos.Avg.Cost', 'Period.Realized.PL', 'Period.Unrealized.PL','Gross.Trading.PL', 'Txn.Fees', 'Net.Trading.PL')
TmpPeriods[,columns]<-TmpPeriods[,columns]*CcyMult
TmpPeriods[,'Ccy.Mult']<-CcyMult
+
+ #add change in Pos.Value in base currency
+ LagValue<-as.numeric(last(Portfolio$symbols[[Symbol]][[paste('posPL',p.ccy.str,sep='.')]]$Pos.Value))
+ ifelse(length(LagValue)==0, LagValue <- 0, LagValue);
+ CcyMove <- TmpPeriods$Pos.Value - LagValue - TmpPeriods$Txn.Value - TmpPeriods$Period.Unrealized.PL - TmpPeriods$Period.Realized.PL;
+ TmpPeriods$Gross.Trading.PL <- TmpPeriods$Gross.Trading.PL + CcyMove
+ TmpPeriods$Net.Trading.PL <- TmpPeriods$Net.Trading.PL + CcyMove
+ TmpPeriods$Period.Unrealized.PL <- TmpPeriods$Period.Unrealized.PL + CcyMove
+
#stick it in posPL.ccy
Portfolio$symbols[[Symbol]][[paste('posPL',p.ccy.str,sep='.')]]<-rbind(Portfolio$symbols[[Symbol]][[paste('posPL',p.ccy.str,sep='.')]],TmpPeriods)
+
# assign Portfolio to environment
assign( paste("portfolio",pname,sep='.'), Portfolio, envir=.blotter )
}
More information about the Blotter-commits
mailing list