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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Nov 7 21:50:12 CET 2014


Author: bodanker
Date: 2014-11-07 21:50:11 +0100 (Fri, 07 Nov 2014)
New Revision: 1646

Modified:
   pkg/blotter/R/updatePosPL.R
Log:
- Fix .updatePosPL when it's called with only one date and price


Modified: pkg/blotter/R/updatePosPL.R
===================================================================
--- pkg/blotter/R/updatePosPL.R	2014-11-06 20:05:03 UTC (rev 1645)
+++ pkg/blotter/R/updatePosPL.R	2014-11-07 20:50:11 UTC (rev 1646)
@@ -105,6 +105,9 @@
 		#first price is NA, it would be nice to fill it in with a previous last valid price
 		fprice <- last(prices[paste('::',startDate,sep='')])
 		if (length(fprice)==1) tmpPL[1,'Prices'] <- fprice 
+                # if there's no previous valid price, calculate it from the prior position value
+                # (can occur if .updatePosPL is called repeatedly with only one date/price)
+                if (length(fprice)==0) tmpPL[1,'Prices'] <- priorPL[,'Pos.Value'] / priorPL[,'Pos.Qty']
 	}
 	# na.locf any missing prices with last observation (this assumption seems the only rational one for vectorization)
 	# and na.locf Pos.Qty,Con.Mult,Pos.Avg.Cost to instantiate $posPL new rows



More information about the Blotter-commits mailing list