[Blotter-commits] r1718 - in pkg/quantstrat: R demo

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Nov 15 18:08:44 CET 2015


Author: bodanker
Date: 2015-11-15 18:08:44 +0100 (Sun, 15 Nov 2015)
New Revision: 1718

Modified:
   pkg/quantstrat/R/chart.forward.R
   pkg/quantstrat/R/chart.forward.training.R
   pkg/quantstrat/demo/luxor.sample.walk.forward.R
Log:
Use xts:::plot.xts for walk-forward analysis

The chart.forward.* functions still used the plot.xts API from xtsExtra
from before Ross Bennett's GSoC work. Update them to use the current
API defined by xts:::plot.xts.

Thanks to Alex Alias for the report and patch.


Modified: pkg/quantstrat/R/chart.forward.R
===================================================================
--- pkg/quantstrat/R/chart.forward.R	2015-11-15 00:23:07 UTC (rev 1717)
+++ pkg/quantstrat/R/chart.forward.R	2015-11-15 17:08:44 UTC (rev 1718)
@@ -47,20 +47,11 @@
     CumMax <- cummax(PL.xts)
     Drawdowns.xts <- -(CumMax - PL.xts)
     data.to.plot <- as.xts(cbind(PL.xts, Drawdowns.xts))
-    
-    # now plot it
-    dev.new()
-    plot.xts(
-        data.to.plot,
-        screens=rep(1:2,each=n+1),
-        col=c(rep('grey',n), 'blue'),
-        minor.ticks=FALSE,
-        main=NA
-    )
-    title(
-        main='Walk Forward Analysis',
-        sub=audit.filename
-    )
-    
+
+    p <- plot(PL.xts, col=c("blue", rep("grey", n-1)), main="Walk Forward Analysis")
+    # set on=NA so it is drawn on a new panel
+    p <- lines(Drawdowns.xts, col=c("blue", rep("grey", n-1)), on=NA, main="Drawdowns")
+    print(p)
+
     .audit <- NULL
 }

Modified: pkg/quantstrat/R/chart.forward.training.R
===================================================================
--- pkg/quantstrat/R/chart.forward.training.R	2015-11-15 00:23:07 UTC (rev 1717)
+++ pkg/quantstrat/R/chart.forward.training.R	2015-11-15 17:08:44 UTC (rev 1718)
@@ -29,10 +29,11 @@
         PL.xts <- cbind(PL.xts, R)
     }
     
-    # add a column for the chosen portfolio, doubling it
+    # .audit$param.combo.nr contains the rowname of the best portfolio
     chosen.one <- .audit$param.combo.nr
     chosen.portfolio.st = ls(name=.audit, pattern=glob2rx(paste('portfolio', '*', chosen.one, sep='.')))
-
+    # add a column for the chosen portfolio, doubling it and
+    # making it plot last, so it's not over-plotted by other portfolios
     R <- PL.xts[,chosen.portfolio.st]
     PL.xts <- cbind(PL.xts, R)
     
@@ -42,21 +43,15 @@
     CumMax <- cummax(PL.xts)
     Drawdowns.xts <- -(CumMax - PL.xts)
     data.to.plot <- as.xts(cbind(PL.xts, Drawdowns.xts))
-    
-    # now plot it
-    dev.new()
-    plot.xts(
-        data.to.plot,
-        screens=rep(1:2,each=n+1),
-        col=c(rep('grey',n), 'blue'),
-        minor.ticks=FALSE,
-        main=NA
-    )
-    title(
-        main='Walk Forward Analysis',
-        sub=audit.filename
-    )
-    
+
+    # based on the suggestion by Ross, note that the number of
+    # lines is increased by 1 since the 'chosen' portfolio is added as the last one
+    # and highlighted using the blue color
+    p <- plot(PL.xts, col=c("blue", rep("grey", n)), main="Walk Forward Analysis")
+    # set on=NA so it is drawn on a new panel
+    p <- lines(Drawdowns.xts, col=c("blue", rep("grey", n)), on=NA, main="Drawdowns")
+    print(p)
+
     .audit <- NULL
 }
 

Modified: pkg/quantstrat/demo/luxor.sample.walk.forward.R
===================================================================
--- pkg/quantstrat/demo/luxor.sample.walk.forward.R	2015-11-15 00:23:07 UTC (rev 1717)
+++ pkg/quantstrat/demo/luxor.sample.walk.forward.R	2015-11-15 17:08:44 UTC (rev 1718)
@@ -10,7 +10,7 @@
 
 require('quantstrat')
 
-chart.forward.testing('../data/luxor.wfa.ples.GBPUSD.2003-01-02 05:30:00.2003-03-31 23:30:00.RData')
+chart.forward.training(paste0(path.package("quantstrat"),'/data/luxor.wfa.ples.RData'))
 
 ##### PLACE DEMO AND TEST DATES HERE #################
 #



More information about the Blotter-commits mailing list