[Blotter-commits] r1440 - pkg/quantstrat/demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Apr 18 23:01:16 CEST 2013
Author: opentrades
Date: 2013-04-18 23:01:16 +0200 (Thu, 18 Apr 2013)
New Revision: 1440
Added:
pkg/quantstrat/demo/luxor.3.paramset.sma.R
pkg/quantstrat/demo/luxor.3.tradegraphs.sma.R
pkg/quantstrat/demo/luxor.5.orderchains.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
Removed:
pkg/quantstrat/demo/luxor.3.sma.optimize.R
pkg/quantstrat/demo/luxor.3.sma.tradegraphs.R
pkg/quantstrat/demo/luxor.StopLoss.R
pkg/quantstrat/demo/luxor.StopTrailing.R
pkg/quantstrat/demo/luxor.TakeProfit.R
pkg/quantstrat/demo/luxor.exits.R
pkg/quantstrat/demo/luxor.orderchains.R
Log:
- more luxor demo reorganizing
Copied: pkg/quantstrat/demo/luxor.3.paramset.sma.R (from rev 1439, pkg/quantstrat/demo/luxor.3.sma.optimize.R)
===================================================================
--- pkg/quantstrat/demo/luxor.3.paramset.sma.R (rev 0)
+++ pkg/quantstrat/demo/luxor.3.paramset.sma.R 2013-04-18 21:01:16 UTC (rev 1440)
@@ -0,0 +1,59 @@
+#!/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
+
+options(width = 240)
+Sys.setenv(TZ='UTC')
+
+.nsamples=80
+
+###
+
+initDate = '2002-10-21'
+
+####
+
+strategy.st = 'luxor'
+portfolio.st = 'forex'
+account.st = 'IB1'
+
+source('luxor.symbols.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
+
+save(stats, file='luxor.3.optimize.sma.RData')
+
+print(results$tradeStats)
+
Deleted: pkg/quantstrat/demo/luxor.3.sma.optimize.R
===================================================================
--- pkg/quantstrat/demo/luxor.3.sma.optimize.R 2013-04-18 20:34:27 UTC (rev 1439)
+++ pkg/quantstrat/demo/luxor.3.sma.optimize.R 2013-04-18 21:01:16 UTC (rev 1440)
@@ -1,56 +0,0 @@
-#!/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
-
-options(width = 240)
-Sys.setenv(TZ='UTC')
-
-.nsamples=80
-
-###
-
-initDate = '2002-10-21'
-
-####
-
-strategy.st = 'luxor'
-portfolio.st = 'forex'
-account.st = 'IB1'
-
-source('luxor.symbols.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)
-
-### apply.paramset()
-
-results <- apply.paramset(strategy.st, paramset.label='SMA', portfolio.st=portfolio.st, account.st=account.st, nsamples=.nsamples, verbose=TRUE)
-
-###
-
-stats <- results$tradeStats
-
-save(stats, file='luxor.3.optimize.sma.RData')
-
-print(results$tradeStats)
-
Deleted: pkg/quantstrat/demo/luxor.3.sma.tradegraphs.R
===================================================================
--- pkg/quantstrat/demo/luxor.3.sma.tradegraphs.R 2013-04-18 20:34:27 UTC (rev 1439)
+++ pkg/quantstrat/demo/luxor.3.sma.tradegraphs.R 2013-04-18 21:01:16 UTC (rev 1440)
@@ -1,39 +0,0 @@
-#!/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)
-
-require(quantstrat)
-
-### load 'stats' back into .GlobalEnv
-
-load('../data/luxor.parameters.1-10.30-55.RData')
-
-### show trade graphs from stats
-
-tradeGraphs (
- stats = stats,
- free.params = c("Param.indicator.1.nFast", "Param.indicator.2.nSlow"),
- statistics = c("Net.Trading.PL", "maxDrawdown", "Avg.Trade.PL", "Num.Trades", "Profit.Factor"),
- title = 'Luxor SMA Parameter Scan'
-)
-
-##### 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)
-################################################################
Copied: pkg/quantstrat/demo/luxor.3.tradegraphs.sma.R (from rev 1439, pkg/quantstrat/demo/luxor.3.sma.tradegraphs.R)
===================================================================
--- pkg/quantstrat/demo/luxor.3.tradegraphs.sma.R (rev 0)
+++ pkg/quantstrat/demo/luxor.3.tradegraphs.sma.R 2013-04-18 21:01:16 UTC (rev 1440)
@@ -0,0 +1,39 @@
+#!/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)
+
+require(quantstrat)
+
+### load 'stats' back into .GlobalEnv
+
+load('../data/luxor.parameters.1-10.30-55.RData')
+
+### show trade graphs from stats
+
+tradeGraphs (
+ stats = stats,
+ free.params = c("Param.indicator.1.nFast", "Param.indicator.2.nSlow"),
+ statistics = c("Net.Trading.PL", "maxDrawdown", "Avg.Trade.PL", "Num.Trades", "Profit.Factor"),
+ title = 'Luxor SMA Parameter Scan'
+)
+
+##### 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)
+################################################################
Copied: pkg/quantstrat/demo/luxor.5.orderchains.R (from rev 1430, pkg/quantstrat/demo/luxor.orderchains.R)
===================================================================
--- pkg/quantstrat/demo/luxor.5.orderchains.R (rev 0)
+++ pkg/quantstrat/demo/luxor.5.orderchains.R 2013-04-18 21:01:16 UTC (rev 1440)
@@ -0,0 +1,332 @@
+#!/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)
+#
+
+options(width = 240)
+#Sys.setenv(TZ="GMT")
+
+.fast = 1
+.slow = 44
+
+.qty=100000
+.th=0.0005
+.txn=-30
+.timespan = 'T08:00/T12:00'
+.timespan = 'T00:00/T23:59'
+
+.stoploss=0.001
+.stoptrailing=0.0015
+.takeprofit=0.003
+
+##### 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()}
+
+initDate = '2002-10-21'
+.from='2002-10-21'
+#.to='2008-07-04'
+.to='2002-10-31'
+#.to='2002-12-31'
+#.to='2003-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(system.file('extdata',package='quantstrat'), '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 ############
+
+### stop-loss
+
+add.rule(s, name = 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=FALSE,
+ orderside='long',
+ ordertype='stoplimit',
+ tmult=TRUE,
+ threshold=.stoploss,
+ TxnFees=.txn,
+ orderqty='all',
+ orderset='ocolong'
+ ),
+ type='chain',
+ parent='EnterLONG',
+ label='StopLossLONG',
+ storefun=FALSE
+)
+
+add.rule(s, name = 'ruleSignal',
+ arguments=list(sigcol='short' , sigval=TRUE,
+ replace=FALSE,
+ orderside='short',
+ ordertype='stoplimit',
+ tmult=TRUE,
+ threshold=.stoploss,
+ TxnFees=.txn,
+ orderqty='all',
+ orderset='ocoshort'
+ ),
+ type='chain',
+ parent='EnterSHORT',
+ label='StopLossSHORT',
+ storefun=FALSE
+)
+
+### stop-trailing
+
+if(TRUE)
+{
+add.rule(s, name = 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=FALSE,
+ orderside='long',
+ ordertype='stoptrailing',
+ tmult=TRUE,
+ threshold=.stoptrailing,
+ TxnFees=.txn,
+ orderqty='all',
+ orderset='ocolong'
+ ),
+ type='chain',
+ parent='EnterLONG',
+ label='StopTrailingLONG',
+ storefun=FALSE
+)
+
+add.rule(s, name = 'ruleSignal',
+ arguments=list(sigcol='short' , sigval=TRUE,
+ replace=FALSE,
+ orderside='short',
+ ordertype='stoptrailing',
+ tmult=TRUE,
+ threshold=.stoptrailing,
+ TxnFees=.txn,
+ orderqty='all',
+ orderset='ocoshort'
+ ),
+ type='chain',
+ parent='EnterSHORT',
+ label='StopTrailingSHORT',
+ storefun=FALSE
+)
+}
+
+### take-profit
+
+add.rule(s, name = 'ruleSignal',
+ arguments=list(sigcol='long' , sigval=TRUE,
+ replace=FALSE,
+ orderside='long',
+ ordertype='limit',
+ tmult=TRUE,
+ threshold=.takeprofit,
+ TxnFees=.txn,
+ orderqty='all',
+ orderset='ocolong'
+ ),
+ type='chain',
+ parent='EnterLONG',
+ label='TakeProfitLONG',
+ storefun=FALSE
+)
+
+add.rule(s, name = 'ruleSignal',
+ arguments=list(sigcol='short' , sigval=TRUE,
+ replace=FALSE,
+ orderside='short',
+ ordertype='limit',
+ tmult=TRUE,
+ threshold=.takeprofit,
+ TxnFees=.txn,
+ orderqty='all',
+ orderset='ocoshort'
+ ),
+ type='chain',
+ parent='EnterSHORT',
+ label='TakeProfitSHORT',
+ storefun=FALSE
+)
+
+###
+
+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',
+ storefun=FALSE
+)
+
+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',
+ storefun=FALSE
+)
+
+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',
+ storefun=FALSE
+)
+
+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',
+ storefun=FALSE
+)
+
+#
+
+###############################################################################
+
+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'))
+
+##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
+# book = getOrderBook(port)
+# stats = tradeStats(port)
+# rets = PortfReturns(acct)
+################################################################
Copied: pkg/quantstrat/demo/luxor.6.paramset.stoploss.R (from rev 1430, pkg/quantstrat/demo/luxor.StopLoss.R)
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.stoploss.R (rev 0)
+++ pkg/quantstrat/demo/luxor.6.paramset.stoploss.R 2013-04-18 21:01:16 UTC (rev 1440)
@@ -0,0 +1,87 @@
+#!/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)
+
+options(width = 240)
+#Sys.setenv(TZ="GMT")
+
+.qty=100000
+
+.fast = 10
+.slow = 30
+
+.qty=100000
+.th=0.0005
+.txn=0
+
+##### 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()}
+
+initDate = '2002-10-21'
+
+source('luxor.symbols.R')
+
+###
+
+strategy.st = 'luxor'
+portfolio.st = 'forex'
+account.st = 'IB1'
+
+source('luxor.symbols.R')
+
+initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
+addPosLimit(
+ portfolio=portfolio.st,
+ symbol='GBPUSD',
+ timestamp=initDate,
+ maxpos=.qty)
+
+initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+
+###
+
+initOrders(portfolio.st, initDate=initDate)
+
+load.strategy(strategy.st)
+
+############################
+
+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)
+
+print(results$tradeStats)
+
+##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
+# book = getOrderBook(port)
+# stats = tradeStats(port)
+# rets = PortfReturns(acct)
+################################################################
Copied: pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R (from rev 1430, pkg/quantstrat/demo/luxor.StopTrailing.R)
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R (rev 0)
+++ pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R 2013-04-18 21:01:16 UTC (rev 1440)
@@ -0,0 +1,85 @@
+#!/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)
+
+options(width = 240)
+Sys.setenv(TZ='UTC')
+
+.qty=100000
+
+.fast = 10
+.slow = 30
+
+.qty=100000
+.th=0.0005
+.txn=0
+
+##### 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()}
+
+initDate = '2002-10-21'
+
+source('luxor.symbols.R')
+
+###
+
+strategy.st = 'luxor'
+portfolio.st = 'forex'
+account.st = 'IB1'
+
+initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
+addPosLimit(
+ portfolio=portfolio.st,
+ symbol='GBPUSD',
+ timestamp=initDate,
+ maxpos=.qty)
+
+initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+
+###
+
+initOrders(portfolio.st, initDate=initDate)
+
+load.strategy(strategy.st)
+
+############################
+
+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)
+
+print(results$tradeStats)
+
+##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
+# book = getOrderBook(port)
+# stats = tradeStats(port)
+# rets = PortfReturns(acct)
+################################################################
Copied: pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R (from rev 1430, pkg/quantstrat/demo/luxor.TakeProfit.R)
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R (rev 0)
+++ pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R 2013-04-18 21:01:16 UTC (rev 1440)
@@ -0,0 +1,85 @@
+#!/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)
+
+options(width = 240)
+Sys.setenv(TZ='UTC')
+
+.qty=100000
+
+.fast = 10
+.slow = 30
+
+.qty=100000
+.th=0.0005
+.txn=0
+
+##### 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()}
+
+initDate = '2002-10-21'
+
+source('luxor.symbols.R')
+
+###
+
+strategy.st = 'luxor'
+portfolio.st = 'forex'
+account.st = 'IB1'
+
+initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
+addPosLimit(
+ portfolio=portfolio.st,
+ symbol='GBPUSD',
+ timestamp=initDate,
+ maxpos=.qty)
+
+initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
+
+###
+
+initOrders(portfolio.st, initDate=initDate)
+
+load.strategy(strategy.st)
+
+############################
+
+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)
+
+print(results$tradeStats)
+
+##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
+# book = getOrderBook(port)
+# stats = tradeStats(port)
+# rets = PortfReturns(acct)
+################################################################
Deleted: pkg/quantstrat/demo/luxor.StopLoss.R
===================================================================
--- pkg/quantstrat/demo/luxor.StopLoss.R 2013-04-18 20:34:27 UTC (rev 1439)
+++ pkg/quantstrat/demo/luxor.StopLoss.R 2013-04-18 21:01:16 UTC (rev 1440)
@@ -1,103 +0,0 @@
-#!/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)
-
-options(width = 240)
-#Sys.setenv(TZ="GMT")
-
-.qty=100000
-
-.fast = 10
-.slow = 30
-
-.qty=100000
-.th=0.0005
-.txn=0
-
-
-##### 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()}
-
-initDate = '2002-10-21'
-.from='2002-10-21'
-#.to='2008-07-04'
-#.to='2003-12-31'
-.to='2002-10-31'
-
-###
-
-currency(c('GBP', 'USD'))
-
-exchange_rate(c('GBPUSD'), tick_size=0.0001)
-
-###
-
-setSymbolLookup.FI(system.file('extdata',package='quantstrat'), 'GBPUSD')
-
-getSymbols('GBPUSD', from=.from, to=.to, verbose=FALSE)
-GBPUSD = to.minutes30(GBPUSD)
-GBPUSD = align.time(to.minutes30(GBPUSD), 1800)
-
-###
-
-strategy.st = 'luxor'
-portfolio.st = 'forex'
-account.st = 'IB1'
-
-initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
-addPosLimit(
- portfolio=portfolio.st,
- symbol='GBPUSD',
- timestamp=initDate,
- maxpos=.qty)
-
-initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
-
-###
-
-initOrders(portfolio.st, initDate=initDate)
-
-load.strategy(strategy.st)
-
-############################
-
-require(foreach)
-
-#registerDoSEQ()
-
-require(doMC)
-registerDoMC(cores=2)
-
-#require(doParallel)
-#registerDoParallel(cores=2)
-
-#require(doRedis)
-#registerDoRedis('jobs')
-
-############################
-
-results <- apply.paramset(strategy.st, paramset.label='StopLoss', portfolio.st=portfolio.st, verbose=TRUE)
-
-print(results$tradeStats)
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
-# book = getOrderBook(port)
-# stats = tradeStats(port)
-# rets = PortfReturns(acct)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.StopTrailing.R
===================================================================
--- pkg/quantstrat/demo/luxor.StopTrailing.R 2013-04-18 20:34:27 UTC (rev 1439)
+++ pkg/quantstrat/demo/luxor.StopTrailing.R 2013-04-18 21:01:16 UTC (rev 1440)
@@ -1,102 +0,0 @@
-#!/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)
-
-options(width = 240)
-#Sys.setenv(TZ="GMT")
-
-.qty=100000
-
-.fast = 10
-.slow = 30
-
-.qty=100000
-.th=0.0005
-.txn=0
-
-##### 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()}
-
-initDate = '2002-10-21'
-.from='2002-10-21'
-#.to='2008-07-04'
-#.to='2003-12-31'
-.to='2002-10-31'
-
-###
-
-currency(c('GBP', 'USD'))
-
-exchange_rate(c('GBPUSD'), tick_size=0.0001)
-
-###
-
-setSymbolLookup.FI(system.file('extdata',package='quantstrat'), 'GBPUSD')
-
-getSymbols('GBPUSD', from=.from, to=.to, verbose=FALSE)
-GBPUSD = to.minutes30(GBPUSD)
-GBPUSD = align.time(to.minutes30(GBPUSD), 1800)
-
-###
-
-strategy.st = 'luxor'
-portfolio.st = 'forex'
-account.st = 'IB1'
-
-initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
-addPosLimit(
- portfolio=portfolio.st,
- symbol='GBPUSD',
- timestamp=initDate,
- maxpos=.qty)
-
-initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
-
-###
-
-initOrders(portfolio.st, initDate=initDate)
-
-load.strategy(strategy.st)
-
-############################
-
-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, verbose=TRUE)
-
-print(results$tradeStats)
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
-# book = getOrderBook(port)
-# stats = tradeStats(port)
-# rets = PortfReturns(acct)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.TakeProfit.R
===================================================================
--- pkg/quantstrat/demo/luxor.TakeProfit.R 2013-04-18 20:34:27 UTC (rev 1439)
+++ pkg/quantstrat/demo/luxor.TakeProfit.R 2013-04-18 21:01:16 UTC (rev 1440)
@@ -1,102 +0,0 @@
-#!/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)
-
-options(width = 240)
-#Sys.setenv(TZ="GMT")
-
-.qty=100000
-
-.fast = 10
-.slow = 30
-
-.qty=100000
-.th=0.0005
-.txn=0
-
-##### 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()}
-
-initDate = '2002-10-21'
-.from='2002-10-21'
-#.to='2008-07-04'
-#.to='2003-12-31'
-.to='2002-10-31'
-
-###
-
-currency(c('GBP', 'USD'))
-
-exchange_rate(c('GBPUSD'), tick_size=0.0001)
-
-###
-
-setSymbolLookup.FI(system.file('extdata',package='quantstrat'), 'GBPUSD')
-
-getSymbols('GBPUSD', from=.from, to=.to, verbose=FALSE)
-GBPUSD = to.minutes30(GBPUSD)
-GBPUSD = align.time(to.minutes30(GBPUSD), 1800)
-
-###
-
-strategy.st = 'luxor'
-portfolio.st = 'forex'
-account.st = 'IB1'
-
-initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
-addPosLimit(
- portfolio=portfolio.st,
- symbol='GBPUSD',
- timestamp=initDate,
- maxpos=.qty)
-
-initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
-
-###
-
-initOrders(portfolio.st, initDate=initDate)
-
-load.strategy(strategy.st)
-
-############################
-
-require(foreach)
-
-registerDoSEQ()
-
-#require(doMC)
-#registerDoMC(cores=2)
-
-#require(doParallel)
-#registerDoParallel(cores=2)
-
-#require(doRedis)
-#registerDoRedis('jobs')
-
-############################
-
-results <- apply.paramset(strategy.st, paramset.label='TakeProfit', portfolio.st=portfolio.st, verbose=TRUE)
-
-print(results$tradeStats)
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
-# book = getOrderBook(port)
-# stats = tradeStats(port)
-# rets = PortfReturns(acct)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.exits.R
===================================================================
--- pkg/quantstrat/demo/luxor.exits.R 2013-04-18 20:34:27 UTC (rev 1439)
+++ pkg/quantstrat/demo/luxor.exits.R 2013-04-18 21:01:16 UTC (rev 1440)
@@ -1,140 +0,0 @@
-#!/usr/bin/Rscript --vanilla
-
-require(quantstrat)
-
-source('luxor.strategy.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()}
-
-.FastSMA = (1:20)
-.SlowSMA = (30:80)
-
-.StopLoss = seq(0.1, 2.0, length.out=20)/100
-.StopTrailing = seq(0.1, 2.0, length.out=20)/100
-.TakeProfit = seq(0.1, 2.0, length.out=20)/100
-
-#s<-getStrategy('luxor')
-s <- 'luxor'
-
-### SMA paramset
-
-add.distribution(s,
- paramset.label = 'SMA',
- component.type = 'indicator',
- component.label = 'nFast',
- variable = list(n = .FastSMA),
- label = 'nFAST'
-)
-
-add.distribution(s,
- paramset.label = 'SMA',
- component.type = 'indicator',
- component.label = 'nSlow',
- variable = list(n = .SlowSMA),
- label = 'nSLOW'
-)
-
-add.constraint(s,
- paramset.label = 'SMA',
- distribution.label.1 = 'nFAST',
- distribution.label.2 = 'nSLOW',
- operator = '<',
- label = 'SMA'
-)
-
-### Stop Loss paramset
-
-add.distribution(s,
- paramset.label = 'StopLoss',
- component.type = 'chain',
- component.label = 'StopLossLONG',
- variable = list(threshold = .StopLoss),
- label = 'StopLossLONG'
-)
-
-add.distribution(s,
- paramset.label = 'StopLoss',
- component.type = 'chain',
- component.label = 'StopLossSHORT',
- variable = list(threshold = .StopLoss),
- label = 'StopLossSHORT'
-)
-
-add.constraint(s,
- paramset.label = 'StopLoss',
- distribution.label.1 = 'StopLossLONG',
- distribution.label.2 = 'StopLossSHORT',
- operator = '==',
- label = 'StopLoss'
-)
-
-### Stop Trailing paramset
-
-add.distribution(s,
- paramset.label = 'StopTrailing',
- component.type = 'chain',
- component.label = 'StopTrailingLONG',
- variable = list(threshold = .StopTrailing),
- label = 'StopTrailingLONG'
-)
-
-add.distribution(s,
- paramset.label = 'StopTrailing',
- component.type = 'chain',
- component.label = 'StopTrailingSHORT',
- variable = list(threshold = .StopTrailing),
- label = 'StopTrailingSHORT'
-)
-
-add.constraint(s,
- paramset.label = 'StopTrailing',
- distribution.label.1 = 'StopTrailingLONG',
- distribution.label.2 = 'StopTrailingSHORT',
- operator = '==',
- label = 'StopTrailing'
-)
-
-### Take Profit paramset
-
-add.distribution(s,
- paramset.label = 'TakeProfit',
- component.type = 'chain',
- component.label = 'TakeProfitLONG',
- variable = list(threshold = .TakeProfit),
- label = 'TakeProfitLONG'
-)
-
-add.distribution(s,
- paramset.label = 'TakeProfit',
- component.type = 'chain',
- component.label = 'TakeProfitSHORT',
- variable = list(threshold = .TakeProfit),
- label = 'TakeProfitSHORT'
-)
-
-add.constraint(s,
- paramset.label = 'TakeProfit',
- distribution.label.1 = 'TakeProfitLONG',
- distribution.label.2 = 'TakeProfitSHORT',
- operator = '==',
- label = 'TakeProfit'
-)
-
-###
-
-save.strategy('luxor')
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
-# book = getOrderBook(port)
-# stats = tradeStats(port)
-# rets = PortfReturns(acct)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.orderchains.R
===================================================================
--- pkg/quantstrat/demo/luxor.orderchains.R 2013-04-18 20:34:27 UTC (rev 1439)
+++ pkg/quantstrat/demo/luxor.orderchains.R 2013-04-18 21:01:16 UTC (rev 1440)
@@ -1,332 +0,0 @@
-#!/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)
-#
-
-options(width = 240)
-#Sys.setenv(TZ="GMT")
-
-.fast = 1
-.slow = 44
-
-.qty=100000
-.th=0.0005
-.txn=-30
-.timespan = 'T08:00/T12:00'
-.timespan = 'T00:00/T23:59'
-
-.stoploss=0.001
-.stoptrailing=0.0015
-.takeprofit=0.003
-
-##### 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()}
-
-initDate = '2002-10-21'
-.from='2002-10-21'
-#.to='2008-07-04'
-.to='2002-10-31'
-#.to='2002-12-31'
-#.to='2003-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(system.file('extdata',package='quantstrat'), '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 ############
-
-### stop-loss
-
-add.rule(s, name = 'ruleSignal',
- arguments=list(sigcol='long' , sigval=TRUE,
- replace=FALSE,
- orderside='long',
- ordertype='stoplimit',
- tmult=TRUE,
- threshold=.stoploss,
- TxnFees=.txn,
- orderqty='all',
- orderset='ocolong'
- ),
- type='chain',
- parent='EnterLONG',
- label='StopLossLONG',
- storefun=FALSE
-)
-
-add.rule(s, name = 'ruleSignal',
- arguments=list(sigcol='short' , sigval=TRUE,
- replace=FALSE,
- orderside='short',
- ordertype='stoplimit',
- tmult=TRUE,
- threshold=.stoploss,
- TxnFees=.txn,
- orderqty='all',
- orderset='ocoshort'
- ),
- type='chain',
- parent='EnterSHORT',
- label='StopLossSHORT',
- storefun=FALSE
-)
-
-### stop-trailing
-
-if(TRUE)
-{
-add.rule(s, name = 'ruleSignal',
- arguments=list(sigcol='long' , sigval=TRUE,
- replace=FALSE,
- orderside='long',
- ordertype='stoptrailing',
- tmult=TRUE,
- threshold=.stoptrailing,
- TxnFees=.txn,
- orderqty='all',
- orderset='ocolong'
- ),
- type='chain',
- parent='EnterLONG',
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/blotter -r 1440
More information about the Blotter-commits
mailing list