[Blotter-commits] r1124 - in pkg/quantstrat: data demo demo/luxor
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Aug 8 14:07:15 CEST 2012
Author: opentrades
Date: 2012-08-08 14:07:15 +0200 (Wed, 08 Aug 2012)
New Revision: 1124
Added:
pkg/quantstrat/data/luxor.parameters.1-10.30-55.RData
pkg/quantstrat/data/luxor.timespan.24x24.2002-2008.RData
pkg/quantstrat/demo/Rplots.pdf
pkg/quantstrat/demo/luxor/
pkg/quantstrat/demo/luxor/luxor.1.R
pkg/quantstrat/demo/luxor/luxor.2.R
pkg/quantstrat/demo/luxor/luxor.3.Parameters.R
pkg/quantstrat/demo/luxor/luxor.3.R
pkg/quantstrat/demo/luxor/luxor.4.R
pkg/quantstrat/demo/luxor/luxor.4.Timespans.R
pkg/quantstrat/demo/luxor/luxorParameterTradeGraphs.R
pkg/quantstrat/demo/luxor/luxorTimespanTradeGraphs.R
Removed:
pkg/quantstrat/data/luxor.250.RData
pkg/quantstrat/demo/luxor.R
pkg/quantstrat/demo/luxorParameters.R
pkg/quantstrat/demo/tradeGraphs.R
Modified:
pkg/quantstrat/demo/00Index
Log:
reworked luxor demos, put them in separate subdir, added timespan analysis, included some scan result object in data dir
Deleted: pkg/quantstrat/data/luxor.250.RData
===================================================================
(Binary files differ)
Copied: pkg/quantstrat/data/luxor.parameters.1-10.30-55.RData (from rev 1123, pkg/quantstrat/data/luxor.250.RData)
===================================================================
(Binary files differ)
Added: pkg/quantstrat/data/luxor.timespan.24x24.2002-2008.RData
===================================================================
(Binary files differ)
Property changes on: pkg/quantstrat/data/luxor.timespan.24x24.2002-2008.RData
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: pkg/quantstrat/demo/00Index
===================================================================
--- pkg/quantstrat/demo/00Index 2012-08-08 11:10:03 UTC (rev 1123)
+++ pkg/quantstrat/demo/00Index 2012-08-08 12:07:15 UTC (rev 1124)
@@ -7,3 +7,4 @@
rsi Relative Strength Index (RSI) strategy demonstrating long-only threshold actions
bbandParameters example of parameter test on bbands demo strategy
macdParameters example of parameter test on macd demo strategy
+luxor subdirectory - several demos using R to implement and analyze luxor strategy from the Jaekle&Tomasini book
Added: pkg/quantstrat/demo/Rplots.pdf
===================================================================
(Binary files differ)
Property changes on: pkg/quantstrat/demo/Rplots.pdf
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: pkg/quantstrat/demo/luxor/luxor.1.R
===================================================================
--- pkg/quantstrat/demo/luxor/luxor.1.R (rev 0)
+++ pkg/quantstrat/demo/luxor/luxor.1.R 2012-08-08 12:07:15 UTC (rev 1124)
@@ -0,0 +1,177 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012
+#
+# Tested and found to work correctly using blotter r1123
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# Paragraph 3.2: luxor without any optimizations
+
+options(width = 240)
+#Sys.setenv(TZ="GMT")
+
+.fast = 10
+.slow = 30
+
+.qty=100000
+.th=0.0005
+.txn=0
+
+initDate = '2002-10-21'
+.from='2002-10-21'
+#.to='2008-07-04'
+#.to='2003-12-31'
+.to='2002-10-31'
+
+####
+
+s = 'luxor'
+p = 'forex'
+a = 'IB1'
+
+###
+
+require(quantstrat)
+
+currency(c('GBP', 'USD'))
+
+exchange_rate(c('GBPUSD'), tick_size=0.0001)
+
+#setSymbolLookup.FI('~/R.symbols/', 'GBPUSD')
+setSymbolLookup.FI('../../data/', 'GBPUSD')
+
+###
+
+getSymbols('GBPUSD', from=.from, to=.to, verbose=FALSE)
+GBPUSD = to.minutes30(GBPUSD)
+GBPUSD = align.time(to.minutes30(GBPUSD), 1800)
+
+###
+
+initPortf(p, symbols='GBPUSD', initDate=initDate, currency='USD')
+initAcct(a, portfolios=p, initDate=initDate, currency='USD')
+
+###
+
+initOrders(p, initDate=initDate)
+
+### strategy ######################################################################
+
+strategy(s, store=TRUE)
+
+### indicators
+
+add.indicator(s, name = "SMA",
+ arguments = list(
+ x = quote(Cl(mktdata)),
+ n = .fast
+ ),
+ label="nFast"
+)
+
+add.indicator(s, name="SMA",
+ arguments = list(
+ x = quote(Cl(mktdata)),
+ n = .slow
+ ),
+ label="nSlow"
+)
+
+### signals
+
+add.signal(s, 'sigCrossover',
+ arguments = list(
+ columns=c("nFast","nSlow"),
+ relationship="gte"
+ ),
+ label='long'
+)
+
+add.signal(s, 'sigCrossover',
+ arguments = list(
+ columns=c("nFast","nSlow"),
+ relationship="lt"
+ ),
+ label='short'
+)
+
+### rules
+
+add.rule(s, 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=TRUE,
+ orderside='short',
+ ordertype='market',
+ TxnFees=.txn,
+ orderqty='all',
+ orderset='ocoshort'
+ ),
+ type='exit',
+ label='Exit2LONG'
+)
+
+add.rule(s, 'ruleSignal',
+ arguments=list(sigcol='short', sigval=TRUE,
+ replace=TRUE,
+ orderside='long' ,
+ ordertype='market',
+ TxnFees=.txn,
+ orderqty='all',
+ orderset='ocolong'
+ ),
+ type='exit',
+ label='Exit2SHORT')
+
+add.rule(s, 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=FALSE,
+ orderside='long' ,
+ ordertype='stoplimit',
+ prefer='High',
+ threshold=.th,
+ TxnFees=0,
+ orderqty=+.qty,
+ orderset='ocolong'
+ ),
+ type='enter',
+ label='EnterLONG'
+)
+
+add.rule(s, 'ruleSignal',
+ arguments=list(sigcol='short', sigval=TRUE,
+ replace=FALSE,
+ orderside='short',
+ ordertype='stoplimit',
+ prefer='Low',
+ threshold=-.th,
+ TxnFees=0,
+ orderqty=-.qty,
+ orderset='ocoshort'
+ ),
+ type='enter',
+ label='EnterSHORT'
+)
+
+#
+
+###############################################################################
+
+applyStrategy(s, p, verbose = FALSE)
+#applyStrategy(s, p, prefer='Open', verbose = FALSE)
+
+updatePortf(p, Symbols='GBPUSD', ,Dates=paste('::',as.Date(Sys.time()),sep=''))
+
+###############################################################################
+
+chart.Posn(p, "GBPUSD")
+
+print(getOrderBook(p))
+
+#txns <- getTxns(p, 'GBPUSD')
+#txns
+###txns$Net
+#cat('Net profit:', sum(txns$Net.Txn.Realized.PL), '\n')
+
+tradeStats(p, 'GBPUSD')
+
Property changes on: pkg/quantstrat/demo/luxor/luxor.1.R
___________________________________________________________________
Added: svn:executable
+ *
Added: pkg/quantstrat/demo/luxor/luxor.2.R
===================================================================
--- pkg/quantstrat/demo/luxor/luxor.2.R (rev 0)
+++ pkg/quantstrat/demo/luxor/luxor.2.R 2012-08-08 12:07:15 UTC (rev 1124)
@@ -0,0 +1,177 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012
+#
+# Tested and found to work correctly using blotter r1123
+#
+# 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
+
+options(width = 240)
+#Sys.setenv(TZ="GMT")
+
+.fast = 10
+.slow = 30
+
+.qty=100000
+.th=0.0005
+.txn=-30
+
+initDate = '2002-10-21'
+.from='2002-10-21'
+#.to='2008-07-04'
+#.to='2003-12-31'
+.to='2002-10-31'
+
+####
+
+s = 'luxor'
+p = 'forex'
+a = 'IB1'
+
+###
+
+require(quantstrat)
+
+currency(c('GBP', 'USD'))
+
+exchange_rate(c('GBPUSD'), tick_size=0.0001)
+
+#setSymbolLookup.FI('~/R.symbols/', 'GBPUSD')
+setSymbolLookup.FI('../../data/', 'GBPUSD')
+
+###
+
+getSymbols('GBPUSD', from=.from, to=.to, verbose=FALSE)
+GBPUSD = to.minutes30(GBPUSD)
+GBPUSD = align.time(to.minutes30(GBPUSD), 1800)
+
+###
+
+initPortf(p, symbols='GBPUSD', initDate=initDate, currency='USD')
+initAcct(a, portfolios=p, initDate=initDate, currency='USD')
+
+###
+
+initOrders(p, initDate=initDate)
+
+### strategy ######################################################################
+
+strategy(s, store=TRUE)
+
+### indicators
+
+add.indicator(s, name = "SMA",
+ arguments = list(
+ x = quote(Cl(mktdata)),
+ n = .fast
+ ),
+ label="nFast"
+)
+
+add.indicator(s, name="SMA",
+ arguments = list(
+ x = quote(Cl(mktdata)),
+ n = .slow
+ ),
+ label="nSlow"
+)
+
+### signals
+
+add.signal(s, 'sigCrossover',
+ arguments = list(
+ columns=c("nFast","nSlow"),
+ relationship="gte"
+ ),
+ label='long'
+)
+
+add.signal(s, 'sigCrossover',
+ arguments = list(
+ columns=c("nFast","nSlow"),
+ relationship="lt"
+ ),
+ label='short'
+)
+
+### rules
+
+add.rule(s, 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=TRUE,
+ orderside='short',
+ ordertype='market',
+ TxnFees=.txn,
+ orderqty='all',
+ orderset='ocoshort'
+ ),
+ type='exit',
+ label='Exit2LONG'
+)
+
+add.rule(s, 'ruleSignal',
+ arguments=list(sigcol='short', sigval=TRUE,
+ replace=TRUE,
+ orderside='long' ,
+ ordertype='market',
+ TxnFees=.txn,
+ orderqty='all',
+ orderset='ocolong'
+ ),
+ type='exit',
+ label='Exit2SHORT')
+
+add.rule(s, 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=FALSE,
+ orderside='long' ,
+ ordertype='stoplimit',
+ prefer='High',
+ threshold=.th,
+ TxnFees=0,
+ orderqty=+.qty,
+ orderset='ocolong'
+ ),
+ type='enter',
+ label='EnterLONG'
+)
+
+add.rule(s, 'ruleSignal',
+ arguments=list(sigcol='short', sigval=TRUE,
+ replace=FALSE,
+ orderside='short',
+ ordertype='stoplimit',
+ prefer='Low',
+ threshold=-.th,
+ TxnFees=0,
+ orderqty=-.qty,
+ orderset='ocoshort'
+ ),
+ type='enter',
+ label='EnterSHORT'
+)
+
+#
+
+###############################################################################
+
+applyStrategy(s, p, verbose = FALSE)
+#applyStrategy(s, p, prefer='Open', verbose = FALSE)
+
+updatePortf(p, Symbols='GBPUSD', ,Dates=paste('::',as.Date(Sys.time()),sep=''))
+
+###############################################################################
+
+chart.Posn(p, "GBPUSD")
+
+print(getOrderBook(p))
+
+#txns <- getTxns(p, 'GBPUSD')
+#txns
+###txns$Net
+#cat('Net profit:', sum(txns$Net.Txn.Realized.PL), '\n')
+
+tradeStats(p, 'GBPUSD')
+
Property changes on: pkg/quantstrat/demo/luxor/luxor.2.R
___________________________________________________________________
Added: svn:executable
+ *
Copied: pkg/quantstrat/demo/luxor/luxor.3.Parameters.R (from rev 1123, pkg/quantstrat/demo/luxorParameters.R)
===================================================================
--- pkg/quantstrat/demo/luxor/luxor.3.Parameters.R (rev 0)
+++ pkg/quantstrat/demo/luxor/luxor.3.Parameters.R 2012-08-08 12:07:15 UTC (rev 1124)
@@ -0,0 +1,80 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012
+#
+# Tested and found to work correctly using blotter r1123
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# Paragraph 3.3 Variation of the input parameters: optimisation and stability diagrams
+# uses luxor.3.R
+
+#verbose = 0
+verbose = 1
+
+method='expand'
+#method='random'
+#.sampleSize=20
+
+#.fastRange=(1:20)
+#.slowRange=(21:80)
+
+.fastRange=(1:5)
+.slowRange=(41:45)
+
+###############################################################################
+
+#require(foreach,quietly=TRUE)
+require(doMC)
+require(quantstrat)
+
+portfolio.st = 'forex'
+
+source('luxor.3.R')
+
+s<-getStrategy('luxor')
+
+parameterTable<-getParameterTable(s)
+#parameterTable
+
+tPD2<-setParameterDistribution(type = 'indicator', indexnum = 1, distribution = list(nFast = .fastRange), label = 'nFast')
+tPD2<-setParameterDistribution(tPD2, type = 'indicator', indexnum = 2, distribution = list(nSlow = .slowRange), label = 'nSlow')
+
+pConstraint2<-setParameterConstraint(constraintLabel='luxorPC',paramList=c('nFast','nSlow'),relationship='lt')
+
+registerDoMC(cores=2)
+
+if(method == 'random')
+{
+ laststpar.rnd<-system.time(
+ scan.results<-applyParameter(
+ strategy=s,
+ portfolios=portfolio.st,
+ parameterPool=tPD2,
+ method='random',
+ sampleSize=.sampleSize,
+ parameterConstraints=pConstraint2
+ )
+ )
+ if(verbose >=1) laststpar.rnd
+}
+
+if(method == 'expand')
+{
+ laststpar.exp<-system.time(
+ scan.results<-applyParameter(
+ strategy=s,
+ portfolios=portfolio.st,
+ parameterPool=tPD2,
+ method='expand',
+ parameterConstraints=pConstraint2
+ )
+ )
+ if(verbose >=1) print(laststpar.exp)
+}
+
+#examine the stats from this parameter run:
+if(verbose >=1) print(scan.results$statsTable)
+
+stats <- scan.results$statsTable
+save(stats, file="luxor.parameters.RData")
Added: pkg/quantstrat/demo/luxor/luxor.3.R
===================================================================
--- pkg/quantstrat/demo/luxor/luxor.3.R (rev 0)
+++ pkg/quantstrat/demo/luxor/luxor.3.R 2012-08-08 12:07:15 UTC (rev 1124)
@@ -0,0 +1,178 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012
+#
+# Tested and found to work correctly using blotter r1123
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# Paragraph 3.3 Variation of the input parameters: optimisation and stability diagrams
+
+options(width = 240)
+#Sys.setenv(TZ="GMT")
+
+.fast = 1
+.slow = 44
+
+.qty=100000
+.th=0.0005
+.txn=-30
+
+initDate = '2002-10-21'
+.from='2002-10-21'
+#.to='2008-07-04'
+#.to='2003-12-31'
+.to='2002-10-31'
+#.to='2002-12-31'
+
+####
+
+s = 'luxor'
+p = 'forex'
+a = 'IB1'
+
+###
+
+require(quantstrat)
+
+currency(c('GBP', 'USD'))
+
+exchange_rate(c('GBPUSD'), tick_size=0.0001)
+
+#setSymbolLookup.FI('~/R.symbols/', 'GBPUSD')
+setSymbolLookup.FI('../../data/', 'GBPUSD')
+
+###
+
+getSymbols('GBPUSD', from=.from, to=.to, verbose=FALSE)
+GBPUSD = to.minutes30(GBPUSD)
+GBPUSD = align.time(to.minutes30(GBPUSD), 1800)
+
+###
+
+initPortf(p, symbols='GBPUSD', initDate=initDate, currency='USD')
+initAcct(a, portfolios=p, initDate=initDate, currency='USD')
+
+###
+
+initOrders(p, initDate=initDate)
+
+### strategy ######################################################################
+
+strategy(s, store=TRUE)
+
+### indicators
+
+add.indicator(s, name = "SMA",
+ arguments = list(
+ x = quote(Cl(mktdata)),
+ n = .fast
+ ),
+ label="nFast"
+)
+
+add.indicator(s, name="SMA",
+ arguments = list(
+ x = quote(Cl(mktdata)),
+ n = .slow
+ ),
+ label="nSlow"
+)
+
+### signals
+
+add.signal(s, 'sigCrossover',
+ arguments = list(
+ columns=c("nFast","nSlow"),
+ relationship="gte"
+ ),
+ label='long'
+)
+
+add.signal(s, 'sigCrossover',
+ arguments = list(
+ columns=c("nFast","nSlow"),
+ relationship="lt"
+ ),
+ label='short'
+)
+
+### rules
+
+add.rule(s, 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=TRUE,
+ orderside='short',
+ ordertype='market',
+ TxnFees=.txn,
+ orderqty='all',
+ orderset='ocoshort'
+ ),
+ type='exit',
+ label='Exit2LONG'
+)
+
+add.rule(s, 'ruleSignal',
+ arguments=list(sigcol='short', sigval=TRUE,
+ replace=TRUE,
+ orderside='long' ,
+ ordertype='market',
+ TxnFees=.txn,
+ orderqty='all',
+ orderset='ocolong'
+ ),
+ type='exit',
+ label='Exit2SHORT')
+
+add.rule(s, 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=FALSE,
+ orderside='long' ,
+ ordertype='stoplimit',
+ prefer='High',
+ threshold=.th,
+ TxnFees=0,
+ orderqty=+.qty,
+ orderset='ocolong'
+ ),
+ type='enter',
+ label='EnterLONG'
+)
+
+add.rule(s, 'ruleSignal',
+ arguments=list(sigcol='short', sigval=TRUE,
+ replace=FALSE,
+ orderside='short',
+ ordertype='stoplimit',
+ prefer='Low',
+ threshold=-.th,
+ TxnFees=0,
+ orderqty=-.qty,
+ orderset='ocoshort'
+ ),
+ type='enter',
+ label='EnterSHORT'
+)
+
+#
+
+###############################################################################
+
+applyStrategy(s, p, verbose = FALSE)
+#applyStrategy(s, p, prefer='Open', verbose = FALSE)
+
+updatePortf(p, Symbols='GBPUSD', ,Dates=paste('::',as.Date(Sys.time()),sep=''))
+
+###############################################################################
+
+chart.Posn(p, "GBPUSD")
+
+print(getOrderBook(p))
+
+#txns <- getTxns(p, 'GBPUSD')
+#txns
+###txns$Net
+#cat('Net profit:', sum(txns$Net.Txn.Realized.PL), '\n')
+
+tradeStats(p, 'GBPUSD')
+
Property changes on: pkg/quantstrat/demo/luxor/luxor.3.R
___________________________________________________________________
Added: svn:executable
+ *
Added: pkg/quantstrat/demo/luxor/luxor.4.R
===================================================================
--- pkg/quantstrat/demo/luxor/luxor.4.R (rev 0)
+++ pkg/quantstrat/demo/luxor/luxor.4.R 2012-08-08 12:07:15 UTC (rev 1124)
@@ -0,0 +1,195 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012
+#
+# Tested and found to work correctly using blotter r1123
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# Paragraph 3.4: inserting an intraday time filter
+
+options(width = 240)
+#Sys.setenv(TZ="GMT")
+
+.fast = 1
+.slow = 44
+
+.qty=100000
+.th=0.0005
+.txn=-30
+.timespan = 'T08:00/T12:00'
+
+initDate = '2002-10-21'
+.from='2002-10-21'
+#.to='2008-07-04'
+#.to='2003-12-31'
+.to='2002-10-31'
+#.to='2002-12-31'
+#.from='2006-01-01'
+#.to='2006-12-31'
+#.from='2007-01-01'
+#.to='2007-12-31'
+
+####
+
+s = 'luxor'
+p = 'forex'
+a = 'IB1'
+
+###
+
+require(quantstrat)
+
+currency(c('GBP', 'USD'))
+
+exchange_rate(c('GBPUSD'), tick_size=0.0001)
+
+#setSymbolLookup.FI('~/R.symbols/', 'GBPUSD')
+setSymbolLookup.FI('../../data/', 'GBPUSD')
+
+###
+
+getSymbols('GBPUSD', from=.from, to=.to, verbose=FALSE)
+GBPUSD = to.minutes30(GBPUSD)
+GBPUSD = align.time(to.minutes30(GBPUSD), 1800)
+
+###
+
+initPortf(p, symbols='GBPUSD', initDate=initDate, currency='USD')
+initAcct(a, portfolios=p, initDate=initDate, currency='USD')
+
+###
+
+initOrders(p, initDate=initDate)
+
+### strategy ######################################################################
+
+addPosLimit(
+ portfolio=p,
+ symbol='GBPUSD',
+ timestamp=initDate,
+ maxpos=.qty)
+
+strategy(s, store=TRUE)
+
+### indicators
+
+add.indicator(s, name = "SMA",
+ arguments = list(
+ x = quote(Cl(mktdata)),
+ n = .fast
+ ),
+ label="nFast"
+)
+
+add.indicator(s, name="SMA",
+ arguments = list(
+ x = quote(Cl(mktdata)),
+ n = .slow
+ ),
+ label="nSlow"
+)
+
+### signals
+
+add.signal(s, name = 'sigCrossover',
+ arguments = list(
+ columns=c("nFast","nSlow"),
+ relationship="gte"
+ ),
+ label='long'
+)
+
+add.signal(s, name = 'sigCrossover',
+ arguments = list(
+ columns=c("nFast","nSlow"),
+ relationship="lt"
+ ),
+ label='short'
+)
+
+### rules
+
+add.rule(s, name = 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=TRUE,
+ orderside='short',
+ ordertype='market',
+ TxnFees=.txn,
+ orderqty='all',
+ orderset='ocoshort'
+ ),
+ type='exit',
+ timespan = .timespan,
+ label='Exit2LONG'
+)
+
+add.rule(s, name = 'ruleSignal',
+ arguments=list(sigcol='short', sigval=TRUE,
+ replace=TRUE,
+ orderside='long' ,
+ ordertype='market',
+ TxnFees=.txn,
+ orderqty='all',
+ orderset='ocolong'
+ ),
+ type='exit',
+ timespan = .timespan,
+ label='Exit2SHORT')
+
+add.rule(s, name = 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=FALSE,
+ orderside='long' ,
+ ordertype='stoplimit',
+ prefer='High',
+ threshold=.th,
+ TxnFees=0,
+ orderqty=+.qty,
+ osFUN=osMaxPos,
+ orderset='ocolong'
+ ),
+ type='enter',
+ timespan = .timespan,
+ label='EnterLONG'
+)
+
+add.rule(s, name = 'ruleSignal',
+ arguments=list(sigcol='short', sigval=TRUE,
+ replace=FALSE,
+ orderside='short',
+ ordertype='stoplimit',
+ prefer='Low',
+ threshold=-.th,
+ TxnFees=0,
+ orderqty=-.qty,
+ osFUN=osMaxPos,
+ orderset='ocoshort'
+ ),
+ type='enter',
+ timespan = .timespan,
+ label='EnterSHORT'
+)
+
+#
+
+###############################################################################
+
+applyStrategy(s, p, verbose = FALSE)
+#applyStrategy(s, p, prefer='Open', verbose = FALSE)
+
+updatePortf(p, Symbols='GBPUSD', ,Dates=paste('::',as.Date(Sys.time()),sep=''))
+
+###############################################################################
+
+chart.Posn(p, "GBPUSD")
+
+print(getOrderBook(p))
+
+#txns <- getTxns(p, 'GBPUSD')
+#txns
+##txns$Net
+#cat('Net profit:', sum(txns$Net.Txn.Realized.PL), '\n')
+
+print(tradeStats(p, 'GBPUSD'))
+
Property changes on: pkg/quantstrat/demo/luxor/luxor.4.R
___________________________________________________________________
Added: svn:executable
+ *
Added: pkg/quantstrat/demo/luxor/luxor.4.Timespans.R
===================================================================
--- pkg/quantstrat/demo/luxor/luxor.4.Timespans.R (rev 0)
+++ pkg/quantstrat/demo/luxor/luxor.4.Timespans.R 2012-08-08 12:07:15 UTC (rev 1124)
@@ -0,0 +1,79 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012
+#
+# Tested and found to work correctly using blotter r1123
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# Paragraph 3.4: inserting an intraday time filter
+# uses luxor.4.R
+
+source('luxor.4.R')
+
+#verbose = 0
+verbose = 1
+
+method='expand'
+#method='random'
+#.sampleSize=20
+
+# 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')
+
+###############################################################################
+
+require(doMC)
+require(quantstrat)
+
+portfolio.st = 'forex'
+
+s<-getStrategy('luxor')
+
+parameterTable<-getParameterTable(s)
+
+tPD2<-setParameterDistribution(type = 'enter', indexnum = 1, distribution = list(timespan = .timespans), label = 'Timespan')
+
+registerDoMC(cores=2)
+
+if(method == 'random')
+{
+ laststpar.rnd<-system.time(
+ scan.results<-applyParameter(
+ strategy=s,
+ portfolios=portfolio.st,
+ parameterPool=tPD2,
+ method='random',
+ sampleSize=.sampleSize,
+ parameterConstraints=NULL
+ )
+ )
+ if(verbose >=1) laststpar.rnd
+}
+
+if(method == 'expand')
+{
+ laststpar.exp<-system.time(
+ scan.results<-applyParameter(
+ strategy=s,
+ portfolios=portfolio.st,
+ parameterPool=tPD2,
+ method='expand',
+ parameterConstraints=NULL
+ )
+ )
+ if(verbose >=1) print(laststpar.exp)
+}
+
+#examine the stats from this parameter run:
+if(verbose >=1) print(scan.results$statsTable)
+
+stats <- scan.results$statsTable
+save(stats, file="luxor.timespan.RData")
Property changes on: pkg/quantstrat/demo/luxor/luxor.4.Timespans.R
___________________________________________________________________
Added: svn:executable
+ *
Copied: pkg/quantstrat/demo/luxor/luxorParameterTradeGraphs.R (from rev 1123, pkg/quantstrat/demo/tradeGraphs.R)
===================================================================
--- pkg/quantstrat/demo/luxor/luxorParameterTradeGraphs.R (rev 0)
+++ pkg/quantstrat/demo/luxor/luxorParameterTradeGraphs.R 2012-08-08 12:07:15 UTC (rev 1124)
@@ -0,0 +1,14 @@
+#!/usr/bin/Rscript --vanilla
+
+require(quantstrat)
+
+load('../../data/luxor.parameters.1-10.30-55.RData')
+
+tradeGraphs (
+ stats = stats,
+ free.params = c("Param.indicator.1.nFast", "Param.indicator.2.nSlow"),
+ fixed.params = NULL,
+ statistics = c("Net.Trading.PL", "maxDrawdown", "Avg.Trade.PL", "Num.Trades", "Profit.Factor"),
+ title = 'Luxor SMA Parameter Scan'
+)
+
Copied: pkg/quantstrat/demo/luxor/luxorTimespanTradeGraphs.R (from rev 1123, pkg/quantstrat/demo/tradeGraphs.R)
===================================================================
--- pkg/quantstrat/demo/luxor/luxorTimespanTradeGraphs.R (rev 0)
+++ pkg/quantstrat/demo/luxor/luxorTimespanTradeGraphs.R 2012-08-08 12:07:15 UTC (rev 1124)
@@ -0,0 +1,27 @@
+#!/usr/bin/Rscript --vanilla
+
+require(quantstrat)
+
+load('../../data/luxor.timespan.24x24.2002-2008.RData')
+
+names(stats)[names(stats)=='testPackListPRL[[k]]$parameters']<-'timespan'
+
+stats$tmp = strsplit(as.character(stats$timespan),'/')
+
+stats$from<-sapply(stats$tmp,FUN='[',1)
+stats$to<-sapply(stats$tmp,FUN='[',2)
+
+stats$start<-as.numeric(gsub('T([0-9]+):[0-9]+',x=stats$from,'\\1'))
+stats$stop<-(as.numeric(gsub('T([0-9]+):[0-9]+',x=stats$to,'\\1'))+1)%%24
+
+# trading data is in EST (GMT-4): move 4 hours to adjust to GMT
+#stats$start<-(stats$start+4)%%24
+#stats$stop<-(stats$stop+4)%%24
+
+tradeGraphs(
+ stats,
+ free.params=c('start','stop'),
+ statistics=c('Net.Trading.PL','maxDrawdown',"Avg.Trade.PL",'Num.Trades',"Profit.Factor"),
+ title = 'Luxor Intraday TimeWindow Scan'
+)
+
Deleted: pkg/quantstrat/demo/luxor.R
===================================================================
--- pkg/quantstrat/demo/luxor.R 2012-08-08 11:10:03 UTC (rev 1123)
+++ pkg/quantstrat/demo/luxor.R 2012-08-08 12:07:15 UTC (rev 1124)
@@ -1,177 +0,0 @@
-#!/usr/bin/Rscript --vanilla
-#
-# Jan Humme (@opentrades) - June 2012
-#
-# Tested and found to work correctly using blotter r1082
-#
-# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
-#
-# Paragraph 3.2: luxor without any optimizations, but with $30 tnx costs + slippage
-
-.fast = 1
-.slow = 44
-
-.qty=100000
-.th=0.0005
-.txn=-30
-#.txn=0
-
-initDate = '2002-10-21'
-.from='2002-10-21'
-#.to='2008-07-04'
-.to='2003-12-31'
-
-####
-
-s = 'luxor'
-p = 'forex'
-a = 'IB1'
-
-options(width = 240)
-#Sys.setenv(TZ="GMT")
-
-###
-
-require(quantstrat)
-
-currency(c('GBP', 'USD'))
-
-exchange_rate(c('GBPUSD'), tick_size=0.0001)
-
-#setSymbolLookup.FI('~/R.symbols/', 'GBPUSD')
-setSymbolLookup.FI('../data/', 'GBPUSD')
-
-###
-
-getSymbols('GBPUSD', from=.from, to=.to, verbose=FALSE)
-GBPUSD = to.minutes30(GBPUSD)
-GBPUSD = align.time(to.minutes30(GBPUSD), 1800)
-
-###
-
-initPortf(p, symbols='GBPUSD', initDate=initDate, currency='USD')
-initAcct(a, portfolios=p, initDate=initDate, currency='USD')
-
-###
-
-initOrders(p, initDate=initDate)
-
-### strategy ######################################################################
-
-strategy(s, store=TRUE)
-
-### indicators
-
-add.indicator(s, name = "SMA",
- arguments = list(
- x = quote(Cl(mktdata)),
- n = .fast
- ),
- label="nFast"
-)
-
-add.indicator(s, name="SMA",
- arguments = list(
- x = quote(Cl(mktdata)),
- n = .slow
- ),
- label="nSlow"
-)
-
-### signals
-
-add.signal(s, 'sigCrossover',
- arguments = list(
- columns=c("nFast","nSlow"),
- relationship="gte"
- ),
- label='long'
-)
-
-add.signal(s, 'sigCrossover',
- arguments = list(
- columns=c("nFast","nSlow"),
- relationship="lt"
- ),
- label='short'
-)
-
-### rules
-
-add.rule(s, 'ruleSignal',
- arguments=list(sigcol='long' , sigval=TRUE,
- replace=TRUE,
- orderside='short',
- ordertype='market',
- TxnFees=.txn,
- orderqty='all',
- orderset='ocoshort'
- ),
- type='exit',
- label='Exit2LONG'
-)
-
-add.rule(s, 'ruleSignal',
- arguments=list(sigcol='short', sigval=TRUE,
- replace=TRUE,
- orderside='long' ,
- ordertype='market',
- TxnFees=.txn,
- orderqty='all',
- orderset='ocolong'
- ),
- type='exit',
- label='Exit2SHORT')
-
-add.rule(s, 'ruleSignal',
- arguments=list(sigcol='long' , sigval=TRUE,
- replace=FALSE,
- orderside='long' ,
- ordertype='stoplimit',
- prefer='High',
- threshold=.th,
- TxnFees=0,
- orderqty=+.qty,
- orderset='ocolong'
- ),
- type='enter',
- label='EnterLONG'
-)
-
-add.rule(s, 'ruleSignal',
- arguments=list(sigcol='short', sigval=TRUE,
- replace=FALSE,
- orderside='short',
- ordertype='stoplimit',
- prefer='Low',
- threshold=-.th,
- TxnFees=0,
- orderqty=-.qty,
- orderset='ocoshort'
- ),
- type='enter',
- label='EnterSHORT'
-)
-
-#
-
-###############################################################################
-
-applyStrategy(s, p, verbose = FALSE)
-#applyStrategy(s, p, prefer='Open', verbose = FALSE)
-
-updatePortf(p, Symbols='GBPUSD', ,Dates=paste('::',as.Date(Sys.time()),sep=''))
-
-###############################################################################
-
-chart.Posn(p, "GBPUSD")
-
-print(getOrderBook(p))
-
-txns <- getTxns(p, 'GBPUSD')
-txns
-##txns$Net
-cat('Net profit:', sum(txns$Net.Txn.Realized.PL), '\n')
-
-tradeStats(p, 'GBPUSD')
-
Deleted: pkg/quantstrat/demo/luxorParameters.R
===================================================================
--- pkg/quantstrat/demo/luxorParameters.R 2012-08-08 11:10:03 UTC (rev 1123)
+++ pkg/quantstrat/demo/luxorParameters.R 2012-08-08 12:07:15 UTC (rev 1124)
@@ -1,66 +0,0 @@
-#!/usr/bin/Rscript --vanilla
-
-#verbose = 0
-verbose = 1
-
-#method='expand'
-method='random'
-.sampleSize=20
-
-.fastRange=(1:20)
-.slowRange=(21:80)
-
-###############################################################################
-
-#require(foreach,quietly=TRUE)
-require(doMC)
-require(quantstrat)
-
-portfolio.st = 'forex'
-
-source('luxor.R')
-
-s<-getStrategy('luxor')
-
-parameterTable<-getParameterTable(s)
-#parameterTable
-
-tPD2<-setParameterDistribution(type = 'indicator', indexnum = 1, distribution = list(nFast = .fastRange), label = 'nFast')
-tPD2<-setParameterDistribution(tPD2, type = 'indicator', indexnum = 2, distribution = list(nSlow = .slowRange), label = 'nSlow')
-
-pConstraint2<-setParameterConstraint(constraintLabel='luxorPC',paramList=c('nFast','nSlow'),relationship='lt')
-
-registerDoMC(cores=2)
-
-if(method == 'random')
-{
- laststpar.rnd<-system.time(
- testPackListPL<-applyParameter(
- strategy=s,
- portfolios=portfolio.st,
- parameterPool=tPD2,
- method='random',
- sampleSize=.sampleSize,
- parameterConstraints=pConstraint2
- )
- )
- if(verbose >=1) laststpar.rnd
-}
-
-if(method == 'expand')
-{
- laststpar.exp<-system.time(
- testPackListPL<-applyParameter(
- strategy=s,
- portfolios=portfolio.st,
- parameterPool=tPD2,
- method='expand',
- parameterConstraints=pConstraint2
- )
- )
- if(verbose >=1) print(laststpar.exp)
-}
-
-#examine the stats from this parameter run:
-if(verbose >=1) print(testPackListPL$statsTable)
-
Deleted: pkg/quantstrat/demo/tradeGraphs.R
===================================================================
--- pkg/quantstrat/demo/tradeGraphs.R 2012-08-08 11:10:03 UTC (rev 1123)
+++ pkg/quantstrat/demo/tradeGraphs.R 2012-08-08 12:07:15 UTC (rev 1124)
@@ -1,14 +0,0 @@
-#!/usr/bin/Rscript --vanilla
-
-require(quantstrat)
-
-load('../data/luxor.250.RData')
-
-tradeGraphs (
- stats = stats,
- free.params = c("Param.indicator.1.nFast", "Param.indicator.2.nSlow"),
- fixed.params = NULL,
- statistics = c("Net.Trading.PL", "maxDrawdown", "Avg.Trade.PL", "Num.Trades", "Profit.Factor"),
- title = 'Luxor'
-)
-
More information about the Blotter-commits
mailing list