[Blotter-commits] r1457 - pkg/quantstrat/demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue May 7 22:46:47 CEST 2013
Author: opentrades
Date: 2013-05-07 22:46:47 +0200 (Tue, 07 May 2013)
New Revision: 1457
Added:
pkg/quantstrat/demo/luxor.1.strategy.basic.R
pkg/quantstrat/demo/luxor.2.add.paramsets.R
pkg/quantstrat/demo/luxor.3.paramset.sma.R
pkg/quantstrat/demo/luxor.4.paramset.timespan.R
pkg/quantstrat/demo/luxor.5.strategy.ordersets.R
pkg/quantstrat/demo/luxor.6.paramset.stoploss.R
pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R
pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R
pkg/quantstrat/demo/luxor.7.exit+risk.R
pkg/quantstrat/demo/luxor.getSymbols.R
pkg/quantstrat/demo/luxor.include.R
pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R
pkg/quantstrat/demo/luxor.sample.MAE.stoptrailing.R
pkg/quantstrat/demo/luxor.sample.MFE.takeprofit.R
pkg/quantstrat/demo/luxor.sample.tradeGraphs.sma.R
pkg/quantstrat/demo/luxor.sample.tradeGraphs.timespan.R
Modified:
pkg/quantstrat/demo/00Index
Log:
- updated luxor demos
Modified: pkg/quantstrat/demo/00Index
===================================================================
--- pkg/quantstrat/demo/00Index 2013-05-07 20:45:41 UTC (rev 1456)
+++ pkg/quantstrat/demo/00Index 2013-05-07 20:46:47 UTC (rev 1457)
@@ -8,23 +8,19 @@
bee Milktrader's Bumblebee FastMA/BBands cross system
bbandParameters example of parameter test on bbands demo strategy
macdParameters example of parameter test on macd demo strategy
-luxor.1 Tomasini & Jaekle: Section 3.2: luxor without any optimizations
-luxor.2 Tomasini & Jaekle: Section 3.2: luxor with $30 slippage and transaction costs
-luxor.3 Tomasini & Jaekle: Section 3.3 Variation of the input parameters: optimization and stability diagrams
-luxor.3.Parameters Tomasini & Jaekle: Section 3.3 Variation of the input parameters: optimization and stability diagrams / scan
-luxor.3.Parameters.tradegraphs Tomasini & Jaekle: 3D graphs of results for SMA scan
-luxor.4 Tomasini & Jaekle: Section 3.4: inserting an intraday time filter
-luxor.4.Timespans Tomasini & Jaekle: Section 3.4: inserting an intraday time filter / scan
-luxor.4.Timespans.tradegraphs Tomasini & Jaekle: 3D graphs of results for timespan scan
-luxor.orderchains Tomasini & Jaekle: adding order chain logic conditional on fills
-luxor.Stop
-luxor-3.11
-luxor-3.12
-luxor-3.16
-luxor.3
-luxor.4
-luxor.StopLoss
-luxor.StopTrailing
-luxor.TakeProfit
-luxor.exits
-luxor.strategy
+luxor.1.strategy.basic.R Jaekle & Tomasini; Sections 3.2: basic luxor strategy not using ordersets or orderchains
+luxor.2.add.paramsets.R Jaekle & Tomasini; Sections 3.3: variation of the input parameters
+luxor.3.paramset.sma.R Jaekle & Tomasini; Sections 3.3: variation of the input parameters
+luxor.4.paramset.timespan.R Jaekle & Tomasini; Sections 3.4: inserting an intraday time filter
+luxor.5.strategy.ordersets.R Jaekle & Tomasini; Sections 3.5: strategy implementation using ordersets and orderchains
+luxor.6.paramset.stoploss.R Jaekle & Tomasini; Sections 3.5: paramset implementation for stoploss optimization
+luxor.6.paramset.stoptrailing.R Jaekle & Tomasini; Sections 3.5: paramset implementation for stop trailing optimization
+luxor.6.paramset.takeprofit.R Jaekle & Tomasini; Sections 3.5: paramset implementation for take profit optimization
+luxor.7.exit+risk.R Jaekle & Tomasini; Sections 3.5: running with stoploss and/or stoptrailing and/or takeprofit
+luxor.getSymbols.R Jaekle & Tomasini; reading symbols
+luxor.include.R Jaekle & Tomasini; Sections constants
+luxor.sample.MAE.stoploss.R Jaekle & Tomasini; sample MAE stoploss graph
+luxor.sample.MAE.stoptrailing.R Jaekle & Tomasini; sample MAE stoptrailing graph
+luxor.sample.MFE.takeprofit.R Jaekle & Tomasini; sample MFE take profit graph
+luxor.sample.tradeGraphs.sma.R Jaekle & Tomasini; sample 3D SMA graph
+luxor.sample.tradeGraphs.timespan.R Jaekle & Tomasini; sample 3D timespan graph
Added: pkg/quantstrat/demo/luxor.1.strategy.basic.R
===================================================================
--- pkg/quantstrat/demo/luxor.1.strategy.basic.R (rev 0)
+++ pkg/quantstrat/demo/luxor.1.strategy.basic.R 2013-05-07 20:46:47 UTC (rev 1457)
@@ -0,0 +1,151 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012, revised April 2013
+#
+# Tested and found to work correctly using blotter r1420
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# Paragraph 3.2: luxor with $30 slippage and transaction costs
+
+##### 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()}
+
+source('luxor.include.R')
+.fast = 10
+.slow = 30
+
+source('luxor.getSymbols.R')
+
+### blotter
+
+initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
+initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+
+### quantstrat
+
+initOrders(portfolio.st, initDate=initDate)
+
+### define strategy
+
+strategy(strategy.st, store=TRUE)
+
+### indicators
+
+add.indicator(strategy.st, name = "SMA",
+ arguments = list(
+ x = quote(Cl(mktdata)[,1]),
+ n = .fast
+ ),
+ label="nFast"
+)
+
+add.indicator(strategy.st, name="SMA",
+ arguments = list(
+ x = quote(Cl(mktdata)[,1]),
+ n = .slow
+ ),
+ label="nSlow"
+)
+
+### signals
+
+add.signal(strategy.st, name='sigCrossover',
+ arguments = list(
+ columns=c("nFast","nSlow"),
+ relationship="gte"
+ ),
+ label='long'
+)
+
+add.signal(strategy.st, name='sigCrossover',
+ arguments = list(
+ columns=c("nFast","nSlow"),
+ relationship="lt"
+ ),
+ label='short'
+)
+
+### rules
+
+add.rule(strategy.st, name='ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ orderside='short',
+ ordertype='market',
+ orderqty='all',
+ TxnFees=.txnfees,
+ replace=TRUE
+ ),
+ type='exit',
+ label='Exit2LONG'
+)
+
+add.rule(strategy.st, name='ruleSignal',
+ arguments=list(sigcol='short', sigval=TRUE,
+ orderside='long' ,
+ ordertype='market',
+ orderqty='all',
+ TxnFees=.txnfees,
+ replace=TRUE
+ ),
+ type='exit',
+ label='Exit2SHORT'
+)
+
+add.rule(strategy.st, name='ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ orderside='long' ,
+ ordertype='stoplimit', prefer='High', threshold=.threshold,
+ orderqty=+.orderqty,
+ replace=FALSE
+ ),
+ type='enter',
+ label='EnterLONG'
+)
+
+add.rule(strategy.st, name='ruleSignal',
+ arguments=list(sigcol='short', sigval=TRUE,
+ orderside='short',
+ ordertype='stoplimit', prefer='Low', threshold=-.threshold,
+ orderqty=-.orderqty,
+ replace=FALSE
+ ),
+ type='enter',
+ label='EnterSHORT'
+)
+
+###############################################################################
+
+applyStrategy(strategy.st, portfolio.st)
+
+View(getOrderBook(portfolio.st)[[portfolio.st]]$GBPUSD)
+
+###############################################################################
+
+updatePortf(portfolio.st, Symbols='GBPUSD', Dates=paste('::',as.Date(Sys.time()),sep=''))
+
+chart.Posn(portfolio.st, "GBPUSD")
+
+###############################################################################
+
+View(tradeStats(portfolio.st, 'GBPUSD'))
+
+###############################################################################
+
+# save the strategy in an .RData object for later retrieval
+
+save.strategy(strategy.st)
+
+##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
+# book = getOrderBook(port)
+# stats = tradeStats(port)
+# rets = PortfReturns(acct)
+################################################################
Property changes on: pkg/quantstrat/demo/luxor.1.strategy.basic.R
___________________________________________________________________
Added: svn:executable
+ *
Added: pkg/quantstrat/demo/luxor.2.add.paramsets.R
===================================================================
--- pkg/quantstrat/demo/luxor.2.add.paramsets.R (rev 0)
+++ pkg/quantstrat/demo/luxor.2.add.paramsets.R 2013-05-07 20:46:47 UTC (rev 1457)
@@ -0,0 +1,74 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012, revised April 2013
+#
+# Tested and found to work correctly using blotter r1420
+
+require(quantstrat)
+
+##### 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()}
+
+source('luxor.include.R')
+
+###
+
+strategy.st <- 'luxor'
+
+###
+
+load.strategy(strategy.st)
+
+### SMA paramset
+
+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'
+)
+
+### Timespan paramset
+
+add.distribution(strategy.st,
+ paramset.label = 'Timespan',
+ component.type = 'rule',
+ component.label = 'timespan',
+ variable = list(n = .timespans),
+ label = 'Timespan'
+)
+
+###
+
+save.strategy(strategy.st)
+
+##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
+# book = getOrderBook(port)
+# stats = tradeStats(port)
+# rets = PortfReturns(acct)
+################################################################
Property changes on: pkg/quantstrat/demo/luxor.2.add.paramsets.R
___________________________________________________________________
Added: svn:executable
+ *
Added: pkg/quantstrat/demo/luxor.3.paramset.sma.R
===================================================================
--- pkg/quantstrat/demo/luxor.3.paramset.sma.R (rev 0)
+++ pkg/quantstrat/demo/luxor.3.paramset.sma.R 2013-05-07 20:46:47 UTC (rev 1457)
@@ -0,0 +1,47 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012, revised April 2013
+#
+# Tested and found to work correctly using blotter r1420
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# Paragraph 3.2: luxor with $30 slippage and transaction costs
+
+###
+
+source('luxor.include.R')
+source('luxor.getSymbols.R')
+
+### blotter
+
+initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
+initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+
+### quantstrat
+
+initOrders(portfolio.st, initDate=initDate)
+
+load.strategy(strategy.st)
+
+### doMC
+
+require(doMC)
+registerDoMC(cores=8)
+
+#require(doParallel)
+#registerDoParallel(cores=2)
+
+#require(doRedis)
+#registerDoRedis('jobs')
+
+results <- apply.paramset(strategy.st, paramset.label='SMA', portfolio.st=portfolio.st, account.st=account.st, nsamples=.nsamples, verbose=TRUE)
+
+###
+
+stats <- results$tradeStats
+
+print(stats)
+
+save(stats, file='luxor.3.paramset.SMA.RData')
+
Property changes on: pkg/quantstrat/demo/luxor.3.paramset.sma.R
___________________________________________________________________
Added: svn:executable
+ *
Added: pkg/quantstrat/demo/luxor.4.paramset.timespan.R
===================================================================
--- pkg/quantstrat/demo/luxor.4.paramset.timespan.R (rev 0)
+++ pkg/quantstrat/demo/luxor.4.paramset.timespan.R 2013-05-07 20:46:47 UTC (rev 1457)
@@ -0,0 +1,45 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012, revised April 2013
+#
+# Tested and found to work correctly using blotter r1420
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+
+stop('#### DEMO BROKEN - BEING FIXED ###')
+
+source('luxor.include.R')
+source('luxor.getSymbols.R')
+
+### blotter
+
+initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
+initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+
+### quantstrat
+
+initOrders(portfolio.st, initDate=initDate)
+
+load.strategy(strategy.st)
+
+### doMC
+
+require(doMC)
+registerDoMC(cores=8)
+
+#require(doParallel)
+#registerDoParallel(cores=2)
+
+#require(doRedis)
+#registerDoRedis('jobs')
+
+results <- apply.paramset(strategy.st, paramset.label='Timespan', portfolio.st=portfolio.st, account.st=account.st, nsamples=.nsamples, verbose=TRUE)
+
+###
+
+stats <- results$tradeStats
+
+print(stats)
+
+save(stats, file='luxor.4.paramset.Timespan.RData')
+
Property changes on: pkg/quantstrat/demo/luxor.4.paramset.timespan.R
___________________________________________________________________
Added: svn:executable
+ *
Added: pkg/quantstrat/demo/luxor.5.strategy.ordersets.R
===================================================================
--- pkg/quantstrat/demo/luxor.5.strategy.ordersets.R (rev 0)
+++ pkg/quantstrat/demo/luxor.5.strategy.ordersets.R 2013-05-07 20:46:47 UTC (rev 1457)
@@ -0,0 +1,306 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - May 2013
+#
+# Tested and found to work correctly using blotter r1448
+#
+# After Jaekle & Tomasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# Advanced luxor strategy implementation including exit management using ordersets and orderchains
+
+require(quantstrat)
+
+##### 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()}
+
+source('luxor.include.R')
+
+### define strategy
+
+strategy(strategy.st, store=TRUE)
+
+### indicators
+
+add.indicator(strategy.st, name = "SMA",
+ arguments = list(
+ x = quote(Cl(mktdata)[,1]),
+ n = .fast
+ ),
+ label="nFast"
+)
+
+add.indicator(strategy.st, name="SMA",
+ arguments = list(
+ x = quote(Cl(mktdata)[,1]),
+ n = .slow
+ ),
+ label="nSlow"
+)
+
+### signals
+
+add.signal(strategy.st, name='sigCrossover',
+ arguments = list(
+ columns=c("nFast","nSlow"),
+ relationship="gte"
+ ),
+ label='long'
+)
+
+add.signal(strategy.st, name='sigCrossover',
+ arguments = list(
+ columns=c("nFast","nSlow"),
+ relationship="lt"
+ ),
+ label='short'
+)
+
+### rules ############
+
+# normal exit rules
+
+add.rule(strategy.st, name = 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=TRUE,
+ orderside='short',
+ ordertype='market',
+ TxnFees=.txnfees,
+ orderqty='all',
+ orderset='ocoshort'
+ ),
+ type='exit',
+ timespan = .timespan,
+ label='Exit2LONG'
+)
+
+add.rule(strategy.st, name = 'ruleSignal',
+ arguments=list(sigcol='short', sigval=TRUE,
+ replace=TRUE,
+ orderside='long' ,
+ ordertype='market',
+ TxnFees=.txnfees,
+ orderqty='all',
+ orderset='ocolong'
+ ),
+ type='exit',
+ timespan = .timespan,
+ label='Exit2SHORT'
+)
+
+# normal entry rules
+
+add.rule(strategy.st, name = 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=FALSE,
+ orderside='long' ,
+ ordertype='stoplimit',
+ prefer='High',
+ threshold=.threshold,
+ TxnFees=0,
+ orderqty=+.orderqty,
+ osFUN=osMaxPos,
+ orderset='ocolong'
+ ),
+ type='enter',
+ timespan = .timespan,
+ label='EnterLONG'
+)
+
+add.rule(strategy.st, name = 'ruleSignal',
+ arguments=list(sigcol='short', sigval=TRUE,
+ replace=FALSE,
+ orderside='short',
+ ordertype='stoplimit',
+ prefer='Low',
+ threshold=.threshold,
+ TxnFees=0,
+ orderqty=-.orderqty,
+ osFUN=osMaxPos,
+ orderset='ocoshort'
+ ),
+ type='enter',
+ timespan = .timespan,
+ label='EnterSHORT'
+)
+
+### stoploss, stoptrailing and takeprofit
+
+# stop-loss
+
+add.rule(strategy.st, name = 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=FALSE,
+ orderside='long',
+ ordertype='stoplimit', tmult=TRUE, threshold=quote(.stoploss),
+ TxnFees=.txnfees,
+ orderqty='all',
+ orderset='ocolong'
+ ),
+ type='chain', parent='EnterLONG',
+ label='StopLossLONG',
+ enabled=FALSE
+)
+
+add.rule(strategy.st, name = 'ruleSignal',
+ arguments=list(sigcol='short' , sigval=TRUE,
+ replace=FALSE,
+ orderside='short',
+ ordertype='stoplimit', tmult=TRUE, threshold=quote(.stoploss),
+ TxnFees=.txnfees,
+ orderqty='all',
+ orderset='ocoshort'
+ ),
+ type='chain', parent='EnterSHORT',
+ label='StopLossSHORT',
+ enabled=FALSE
+)
+
+add.distribution(strategy.st,
+ paramset.label = 'StopLoss',
+ component.type = 'chain',
+ component.label = 'StopLossLONG',
+ variable = list(threshold = .StopLoss),
+ label = 'StopLossLONG'
+)
+
+add.distribution(strategy.st,
+ paramset.label = 'StopLoss',
+ component.type = 'chain',
+ component.label = 'StopLossSHORT',
+ variable = list(threshold = .StopLoss),
+ label = 'StopLossSHORT'
+)
+
+add.constraint(strategy.st,
+ paramset.label = 'StopLoss',
+ distribution.label.1 = 'StopLossLONG',
+ distribution.label.2 = 'StopLossSHORT',
+ operator = '==',
+ label = 'StopLoss'
+)
+
+# stop-trailing
+
+add.rule(strategy.st, name = 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=FALSE,
+ orderside='long',
+ ordertype='stoptrailing', tmult=TRUE, threshold=quote(.stoptrailing),
+ TxnFees=.txnfees,
+ orderqty='all',
+ orderset='ocolong'
+ ),
+ type='chain', parent='EnterLONG',
+ label='StopTrailingLONG',
+ enabled=FALSE
+)
+
+add.rule(strategy.st, name = 'ruleSignal',
+ arguments=list(sigcol='short' , sigval=TRUE,
+ replace=FALSE,
+ orderside='short',
+ ordertype='stoptrailing', tmult=TRUE, threshold=quote(.stoptrailing),
+ TxnFees=.txnfees,
+ orderqty='all',
+ orderset='ocoshort'
+ ),
+ type='chain', parent='EnterSHORT',
+ label='StopTrailingSHORT',
+ enabled=FALSE
+)
+
+add.distribution(strategy.st,
+ paramset.label = 'StopTrailing',
+ component.type = 'chain',
+ component.label = 'StopTrailingLONG',
+ variable = list(threshold = .StopTrailing),
+ label = 'StopTrailingLONG'
+)
+
+add.distribution(strategy.st,
+ paramset.label = 'StopTrailing',
+ component.type = 'chain',
+ component.label = 'StopTrailingSHORT',
+ variable = list(threshold = .StopTrailing),
+ label = 'StopTrailingSHORT'
+)
+
+add.constraint(strategy.st,
+ paramset.label = 'StopTrailing',
+ distribution.label.1 = 'StopTrailingLONG',
+ distribution.label.2 = 'StopTrailingSHORT',
+ operator = '==',
+ label = 'StopTrailing'
+)
+
+# take-profit
+
+add.rule(strategy.st, name = 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=FALSE,
+ orderside='long',
+ ordertype='limit', tmult=TRUE, threshold=quote(.takeprofit),
+ TxnFees=.txnfees,
+ orderqty='all',
+ orderset='ocolong'
+ ),
+ type='chain', parent='EnterLONG',
+ label='TakeProfitLONG',
+ enabled=FALSE
+)
+
+add.rule(strategy.st, name = 'ruleSignal',
+ arguments=list(sigcol='short' , sigval=TRUE,
+ replace=FALSE,
+ orderside='short',
+ ordertype='limit', tmult=TRUE, threshold=quote(.takeprofit),
+ TxnFees=.txnfees,
+ orderqty='all',
+ orderset='ocoshort'
+ ),
+ type='chain', parent='EnterSHORT',
+ label='TakeProfitSHORT',
+ enabled=FALSE
+)
+
+add.distribution(strategy.st,
+ paramset.label = 'TakeProfit',
+ component.type = 'chain',
+ component.label = 'TakeProfitLONG',
+ variable = list(threshold = .TakeProfit),
+ label = 'TakeProfitLONG'
+)
+
+add.distribution(strategy.st,
+ paramset.label = 'TakeProfit',
+ component.type = 'chain',
+ component.label = 'TakeProfitSHORT',
+ variable = list(threshold = .TakeProfit),
+ label = 'TakeProfitSHORT'
+)
+
+add.constraint(strategy.st,
+ paramset.label = 'TakeProfit',
+ distribution.label.1 = 'TakeProfitLONG',
+ distribution.label.2 = 'TakeProfitSHORT',
+ operator = '==',
+ label = 'TakeProfit'
+)
+
+###############################################################################
+
+save.strategy(strategy.st)
+
+##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
+# book = getOrderBook(port)
+# stats = tradeStats(port)
+# rets = PortfReturns(acct)
+################################################################
Property changes on: pkg/quantstrat/demo/luxor.5.strategy.ordersets.R
___________________________________________________________________
Added: svn:executable
+ *
Added: pkg/quantstrat/demo/luxor.6.paramset.stoploss.R
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.stoploss.R (rev 0)
+++ pkg/quantstrat/demo/luxor.6.paramset.stoploss.R 2013-05-07 20:46:47 UTC (rev 1457)
@@ -0,0 +1,78 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012
+#
+# Tested and found to work correctly using blotter r1230
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# compute StopLoss percentage for various paramsets
+
+require(quantstrat)
+
+##### 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()}
+
+source('luxor.include.R')
+source('luxor.getSymbols.R')
+
+###
+
+initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
+addPosLimit(
+ portfolio=portfolio.st,
+ symbol='GBPUSD',
+ timestamp=initDate,
+ maxpos=.orderqty)
+
+initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+
+###
+
+initOrders(portfolio.st, initDate=initDate)
+
+load.strategy(strategy.st)
+
+### 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')
+
+### END uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules
+
+require(foreach)
+#registerDoSEQ()
+
+require(doMC)
+registerDoMC(cores=8)
+
+#require(doParallel)
+#registerDoParallel(cores=2)
+
+#require(doRedis)
+#registerDoRedis('jobs')
+
+############################
+
+results <- apply.paramset(strategy.st, paramset.label='StopLoss', portfolio.st=portfolio.st, account.st=account.st, nsamples=80, verbose=TRUE)
+
+stats <- results$tradeStats
+
+print(stats)
+
+plot(100*stats$StopLossLONG, stats$Net.Trading.PL, type='b', xlab='Stoploss %', ylab='Net.Trading.PL', main='Luxor')
+
+##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
+# book = getOrderBook(port)
+# stats = tradeStats(port)
+# rets = PortfReturns(acct)
+################################################################
Added: pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R (rev 0)
+++ pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R 2013-05-07 20:46:47 UTC (rev 1457)
@@ -0,0 +1,78 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012
+#
+# Tested and found to work correctly using blotter r1230
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# compute StopTrailing percentage for various paramsets
+
+require(quantstrat)
+
+##### 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()}
+
+source('luxor.include.R')
+source('luxor.getSymbols.R')
+
+###
+
+initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
+addPosLimit(
+ portfolio=portfolio.st,
+ symbol='GBPUSD',
+ timestamp=initDate,
+ maxpos=.orderqty)
+
+initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+
+###
+
+initOrders(portfolio.st, initDate=initDate)
+
+load.strategy(strategy.st)
+
+### 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')
+
+### END uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules
+
+require(foreach)
+#registerDoSEQ()
+
+require(doMC)
+registerDoMC(cores=2)
+
+#require(doParallel)
+#registerDoParallel(cores=2)
+
+#require(doRedis)
+#registerDoRedis('jobs')
+
+############################
+
+results <- apply.paramset(strategy.st, paramset.label='StopTrailing', portfolio.st=portfolio.st, account.st=account.st, nsamples=80, verbose=TRUE)
+
+stats <- results$tradeStats
+
+print(stats)
+
+plot(100*stats$StopTrailingLONG, stats$Net.Trading.PL, type='b', xlab='StopTrailing %', ylab='Net.Trading.PL', main='Luxor')
+
+##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
+# book = getOrderBook(port)
+# stats = tradeStats(port)
+# rets = PortfReturns(acct)
+################################################################
Added: pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R (rev 0)
+++ pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R 2013-05-07 20:46:47 UTC (rev 1457)
@@ -0,0 +1,78 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012
+#
+# Tested and found to work correctly using blotter r1230
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# compute TakeProfit percentage for various paramsets
+
+require(quantstrat)
+
+##### 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()}
+
+source('luxor.include.R')
+source('luxor.getSymbols.R')
+
+###
+
+initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
+addPosLimit(
+ portfolio=portfolio.st,
+ symbol='GBPUSD',
+ timestamp=initDate,
+ maxpos=.orderqty)
+
+initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+
+###
+
+initOrders(portfolio.st, initDate=initDate)
+
+load.strategy(strategy.st)
+
+### 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')
+
+### END uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules
+
+require(foreach)
+#registerDoSEQ()
+
+require(doMC)
+registerDoMC(cores=8)
+
+#require(doParallel)
+#registerDoParallel(cores=2)
+
+#require(doRedis)
+#registerDoRedis('jobs')
+
+############################
+
+results <- apply.paramset(strategy.st, paramset.label='TakeProfit', portfolio.st=portfolio.st, account.st=account.st, nsamples=80, verbose=TRUE)
+
+stats <- results$tradeStats
+
+print(stats)
+
+plot(100*stats$TakeProfitLONG, stats$Net.Trading.PL, type='b', xlab='TakeProfit %', ylab='Net.Trading.PL', main='Luxor')
+
+##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
+# book = getOrderBook(port)
+# stats = tradeStats(port)
+# rets = PortfReturns(acct)
+################################################################
Added: pkg/quantstrat/demo/luxor.7.exit+risk.R
===================================================================
--- pkg/quantstrat/demo/luxor.7.exit+risk.R (rev 0)
+++ pkg/quantstrat/demo/luxor.7.exit+risk.R 2013-05-07 20:46:47 UTC (rev 1457)
@@ -0,0 +1,80 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - April 2013
+#
+# Tested and found to work correctly using blotter r1420
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# Paragraph 3.5: determination of appropriate exit and risk management
+
+source('luxor.include.R')
+
+##### 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()}
+
+source('luxor.getSymbols.R')
+
+### blotter
+
+initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
+initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+
+### quantstrat
+
+load.strategy('luxor')
+
+### 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')
+
+### END uncomment lines to activate StopLoss and/or StopTrailing and/or TakeProfit rules
+
+addPosLimit(
+ portfolio=portfolio.st,
+ symbol='GBPUSD',
+ timestamp=initDate,
+ maxpos=.orderqty)
+
+initOrders(portfolio.st, initDate=initDate)
+
+applyStrategy(strategy.st, portfolio.st, prefer='Open')
+
+View(getOrderBook(portfolio.st)[[portfolio.st]]$GBPUSD)
+
+###############################################################################
+
+updatePortf(portfolio.st, Symbols='GBPUSD', Dates=paste('::',as.Date(Sys.time()),sep=''))
+
+chart.Posn(portfolio.st, "GBPUSD")
+
+###############################################################################
+
+View(tradeStats(portfolio.st, 'GBPUSD'))
+
+###############################################################################
+
+print(tradeQuantiles('forex', 'GBPUSD'))
+
+dev.new()
+
+### Uncomment to choose appropriate MAE of MFE graph
+
+chart.ME(portfolio.st, 'GBPUSD', scale='percent', type='MAE')
+#chart.ME(portfolio.st, 'GBPUSD', scale='percent', type='MFE')
+
+##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
+# book = getOrderBook(port)
+# stats = tradeStats(port)
+# rets = PortfReturns(acct)
+################################################################
Property changes on: pkg/quantstrat/demo/luxor.7.exit+risk.R
___________________________________________________________________
Added: svn:executable
+ *
Added: pkg/quantstrat/demo/luxor.getSymbols.R
===================================================================
--- pkg/quantstrat/demo/luxor.getSymbols.R (rev 0)
+++ pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-07 20:46:47 UTC (rev 1457)
@@ -0,0 +1,42 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012, revised April 2013
+#
+# Tested and found to work correctly using blotter r1420
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# Paragraph 3.2: luxor with $30 slippage and transaction costs
+
+Sys.setenv(TZ="UTC")
+
+### packages
+#
+# quantstrat package will pull in some other packages:
+# FinancialInstrument, quantmod, blotter, xts
+
+require(quantstrat)
+
+### FinancialInstrument
+
+currency(c('GBP', 'USD'))
+
+exchange_rate('GBPUSD', tick_size=0.0001)
+
+### quantmod
+
+getSymbols.FI(Symbols='GBPUSD',
+# dir=system.file('extdata',package='quantstrat'),
+ dir='~/R/OHLC',
+ from=.from, to=.to
+)
+
+# ALTERNATIVE WAY TO FETCH SYMBOL DATA
+#setSymbolLookup.FI(system.file('extdata',package='quantstrat'), 'GBPUSD')
+#getSymbols('GBPUSD', from=.from, to=.to, verbose=FALSE)
+
+### xts
+
+GBPUSD = to.minutes30(GBPUSD)
+GBPUSD = align.time(to.minutes30(GBPUSD), 1800)
+
Added: pkg/quantstrat/demo/luxor.include.R
===================================================================
--- pkg/quantstrat/demo/luxor.include.R (rev 0)
+++ pkg/quantstrat/demo/luxor.include.R 2013-05-07 20:46:47 UTC (rev 1457)
@@ -0,0 +1,60 @@
+###
+
+options(width = 240)
+Sys.setenv(TZ="UTC")
+
+###
+
+initDate = '2002-10-21'
+
+.from=initDate
+
+.to='2008-07-04'
+#.to='2002-12-31'
+.to='2002-10-31'
+
+###
+
+strategy.st = 'luxor'
+portfolio.st = 'forex'
+account.st = 'IB1'
+
+###
+
+.orderqty = 100000
+.threshold = 0.0005
+.txnfees = -6 # round-trip fee
+
+### Distributions for paramset analysis
+
+.nsamples=80
+
+.FastSMA = (1:20)
+.SlowSMA = (30:80)
+
+.StopLoss = seq(0.02, 0.48, length.out=24)/100
+.StopTrailing = seq(0.05, 0.4, length.out=8)/100
+.TakeProfit = seq(0.1, 1.0, length.out=10)/100
+
+# generate 24x24h ISO8601 timespan vector
+
+.timespans.start<-paste(sprintf("T%02d",0:23),':00',sep='')
+.timespans.stop<-paste(sprintf("T%02d",0:23),':59',sep='')
+
+.timespans<-outer(.timespans.start, .timespans.stop, FUN=paste, sep='/')
+
+# in order to run the full 24x24 hour scan above, comment out the following line:
+.timespans<-c('T06:00/T10:00', 'T07:00/T11:00', 'T08:00/T12:00', 'T09:00/T13:00', 'T10:00/T14:00', 'T11:00/T15:00', 'T12:00/T16:00')
+
+### Actual arameters
+
+.fast = 6
+.slow = 44
+
+#.timespan = 'T08:00/T12:00'
+.timespan = 'T00:00/T23:59'
+
+.stoploss <- 0.0025
+.stoptrailing <- 0.008
+.takeprofit <- 0.019
+
Added: pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R
===================================================================
--- pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R (rev 0)
+++ pkg/quantstrat/demo/luxor.sample.MAE.stoploss.R 2013-05-07 20:46:47 UTC (rev 1457)
@@ -0,0 +1,40 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012
+#
+# Tested and found to work correctly using blotter r1143
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# Figure 3.11: MAE graph of Luxor system
+
+require('blotter')
+
+data('luxor-p066', package='quantstrat', envir=.blotter)
+
+currency(c('GBP', 'USD'))
+exchange_rate(c('GBPUSD'), tick_size=0.0001)
+
+chart.ME(
+ Portfolio='luxor',
+ Symbol='GBPUSD',
+ type='MAE',
+ scale='cash'
+)
+
+##### 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)
+################################################################
Added: pkg/quantstrat/demo/luxor.sample.MAE.stoptrailing.R
===================================================================
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/blotter -r 1457
More information about the Blotter-commits
mailing list