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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jan 12 21:01:02 CET 2010


Author: braverock
Date: 2010-01-12 21:01:01 +0100 (Tue, 12 Jan 2010)
New Revision: 146

Modified:
   pkg/blotter/R/chart.Posn.R
Log:
- add logic to only chart CumPL if summary portfolio stats have been calculated

Modified: pkg/blotter/R/chart.Posn.R
===================================================================
--- pkg/blotter/R/chart.Posn.R	2010-01-12 19:47:21 UTC (rev 145)
+++ pkg/blotter/R/chart.Posn.R	2010-01-12 20:01:01 UTC (rev 146)
@@ -32,6 +32,8 @@
     Position = Portfolio[[Symbol]]$txn$Pos.Qty
     Position = na.locf(merge(Position,index(Prices)))
     CumPL = cumsum(Portfolio[[Symbol]]$posPL$Trading.PL)
+    if(length(CumPL)>1) CumPL = na.locf(merge(CumPL,index(Prices)))
+    else CumPL = NULL
     #     # These aren't quite right, as abs(Pos.Qty) should be less than prior abs(Pos.Qty)
     # SellCover = Portfolio[[Symbol]]$txn$Txn.Price * (Portfolio[[Symbol]]$txn$Txn.Qty<0) * (Portfolio[[Symbol]]$txn$Pos.Qty==0)
     # BuyCover = Portfolio[[Symbol]]$txn$Txn.Price * (Portfolio[[Symbol]]$txn$Txn.Qty>0) * (Portfolio[[Symbol]]$txn$Pos.Qty==0)
@@ -44,7 +46,7 @@
     plot(addTA(Buys,pch=2,type='p',col='green', on=1));
     plot(addTA(Sells,pch=6,type='p',col='red', on=1));
     plot(addTA(Position,type='h',col='blue', lwd=2));
-    plot(addTA(CumPL, col='darkgreen', lwd=2))
+    if(!is.null(CumPL))  plot(addTA(CumPL, col='darkgreen', lwd=2))
 }
 
 ###############################################################################



More information about the Blotter-commits mailing list