[Blotter-commits] r1383 - in pkg/quantstrat: . R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jan 24 22:12:38 CET 2013


Author: opentrades
Date: 2013-01-24 22:12:38 +0100 (Thu, 24 Jan 2013)
New Revision: 1383

Added:
   pkg/quantstrat/R/chart.forward.R
Modified:
   pkg/quantstrat/DESCRIPTION
   pkg/quantstrat/NAMESPACE
Log:
- added chart.forward() function to visualize portfolio chosen by objective function in relation to all evaluated portfolios



Modified: pkg/quantstrat/DESCRIPTION
===================================================================
--- pkg/quantstrat/DESCRIPTION	2013-01-24 00:56:18 UTC (rev 1382)
+++ pkg/quantstrat/DESCRIPTION	2013-01-24 21:12:38 UTC (rev 1383)
@@ -10,16 +10,19 @@
     foreach(>= 1.4.0)
 Suggests:
     PerformanceAnalytics,PortfolioAnalytics,rgl,
-    testthat
+    testthat,
+    xtsExtra
 Maintainer: Brian G. Peterson <brian at braverock.com>
 Description: Specify, build, and back-test quantitative
     financial trading and portfolio strategies
-Contributors: Yu Chen, Joe Dunn, Dirk Eddelbuettel, Jeffrey A. Ryan, Garrett See
+Contributors: Yu Chen, Joe Dunn, Dirk Eddelbuettel, Jeffrey A. Ryan, Garrett
+    See, Jan Humme
 LazyLoad: yes
 License: GPL-3
 ByteCompile: TRUE
 Collate:
     'applyStrategy.rebalancing.R'
+    'chart.forward.R'
     'indicators.R'
     'initialize.R'
     'match.names.R'

Modified: pkg/quantstrat/NAMESPACE
===================================================================
--- pkg/quantstrat/NAMESPACE	2013-01-24 00:56:18 UTC (rev 1382)
+++ pkg/quantstrat/NAMESPACE	2013-01-24 21:12:38 UTC (rev 1383)
@@ -13,6 +13,7 @@
 export(applySignals)
 export(applyStrategy.rebalancing)
 export(applyStrategy)
+export(chart.forward)
 export(delete.paramset)
 export(getOrderBook)
 export(getOrders)

Added: pkg/quantstrat/R/chart.forward.R
===================================================================
--- pkg/quantstrat/R/chart.forward.R	                        (rev 0)
+++ pkg/quantstrat/R/chart.forward.R	2013-01-24 21:12:38 UTC (rev 1383)
@@ -0,0 +1,57 @@
+#' Chart to analyse walk.forward() objective function
+#'
+#' @param audit.filename name of .audit environment file as produced by walk.forward()
+#'
+#' @export
+
+chart.forward <- function(audit.filename)
+{
+    if(!require(xtsExtra, quietly=TRUE))	stop('The "xtsExtra" package is required to use this function')
+
+    .audit <- NULL
+
+    load(audit.filename)
+
+    # extract all portfolio names from the audit environment
+    portfolios.st = ls(name=.audit, pattern='portfolio.*')
+    n <- length(portfolios.st)
+
+    # calculate Net.Trading.PL for each portfolio, one xts col per portfolio
+    PL.xts <- xts()
+    for(portfolio.st in portfolios.st)
+    {
+        p <- getPortfolio(portfolio.st, envir=.audit)
+        
+        R <- cumsum(p$summary['2004-01-01/','Net.Trading.PL'])
+        names(R) <- portfolio.st
+        
+        PL.xts <- cbind(PL.xts, R)
+    }
+    
+    # add a column for the chosen portfolio, doubling it
+    chosen.one <- .audit$param.combo.nr
+    chosen.portfolio.st = ls(name=.audit, pattern=glob2rx(paste('portfolio', '*', chosen.one, sep='.')))
+    R <- PL.xts[,chosen.portfolio.st]
+    PL.xts <- cbind(PL.xts, R)
+    
+    # add drawdown columns for all portfolio columns
+    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
+    )
+    
+    .audit <- NULL
+}


Property changes on: pkg/quantstrat/R/chart.forward.R
___________________________________________________________________
Added: svn:executable
   + *



More information about the Blotter-commits mailing list