[Blotter-commits] r59 - pkg/demo

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Mar 5 06:32:39 CET 2009


Author: peter_carl
Date: 2009-03-05 06:32:39 +0100 (Thu, 05 Mar 2009)
New Revision: 59

Modified:
   pkg/demo/turtles.R
Log:
-- added quantmod graphic with trades


Modified: pkg/demo/turtles.R
===================================================================
--- pkg/demo/turtles.R	2009-03-03 02:59:04 UTC (rev 58)
+++ pkg/demo/turtles.R	2009-03-05 05:32:39 UTC (rev 59)
@@ -164,6 +164,18 @@
 # Final values
 cat('Return: ',(getEndEq(Account=account, Date=CurrentDate)-initEq)/initEq,'\n')
 
+if (require(quantmod)) {
+  Buys = portfolio[["XLF"]]$txn$Txn.Price*(Portfolio[[Symbol]]$txn$Txn.Qty>0)
+  Sells = portfolio[["XLF"]]$txn$Txn.Price*(Portfolio[[Symbol]]$txn$Txn.Qty<0)
+  Position = portfolio[["XLF"]]$posPL$Pos.Qty
+  CumPL = cumsum(portfolio[["XLF"]]$posPL$Trading.PL)
+  chartSeries(XLF['2006::2009',], TA=NULL)
+  plot(addTA(Buys['2006::2009',],pch=2,type='p',col='green', on=1));
+  plot(addTA(Sells['2006::2009',],pch=6,type='p',col='red', on=1));
+  plot(addTA(Position['2006::2009',],type='h',col='blue', lwd=2));
+  plot(addTA(CumPL['2006::2009',], col='darkgreen', lwd=2))
+}
+
 require(PerformanceAnalytics)
 return = Delt(account[["TOTAL"]]$End.Eq)
 charts.PerformanceSummary(return)
\ No newline at end of file



More information about the Blotter-commits mailing list