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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Dec 19 00:52:13 CET 2012


Author: opentrades
Date: 2012-12-19 00:52:12 +0100 (Wed, 19 Dec 2012)
New Revision: 1303

Added:
   pkg/quantstrat/R/walk.forward.R
Modified:
   pkg/quantstrat/DESCRIPTION
   pkg/quantstrat/NAMESPACE
   pkg/quantstrat/man/addOrder.Rd
   pkg/quantstrat/man/apply.paramset.Rd
   pkg/quantstrat/man/ruleSignal.Rd
Log:
first draft for walk.forward.R



Modified: pkg/quantstrat/DESCRIPTION
===================================================================
--- pkg/quantstrat/DESCRIPTION	2012-12-18 13:19:40 UTC (rev 1302)
+++ pkg/quantstrat/DESCRIPTION	2012-12-18 23:52:12 UTC (rev 1303)
@@ -8,7 +8,8 @@
     xts(>= 0.8-2),TTR(>= 0.2),blotter(>= 0.7.2),
     FinancialInstrument(>= 0.12.5)
 Suggests:
-    PerformanceAnalytics,PortfolioAnalytics,rgl, testthat
+    PerformanceAnalytics,PortfolioAnalytics,rgl,
+    testthat
 Maintainer: Brian G. Peterson <brian at braverock.com>
 Description: Specify, build, and back-test quantitative
     financial trading and portfolio strategies
@@ -16,3 +17,23 @@
 LazyLoad: yes
 License: GPL-3
 ByteCompile: TRUE
+Collate:
+    'applyStrategy.rebalancing.R'
+    'indicators.R'
+    'initialize.R'
+    'match.names.R'
+    'orders.R'
+    'osFUNs.R'
+    'parameters.R'
+    'paramsets.R'
+    'rebalance.rules.R'
+    'ruleOrderProc.R'
+    'ruleRevoke.R'
+    'rules.R'
+    'ruleSignal.R'
+    'signals.R'
+    'strategy.R'
+    'tradeGraphs.R'
+    'utils.R'
+    'walk.forward.R'
+    'wrapup.R'

Modified: pkg/quantstrat/NAMESPACE
===================================================================
--- pkg/quantstrat/NAMESPACE	2012-12-18 13:19:40 UTC (rev 1302)
+++ pkg/quantstrat/NAMESPACE	2012-12-18 23:52:12 UTC (rev 1303)
@@ -44,3 +44,4 @@
 export(tradeGraphs)
 export(updateOrders)
 export(updateStrategy)
+export(walk.forward)

Copied: pkg/quantstrat/R/walk.forward.R (from rev 1302, pkg/quantstrat/R/paramsets.R)
===================================================================
--- pkg/quantstrat/R/walk.forward.R	                        (rev 0)
+++ pkg/quantstrat/R/walk.forward.R	2012-12-18 23:52:12 UTC (rev 1303)
@@ -0,0 +1,114 @@
+###############################################################################
+# R (http://r-project.org/) Quantitative Strategy Model Framework
+#
+# Copyright (c) 2009-2012
+# Peter Carl, Dirk Eddelbuettel, Brian G. Peterson, Jeffrey Ryan, and Joshua Ulrich 
+#
+# This library is distributed under the terms of the GNU Public License (GPL)
+# for full details see the file COPYING
+#
+# $Id: parameters.R 1218 2012-10-11 20:47:44Z opentrades $
+#
+###############################################################################
+#
+# Authors: Jan Humme
+#
+###############################################################################
+
+max.Net.Trading.PL <- function(tradeStats.list)
+{
+        which(max(tradeStats.list$Net.Trading.PL) == tradeStats.list$Net.Trading.PL)
+}
+
+### exported functions ############################################################
+
+#' walk.forward
+#' 
+#' walk.forward
+#' 
+#' @param strategy the name of the strategy object
+#' @param paramset.label a label uniquely identifying the paramset within the strategy
+#'
+#' @author Jan Humme
+#' @export
+
+walk.forward <- function(portfolio.st, strategy.st, paramset.label, on, k.training, nsamples=0, k.testing, objective=max.Net.Trading.PL, verbose=FALSE)
+{
+warning('walk.forward() is still under development! expect changes in arguments and results at any time JH')
+
+        must.have.args(match.call(), c('portfolio.st', 'strategy.st', 'paramset.label', 'k.training'))
+
+        strategy <- must.be.strategy(strategy.st)
+        must.be.paramset(strategy, paramset.label)
+
+        portfolio <- getPortfolio(portfolio.st)
+
+        results <- list()
+
+        for(symbol.st in names(portfolio$symbols))
+        {
+                symbol <- get(symbol.st)
+
+                ep <- endpoints(symbol, on)
+
+                k <- 1; while(TRUE)
+                {
+                        result <- list()
+
+                        training.start <- ep[k] + 1
+                        training.end  <- ep[k + k.training]
+
+                        if(is.na(training.end))
+                                break
+
+                        result$training <- list()
+                        result$training$start <- index(symbol[training.start])
+                        result$training$end <- index(symbol[training.end])
+
+                        print(paste('=== training', paramset.label, 'on', paste(result$training$start, result$training$end, sep='/')))
+
+                        result$training$results <- apply.paramset(strategy.st=strategy.st, paramset.label=paramset.label, portfolio.st=portfolio.st, mktdata=symbol[training.start:training.end], nsamples=nsamples, verbose=verbose)
+
+                        if(!missing(k.testing) && k.testing>0)
+                        {
+                                if(!is.function(objective))
+                                        stop(paste(objective, 'unknown objective function', sep=': '))
+
+                                testing.start <- ep[k + k.training] + 1
+                                testing.end   <- ep[k + k.training + k.testing]
+
+                                if(is.na(testing.end))
+                                        break
+
+                                result$testing <- list()
+                                result$testing$start <- index(symbol[testing.start])
+                                result$testing$end <- index(symbol[testing.end])
+
+                                tradeStats.list <- result$training$results$tradeStats
+                                param.combo.nr <- do.call(objective, list('tradeStats.list'=tradeStats.list))
+                                result$testing$param.combo.nr <- param.combo.nr
+
+                                last.param.combo.column.nr <- grep('Portfolio', names(tradeStats.list)) - 1
+                                param.combo <- tradeStats.list[param.combo.nr,1:last.param.combo.column.nr]
+                                result$testing$param.combo <- param.combo
+
+                                strategy <- quantstrat:::install.param.combo(strategy, param.combo, paramset.label)
+                                result$testing$strategy <- param.combo
+
+                                print(paste('--- testing param.combo', param.combo.nr, 'on', paste(result$testing$start, result$testing$end, sep='/')))
+
+#browser()
+                                applyStrategy(strategy, portfolios=portfolio.st, mktdata=symbol[testing.start:testing.end])
+                        }
+                        results[[k]] <- result
+
+                        k <- k + 1
+                }
+        }
+        updatePortf(portfolio.st, Dates=paste('::',as.Date(Sys.time()),sep=''))
+
+        results$portfolio <- portfolio
+        results$tradeStats <- tradeStats(portfolio.st)
+
+        return(results)
+} 

Modified: pkg/quantstrat/man/addOrder.Rd
===================================================================
--- pkg/quantstrat/man/addOrder.Rd	2012-12-18 13:19:40 UTC (rev 1302)
+++ pkg/quantstrat/man/addOrder.Rd	2012-12-18 23:52:12 UTC (rev 1303)
@@ -5,7 +5,7 @@
   addOrder(portfolio, symbol, timestamp, qty, price,
     ordertype, side, threshold = NULL, orderset = "",
     status = "open", statustimestamp = "", prefer = NULL,
-    delay = 1e-05, tmult = FALSE, replace = TRUE,
+    delay = 0.00001, tmult = FALSE, replace = TRUE,
     return = FALSE, ..., TxnFees = 0, label = "")
 }
 \arguments{

Modified: pkg/quantstrat/man/apply.paramset.Rd
===================================================================
--- pkg/quantstrat/man/apply.paramset.Rd	2012-12-18 13:19:40 UTC (rev 1302)
+++ pkg/quantstrat/man/apply.paramset.Rd	2012-12-18 23:52:12 UTC (rev 1303)
@@ -3,7 +3,7 @@
 \title{Apply a paramset to the strategy}
 \usage{
   apply.paramset(strategy.st, paramset.label, portfolio.st,
-    nsamples = 0, verbose = FALSE)
+    mktdata, nsamples = 0, verbose = FALSE)
 }
 \arguments{
   \item{strategy}{the name of the strategy object}

Modified: pkg/quantstrat/man/ruleSignal.Rd
===================================================================
--- pkg/quantstrat/man/ruleSignal.Rd	2012-12-18 13:19:40 UTC (rev 1302)
+++ pkg/quantstrat/man/ruleSignal.Rd	2012-12-18 23:52:12 UTC (rev 1303)
@@ -5,7 +5,7 @@
   ruleSignal(mktdata = mktdata, timestamp, sigcol, sigval,
     orderqty = 0, ordertype, orderside = NULL,
     orderset = NULL, threshold = NULL, tmult = FALSE,
-    replace = TRUE, delay = 1e-04, osFUN = "osNoOp",
+    replace = TRUE, delay = 0.0001, osFUN = "osNoOp",
     pricemethod = c("market", "opside", "active"),
     portfolio, symbol, ..., ruletype, TxnFees = 0,
     prefer = NULL, sethold = FALSE, label = "")



More information about the Blotter-commits mailing list