[Blotter-commits] r1464 - in pkg/quantstrat: R data demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed May 8 22:43:14 CEST 2013
Author: opentrades
Date: 2013-05-08 22:43:14 +0200 (Wed, 08 May 2013)
New Revision: 1464
Added:
pkg/quantstrat/data/luxor.wfa.ples.GBPUSD.2003-01-02 05:30:00.2003-03-31 23:30:00.RData
pkg/quantstrat/demo/luxor.sample.walk.forward.R
Modified:
pkg/quantstrat/R/chart.forward.testing.R
pkg/quantstrat/R/chart.forward.training.R
pkg/quantstrat/R/paramsets.R
pkg/quantstrat/demo/luxor.5.strategy.ordersets.R
pkg/quantstrat/demo/luxor.7.exit+risk.R
pkg/quantstrat/demo/luxor.include.R
Log:
- addde WFA paramset to luxor.5 strategy
- added luxor WFA (Walk Forward Analysis) demo
- fixed some small issues with walk forward implementation
- added sample walk forward chart demo
Modified: pkg/quantstrat/R/chart.forward.testing.R
===================================================================
--- pkg/quantstrat/R/chart.forward.testing.R 2013-05-08 17:11:48 UTC (rev 1463)
+++ pkg/quantstrat/R/chart.forward.testing.R 2013-05-08 20:43:14 UTC (rev 1464)
@@ -22,20 +22,24 @@
{
p <- getPortfolio(portfolio.st, envir=.audit)
- R <- cumsum(p$summary['2004-01-01/','Net.Trading.PL'])
+ from <- index(p$summary[2])
+
+ #R <- cumsum(p$summary['2004-01-01/','Net.Trading.PL'])
+ R <- cumsum(p$summary[paste(from, '/', sep=''),'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='.')))
- testing.portfolio.st = 'portfolio.futures'
+ chosen.one <- .audit$param.combo.nr
+ testing.portfolio.st <- ls(env=.audit, pattern=glob2rx(paste('portfolio', '*', chosen.one, sep='.')))
R <- PL.xts[,testing.portfolio.st]
PL.xts <- cbind(PL.xts, R)
+ PL.xts <- na.locf(PL.xts)
+
# add drawdown columns for all portfolio columns
CumMax <- cummax(PL.xts)
Drawdowns.xts <- -(CumMax - PL.xts)
Modified: pkg/quantstrat/R/chart.forward.training.R
===================================================================
--- pkg/quantstrat/R/chart.forward.training.R 2013-05-08 17:11:48 UTC (rev 1463)
+++ pkg/quantstrat/R/chart.forward.training.R 2013-05-08 20:43:14 UTC (rev 1464)
@@ -21,8 +21,11 @@
for(portfolio.st in portfolios.st)
{
p <- getPortfolio(portfolio.st, envir=.audit)
-
- R <- cumsum(p$summary['2004-01-01/','Net.Trading.PL'])
+
+ from <- index(p$summary[2])
+
+ #R <- cumsum(p$summary['2004-01-01/','Net.Trading.PL'])
+ R <- cumsum(p$summary[paste(from, '/', sep=''),'Net.Trading.PL'])
names(R) <- portfolio.st
PL.xts <- cbind(PL.xts, R)
@@ -31,9 +34,12 @@
# 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)
+ PL.xts <- na.locf(PL.xts)
+
# add drawdown columns for all portfolio columns
CumMax <- cummax(PL.xts)
Drawdowns.xts <- -(CumMax - PL.xts)
Modified: pkg/quantstrat/R/paramsets.R
===================================================================
--- pkg/quantstrat/R/paramsets.R 2013-05-08 17:11:48 UTC (rev 1463)
+++ pkg/quantstrat/R/paramsets.R 2013-05-08 20:43:14 UTC (rev 1464)
@@ -216,7 +216,7 @@
#'
#' @author Jan Humme
#' @export
-#' @seealso \code{\link{add.constraint}}, \code{\link{add.constraint}}, \code{\link{apply.paramset}}
+#' @seealso \code{\link{add.distibution}}, \code{\link{add.constraint}}, \code{\link{apply.paramset}}
delete.paramset <- function(strategy, paramset.label, store=TRUE)
{
Added: pkg/quantstrat/data/luxor.wfa.ples.GBPUSD.2003-01-02 05:30:00.2003-03-31 23:30:00.RData
===================================================================
(Binary files differ)
Property changes on: pkg/quantstrat/data/luxor.wfa.ples.GBPUSD.2003-01-02 05:30:00.2003-03-31 23:30:00.RData
___________________________________________________________________
Added: svn:mime-type
+ application/x-gzip
Modified: pkg/quantstrat/demo/luxor.5.strategy.ordersets.R
===================================================================
--- pkg/quantstrat/demo/luxor.5.strategy.ordersets.R 2013-05-08 17:11:48 UTC (rev 1463)
+++ pkg/quantstrat/demo/luxor.5.strategy.ordersets.R 2013-05-08 20:43:14 UTC (rev 1464)
@@ -131,8 +131,34 @@
label='EnterSHORT'
)
-### stoploss, stoptrailing and takeprofit
+### parameter sets
+# SMA
+
+add.distribution(strategy.st,
+ paramset.label = 'SMA',
+ component.type = 'indicator',
+ component.label = 'nFast',
+ variable = list(n = .FastSMA),
+ label = 'nFAST'
+)
+
+add.distribution(strategy.st,
+ paramset.label = 'SMA',
+ component.type = 'indicator',
+ component.label = 'nSlow',
+ variable = list(n = .SlowSMA),
+ label = 'nSLOW'
+)
+
+add.constraint(strategy.st,
+ paramset.label = 'SMA',
+ distribution.label.1 = 'nFAST',
+ distribution.label.2 = 'nSLOW',
+ operator = '<',
+ label = 'SMA'
+)
+
# stop-loss
add.rule(strategy.st, name = 'ruleSignal',
@@ -295,6 +321,32 @@
label = 'TakeProfit'
)
+# Walk Forward Analysis
+
+add.distribution(strategy.st,
+ paramset.label = 'WFA',
+ component.type = 'indicator',
+ component.label = 'nFast',
+ variable = list(n = .FastWFA),
+ label = 'nFAST'
+)
+
+add.distribution(strategy.st,
+ paramset.label = 'WFA',
+ component.type = 'indicator',
+ component.label = 'nSlow',
+ variable = list(n = .SlowWFA),
+ label = 'nSLOW'
+)
+
+add.constraint(strategy.st,
+ paramset.label = 'WFA',
+ distribution.label.1 = 'nFAST',
+ distribution.label.2 = 'nSLOW',
+ operator = '<',
+ label = 'WFA'
+)
+
###############################################################################
save.strategy(strategy.st)
Modified: pkg/quantstrat/demo/luxor.7.exit+risk.R
===================================================================
--- pkg/quantstrat/demo/luxor.7.exit+risk.R 2013-05-08 17:11:48 UTC (rev 1463)
+++ pkg/quantstrat/demo/luxor.7.exit+risk.R 2013-05-08 20:43:14 UTC (rev 1464)
@@ -35,8 +35,8 @@
### BEGIN uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules
enable.rule('luxor', 'chain', 'StopLoss')
-enable.rule('luxor', 'chain', 'StopTrailing')
-enable.rule('luxor', 'chain', 'TakeProfit')
+#enable.rule('luxor', 'chain', 'StopTrailing')
+#enable.rule('luxor', 'chain', 'TakeProfit')
### END uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules
Modified: pkg/quantstrat/demo/luxor.include.R
===================================================================
--- pkg/quantstrat/demo/luxor.include.R 2013-05-08 17:11:48 UTC (rev 1463)
+++ pkg/quantstrat/demo/luxor.include.R 2013-05-08 20:43:14 UTC (rev 1464)
@@ -1,16 +1,20 @@
###
options(width = 240)
+#options(warn=1)
+
Sys.setenv(TZ="UTC")
###
initDate = '2002-10-21'
+#initDate = '2003-01-01'
.from=initDate
-.to='2008-07-04'
+#.to='2008-07-04'
.to='2002-10-31'
+#.to='2003-07-31'
###
@@ -31,10 +35,15 @@
.FastSMA = (1:20)
.SlowSMA = (30:80)
-.StopLoss = seq(0.02, 0.48, length.out=24)/100
+#.StopLoss = seq(0.02, 0.48, length.out=24)/100
+#.StopLoss = seq(0.01, 0.24, length.out=24)/100
+.StopLoss = seq(0.002, 0.048, length.out=24)/100
.StopTrailing = seq(0.05, 0.4, length.out=8)/100
.TakeProfit = seq(0.1, 1.0, length.out=10)/100
+.FastWFA = c(1, 3, 5, 7, 9)
+.SlowWFA = c(42, 44, 46)
+
# generate 24x24h ISO8601 timespan vector
.timespans.start<-paste(sprintf("T%02d",0:23),':00',sep='')
Added: pkg/quantstrat/demo/luxor.sample.walk.forward.R
===================================================================
--- pkg/quantstrat/demo/luxor.sample.walk.forward.R (rev 0)
+++ pkg/quantstrat/demo/luxor.sample.walk.forward.R 2013-05-08 20:43:14 UTC (rev 1464)
@@ -0,0 +1,30 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012
+#
+# Tested and found to work correctly using blotter r1457
+#
+# After Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# Walk forward chart sample
+
+require('quantstrat')
+
+chart.forward.testing('../data/luxor.wfa.ples.GBPUSD.2003-01-02 05:30:00.2003-03-31 23:30:00.RData')
+
+##### PLACE DEMO AND TEST DATES HERE #################
+#
+#if(isTRUE(options('in_test')$in_test))
+# # use test dates
+# {initDate="2011-01-01"
+# endDate="2012-12-31"
+# } else
+# # use demo defaults
+# {initDate="1999-12-31"
+# endDate=Sys.Date()}
+
+##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
+# book = getOrderBook(port)
+# stats = tradeStats(port)
+# rets = PortfReturns(acct)
+################################################################
More information about the Blotter-commits
mailing list