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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Oct 17 15:35:19 CEST 2012


Author: braverock
Date: 2012-10-17 15:35:18 +0200 (Wed, 17 Oct 2012)
New Revision: 1223

Modified:
   pkg/blotter/R/chart.Posn.R
Log:
- add drawdown panel to chart.Posn

Modified: pkg/blotter/R/chart.Posn.R
===================================================================
--- pkg/blotter/R/chart.Posn.R	2012-10-15 11:25:23 UTC (rev 1222)
+++ pkg/blotter/R/chart.Posn.R	2012-10-17 13:35:18 UTC (rev 1223)
@@ -53,6 +53,14 @@
         CumPL = na.locf(merge(CumPL,index(Prices)))
     else 
         CumPL = NULL
+    
+    if(!is.null(CumPL)) {
+        CumMax <- cummax(CumPL)
+        Drawdown <- -(CumMax - CumPL)
+        Drawdown<-rbind(xts(-max(CumPL),order.by=first(index(Drawdown)-1)),Drawdown)
+    } else {
+        Drawdown <- NULL
+    }
     #     # These aren't quite right, as abs(Pos.Qty) should be less than prior abs(Pos.Qty)
     # SellCover = Portfolio$symbols[[Symbol]]$txn$Txn.Price * (Portfolio$symbols[[Symbol]]$txn$Txn.Qty<0) * (Portfolio$symbols[[Symbol]]$txn$Pos.Qty==0)
     # BuyCover = Portfolio$symbols[[Symbol]]$txn$Txn.Price * (Portfolio$symbols[[Symbol]]$txn$Txn.Qty>0) * (Portfolio$symbols[[Symbol]]$txn$Pos.Qty==0)
@@ -72,6 +80,7 @@
         (add_TA(Position,type='p',col='blue', lwd=2, on=2))   
     }
     if(!is.null(CumPL))  (add_TA(CumPL, col='darkgreen', lwd=2))
+    if(!is.null(Drawdown)) (add_TA(Drawdown, col='darkred', lwd=2, yaxis=c(0,-max(CumMax))))
     plot(current.chob())
 }
 



More information about the Blotter-commits mailing list