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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 27 15:03:52 CEST 2010


Author: braverock
Date: 2010-09-27 15:03:51 +0200 (Mon, 27 Sep 2010)
New Revision: 402

Modified:
   pkg/blotter/R/updatePosPL.R
Log:
- fix NA in first row of Gross.Trading.PL, 
  resolves possible improper result in first period

Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R	2010-09-23 20:48:57 UTC (rev 401)
+++ pkg/blotter/R/updatePosPL.R	2010-09-27 13:03:51 UTC (rev 402)
@@ -87,8 +87,9 @@
 	tmpPL$Unrealized.PL <- round(tmpPL$Pos.Qty*(tmpPL$Prices-tmpPL$Pos.Avg.Cost)*tmpPL$Con.Mult,2)
 	
 	# matrix calc Gross.Trading.PL as Pos.Value-Lag(Pos.Value)-Txn.Value
-	tmpPL$Gross.Trading.PL <- tmpPL$Pos.Value-Lag(tmpPL$Pos.Value)- tmpPL$Txn.Value
-	tmpPL$Gross.Trading.PL[1] <- 0
+	LagValue<-Lag(tmpPL$Pos.Value)
+	LagValue<-ifelse(is.na(LagValue),0,LagValue) # needed to avoid a possible NA on the first value that would mess up the Gross.Trading.PL calc
+	tmpPL$Gross.Trading.PL <- tmpPL$Pos.Value- LagValue - tmpPL$Txn.Value
 	
 	# matrix calc Realized.PL as Gross.Trading.PL - Unrealized.PL
 	tmpPL$Realized.PL <- round(tmpPL$Gross.Trading.PL - tmpPL$Unrealized.PL,2)



More information about the Blotter-commits mailing list