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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Mar 14 05:05:51 CET 2011


Author: bodanker
Date: 2011-03-14 05:05:47 +0100 (Mon, 14 Mar 2011)
New Revision: 575

Modified:
   pkg/blotter/R/updatePosPL.R
Log:
- Fix updatePosPL bug when updatePortf is run over multiple transactions


Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R	2011-03-13 18:45:47 UTC (rev 574)
+++ pkg/blotter/R/updatePosPL.R	2011-03-14 04:05:47 UTC (rev 575)
@@ -196,9 +196,11 @@
 	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;
+	LagValue <- as.numeric(last(Portfolio$symbols[[Symbol]][[paste('posPL',p.ccy.str,sep='.')]]$Pos.Value))
+	if(length(LagValue)==0) LagValue <- 0
+	LagPos.Value <- lag(TmpPeriods$Pos.Value,1)
+	LagPos.Value[1] <- LagValue
+	CcyMove <- TmpPeriods$Pos.Value - LagPos.Value - 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



More information about the Blotter-commits mailing list