[Blotter-commits] r1456 - pkg/quantstrat/demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue May 7 22:45:41 CEST 2013
Author: opentrades
Date: 2013-05-07 22:45:41 +0200 (Tue, 07 May 2013)
New Revision: 1456
Removed:
pkg/quantstrat/demo/luxor.1.strategy.R
pkg/quantstrat/demo/luxor.2.add.paramsets.R
pkg/quantstrat/demo/luxor.3.paramset.sma.R
pkg/quantstrat/demo/luxor.3.tradegraphs.sma.R
pkg/quantstrat/demo/luxor.4.Timespans.R
pkg/quantstrat/demo/luxor.4.Timespans.tradegraphs.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
pkg/quantstrat/demo/luxor.7.MAE.stoploss.R
pkg/quantstrat/demo/luxor.7.MAE.stoptrailing.R
pkg/quantstrat/demo/luxor.7.MFE.takeprofit.R
pkg/quantstrat/demo/luxor.getSymbols.R
pkg/quantstrat/demo/luxor.include.R
Log:
- removed luxor demos (about to be replaced)
Deleted: pkg/quantstrat/demo/luxor.1.strategy.R
===================================================================
--- pkg/quantstrat/demo/luxor.1.strategy.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.1.strategy.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -1,156 +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")
-
-###
-
-.fast = 10
-.slow = 30
-
-##### 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')
-
-### 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)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.2.add.paramsets.R
===================================================================
--- pkg/quantstrat/demo/luxor.2.add.paramsets.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.2.add.paramsets.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -1,147 +0,0 @@
-#!/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()}
-
-###
-
-.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
-
-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'
-)
-
-### Stop Loss paramset
-
-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 paramset
-
-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 paramset
-
-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)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.3.paramset.sma.R
===================================================================
--- pkg/quantstrat/demo/luxor.3.paramset.sma.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.3.paramset.sma.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -1,52 +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
-
-###
-
-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
-
-save(stats, file='luxor.3.optimize.sma.RData')
-
-print(results$tradeStats)
-
Deleted: pkg/quantstrat/demo/luxor.3.tradegraphs.sma.R
===================================================================
--- pkg/quantstrat/demo/luxor.3.tradegraphs.sma.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.3.tradegraphs.sma.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -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)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.4.Timespans.R
===================================================================
--- pkg/quantstrat/demo/luxor.4.Timespans.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.4.Timespans.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -1,102 +0,0 @@
-#!/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(foreach,quietly=TRUE)
-# example parallel initialization for doParallel. this or doMC, or doRedis are
-# most probably preferable to doSMP
-#require(doParallel)
-#registerDoParallel() # by default number of physical cores -1
-
-require(quantstrat)
-
-portfolio.st = 'forex'
-
-s<-getStrategy('luxor')
-
-parameterTable<-getParameterTable(s)
-
-tPD2<-setParameterDistribution(strategy=s, component.type='enter', component.label='EnterLONG', 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")
-
-##### 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)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.4.Timespans.tradegraphs.R
===================================================================
--- pkg/quantstrat/demo/luxor.4.Timespans.tradegraphs.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.4.Timespans.tradegraphs.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -1,43 +0,0 @@
-#!/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'
-)
-
-##### 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)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.5.orderchains.R
===================================================================
--- pkg/quantstrat/demo/luxor.5.orderchains.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.5.orderchains.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -1,291 +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")
-
-##### 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()}
-
-.from='2002-10-21'
-#.to='2008-07-04'
-.to='2002-10-31'
-
-###
-
-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)
-
-### define strategy
-
-addPosLimit(
- portfolio=portfolio.st,
- symbol='GBPUSD',
- timestamp=initDate,
- maxpos=.orderqty)
-
-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 ############
-
-### stop-loss
-
-add.rule(strategy.st, name = 'ruleSignal',
- arguments=list(sigcol='long' , sigval=TRUE,
- replace=FALSE,
- orderside='long',
- ordertype='stoplimit',
- tmult=TRUE,
- threshold=.stoploss,
- TxnFees=.txnfees,
- orderqty='all',
- orderset='ocolong'
- ),
- type='chain', parent='EnterLONG',
- label='StopLossLONG',
- storefun=FALSE
-)
-
-add.rule(strategy.st, name = 'ruleSignal',
- arguments=list(sigcol='short' , sigval=TRUE,
- replace=FALSE,
- orderside='short',
- ordertype='stoplimit',
- tmult=TRUE,
- threshold=.stoploss,
- TxnFees=.txnfees,
- orderqty='all',
- orderset='ocoshort'
- ),
- type='chain', parent='EnterSHORT',
- label='StopLossSHORT',
- storefun=FALSE
-)
-
-### stop-trailing
-
-if(TRUE)
-{
-add.rule(strategy.st, name = 'ruleSignal',
- arguments=list(sigcol='long' , sigval=TRUE,
- replace=FALSE,
- orderside='long',
- ordertype='stoptrailing',
- tmult=TRUE,
- threshold=.stoptrailing,
- TxnFees=.txnfees,
- orderqty='all',
- orderset='ocolong'
- ),
- type='chain', parent='EnterLONG',
- label='StopTrailingLONG',
- storefun=FALSE
-)
-
-add.rule(strategy.st, name = 'ruleSignal',
- arguments=list(sigcol='short' , sigval=TRUE,
- replace=FALSE,
- orderside='short',
- ordertype='stoptrailing',
- tmult=TRUE,
- threshold=.stoptrailing,
- TxnFees=.txnfees,
- orderqty='all',
- orderset='ocoshort'
- ),
- type='chain', parent='EnterSHORT',
- label='StopTrailingSHORT',
- storefun=FALSE
-)
-}
-
-### take-profit
-
-add.rule(strategy.st, name = 'ruleSignal',
- arguments=list(sigcol='long' , sigval=TRUE,
- replace=FALSE,
- orderside='long',
- ordertype='limit',
- tmult=TRUE,
- threshold=.takeprofit,
- TxnFees=.txnfees,
- orderqty='all',
- orderset='ocolong'
- ),
- type='chain', parent='EnterLONG',
- label='TakeProfitLONG',
- storefun=FALSE
-)
-
-add.rule(strategy.st, name = 'ruleSignal',
- arguments=list(sigcol='short' , sigval=TRUE,
- replace=FALSE,
- orderside='short',
- ordertype='limit',
- tmult=TRUE,
- threshold=.takeprofit,
- TxnFees=.txnfees,
- orderqty='all',
- orderset='ocoshort'
- ),
- type='chain', parent='EnterSHORT',
- label='TakeProfitSHORT',
- storefun=FALSE
-)
-
-###
-
-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',
- storefun=FALSE
-)
-
-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',
- storefun=FALSE
-)
-
-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',
- storefun=FALSE
-)
-
-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',
- storefun=FALSE
-)
-
-#
-
-###############################################################################
-
-applyStrategy(strategy.st, portfolio.st, verbose = FALSE)
-#applyStrategy(strategy.st, p, prefer='Open', verbose = FALSE)
-
-updatePortf(portfolio.st, Symbols='GBPUSD', ,Dates=paste('::',as.Date(Sys.time()),sep=''))
-
-###############################################################################
-
-chart.Posn(portfolio.st, "GBPUSD")
-
-print(getOrderBook(portfolio.st))
-
-#txns <- getTxns(portfolio.st, 'GBPUSD')
-#txns
-##txns$Net
-#cat('Net profit:', sum(txns$Net.Txn.Realized.PL), '\n')
-
-print(tradeStats(portfolio.st, 'GBPUSD'))
-
-save.strategy(strategy.st)
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
-# book = getOrderBook(port)
-# stats = tradeStats(port)
-# rets = PortfReturns(acct)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.6.paramset.stoploss.R
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.stoploss.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.6.paramset.stoploss.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -1,71 +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")
-
-##### 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)
-
-############################
-
-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)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -1,71 +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='UTC')
-
-##### 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)
-
-############################
-
-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)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -1,71 +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='UTC')
-
-##### 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)
-
-############################
-
-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.7.MAE.stoploss.R
===================================================================
--- pkg/quantstrat/demo/luxor.7.MAE.stoploss.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.7.MAE.stoploss.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -1,35 +0,0 @@
-#!/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('luxor', '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)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.7.MAE.stoptrailing.R
===================================================================
--- pkg/quantstrat/demo/luxor.7.MAE.stoptrailing.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.7.MAE.stoptrailing.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -1,35 +0,0 @@
-#!/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.12: MAE graph in percentage terms
-
-require('blotter')
-
-data('luxor-p066', package='quantstrat', envir=.blotter)
-
-currency(c('GBP', 'USD'))
-exchange_rate(c('GBPUSD'), tick_size=0.0001)
-
-chart.ME('luxor', type='MAE', scale='percent')
-
-##### 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)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.7.MFE.takeprofit.R
===================================================================
--- pkg/quantstrat/demo/luxor.7.MFE.takeprofit.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.7.MFE.takeprofit.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -1,35 +0,0 @@
-#!/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.16: MFE graph in percentage terms
-
-require('blotter')
-
-data('luxor-p066', package='quantstrat', envir=.blotter)
-
-currency(c('GBP', 'USD'))
-exchange_rate(c('GBPUSD'), tick_size=0.0001)
-
-chart.ME('luxor', type='MFE', scale='percent')
-
-##### 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)
-################################################################
Deleted: pkg/quantstrat/demo/luxor.getSymbols.R
===================================================================
--- pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.getSymbols.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -1,45 +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
-
-Sys.setenv(TZ="UTC")
-
-.from='2002-10-21'
-#.to='2008-07-04'
-.to='2002-10-31'
-
-### 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'),
- 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)
-
Deleted: pkg/quantstrat/demo/luxor.include.R
===================================================================
--- pkg/quantstrat/demo/luxor.include.R 2013-05-05 16:28:54 UTC (rev 1455)
+++ pkg/quantstrat/demo/luxor.include.R 2013-05-07 20:45:41 UTC (rev 1456)
@@ -1,27 +0,0 @@
-###
-
-initDate = '2002-10-21'
-
-strategy.st = 'luxor'
-portfolio.st = 'forex'
-account.st = 'IB1'
-
-###
-
-.fast = 1
-.slow = 44
-
-.timespan = 'T08:00/T12:00'
-.timespan = 'T00:00/T23:59'
-
-.stoploss = 0.001
-.stoptrailing = 0.0015
-.takeprofit = 0.003
-
-###
-
-.orderqty = 100000
-.threshold = 0.0005
-.txnfees = -30
-
-###
More information about the Blotter-commits
mailing list