[Blotter-commits] r1448 - pkg/quantstrat/demo

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 24 21:52:23 CEST 2013


Author: opentrades
Date: 2013-04-24 21:52:23 +0200 (Wed, 24 Apr 2013)
New Revision: 1448

Added:
   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
Removed:
   pkg/quantstrat/demo/luxor-3.11.R
   pkg/quantstrat/demo/luxor-3.12.R
   pkg/quantstrat/demo/luxor-3.16.R
   pkg/quantstrat/demo/luxor.symbols.R
Modified:
   pkg/quantstrat/demo/luxor.1.strategy.R
   pkg/quantstrat/demo/luxor.3.paramset.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
Log:
- various improvements to luxor demos



Deleted: pkg/quantstrat/demo/luxor-3.11.R
===================================================================
--- pkg/quantstrat/demo/luxor-3.11.R	2013-04-24 16:00:39 UTC (rev 1447)
+++ pkg/quantstrat/demo/luxor-3.11.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -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-3.12.R
===================================================================
--- pkg/quantstrat/demo/luxor-3.12.R	2013-04-24 16:00:39 UTC (rev 1447)
+++ pkg/quantstrat/demo/luxor-3.12.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -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-3.16.R
===================================================================
--- pkg/quantstrat/demo/luxor-3.16.R	2013-04-24 16:00:39 UTC (rev 1447)
+++ pkg/quantstrat/demo/luxor-3.16.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -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)
-################################################################

Modified: pkg/quantstrat/demo/luxor.1.strategy.R
===================================================================
--- pkg/quantstrat/demo/luxor.1.strategy.R	2013-04-24 16:00:39 UTC (rev 1447)
+++ pkg/quantstrat/demo/luxor.1.strategy.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -16,10 +16,6 @@
 .fast = 10
 .slow = 30
 
-.orderqty = 100000
-.threshold = 0.0005
-.txn.fees = -30
-
 ##### PLACE DEMO AND TEST DATES HERE #################
 #
 #if(isTRUE(options('in_test')$in_test))
@@ -31,16 +27,9 @@
 #  {initDate="1999-12-31"
 #  endDate=Sys.Date()}
 
-initDate = '2002-10-21'
+source('luxor.include.R')
+source('luxor.getSymbols.R')
 
-####
-
-strategy.st = 'luxor'
-portfolio.st = 'forex'
-account.st = 'IB1'
-
-source('luxor.symbols.R')
-
 ### blotter
 
 initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
@@ -97,7 +86,7 @@
 		orderside='short',
 		ordertype='market',
 		orderqty='all',
-		TxnFees=.txn.fees,
+		TxnFees=.txnfees,
 		replace=TRUE
 	),
 	type='exit',
@@ -109,7 +98,7 @@
 		orderside='long' ,
 		ordertype='market',
 		orderqty='all',
-		TxnFees=.txn.fees,
+		TxnFees=.txnfees,
 		replace=TRUE
 	),
 	type='exit',

Modified: pkg/quantstrat/demo/luxor.3.paramset.sma.R
===================================================================
--- pkg/quantstrat/demo/luxor.3.paramset.sma.R	2013-04-24 16:00:39 UTC (rev 1447)
+++ pkg/quantstrat/demo/luxor.3.paramset.sma.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -15,16 +15,9 @@
 
 ###
 
-initDate = '2002-10-21'
+source('luxor.include.R')
+source('luxor.getSymbols.R')
 
-####
-
-strategy.st = 'luxor'
-portfolio.st = 'forex'
-account.st = 'IB1'
-
-source('luxor.symbols.R')
-
 ### blotter
 
 initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')

Modified: pkg/quantstrat/demo/luxor.5.orderchains.R
===================================================================
--- pkg/quantstrat/demo/luxor.5.orderchains.R	2013-04-24 16:00:39 UTC (rev 1447)
+++ pkg/quantstrat/demo/luxor.5.orderchains.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -10,19 +10,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))
@@ -34,71 +21,47 @@
 #  {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)
+source('luxor.include.R')
+source('luxor.getSymbols.R')
 
-currency(c('GBP', 'USD'))
+### blotter
 
-exchange_rate(c('GBPUSD'), tick_size=0.0001)
+initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
+initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
 
-setSymbolLookup.FI(system.file('extdata',package='quantstrat'), 'GBPUSD')
+### quantstrat
 
-###
+initOrders(portfolio.st, initDate=initDate)
 
-getSymbols('GBPUSD', from=.from, to=.to, verbose=FALSE)
-GBPUSD = to.minutes30(GBPUSD)
-GBPUSD = align.time(to.minutes30(GBPUSD), 1800)
+### define strategy
 
-###
-
-initPortf(p, symbols='GBPUSD', initDate=initDate, currency='USD')
-initAcct(a, portfolios=p, initDate=initDate, currency='USD')
-
-###
-
-initOrders(p, initDate=initDate)
-
-### strategy ######################################################################
-
 addPosLimit(
-            portfolio=p,
+            portfolio=portfolio.st,
             symbol='GBPUSD',
             timestamp=initDate,
-            maxpos=.qty)
+            maxpos=.orderqty)
 
-strategy(s, store=TRUE)
+strategy(strategy.st, store=TRUE)
 
 ### indicators
 
-add.indicator(s, name = "SMA",
+add.indicator(strategy.st, name = "SMA",
 	arguments = list(
-		x = quote(Cl(mktdata)),
+		x = quote(Cl(mktdata)[,1]),
 		n = .fast
 	),
 	label="nFast"
 )
 
-add.indicator(s, name="SMA",
+add.indicator(strategy.st, name="SMA",
 	arguments = list(
-		x = quote(Cl(mktdata)),
+		x = quote(Cl(mktdata)[,1]),
 		n = .slow
 	),
 	label="nSlow"
@@ -106,7 +69,7 @@
 
 ### signals
 
-add.signal(s, name = 'sigCrossover',
+add.signal(strategy.st, name='sigCrossover',
 	arguments = list(
 		columns=c("nFast","nSlow"),
 		relationship="gte"
@@ -114,7 +77,7 @@
 	label='long'
 )
 
-add.signal(s, name = 'sigCrossover',
+add.signal(strategy.st, name='sigCrossover',
 	arguments = list(
 		columns=c("nFast","nSlow"),
 		relationship="lt"
@@ -126,36 +89,34 @@
 
 ### stop-loss
 
-add.rule(s, name = 'ruleSignal',
+add.rule(strategy.st, name = 'ruleSignal',
 	arguments=list(sigcol='long' , sigval=TRUE,
 		replace=FALSE,
 		orderside='long',
 		ordertype='stoplimit',
 		tmult=TRUE,
 		threshold=.stoploss,
-		TxnFees=.txn,
+		TxnFees=.txnfees,
 		orderqty='all',
 		orderset='ocolong'
 	),
-	type='chain',
-	parent='EnterLONG',
+	type='chain', parent='EnterLONG',
 	label='StopLossLONG',
 	storefun=FALSE
 )
 
-add.rule(s, name = 'ruleSignal',
+add.rule(strategy.st, name = 'ruleSignal',
 	arguments=list(sigcol='short' , sigval=TRUE,
 		replace=FALSE,
 		orderside='short',
 		ordertype='stoplimit',
 		tmult=TRUE,
 		threshold=.stoploss,
-		TxnFees=.txn,
+		TxnFees=.txnfees,
 		orderqty='all',
 		orderset='ocoshort'
 	),
-	type='chain',
-	parent='EnterSHORT',
+	type='chain', parent='EnterSHORT',
 	label='StopLossSHORT',
 	storefun=FALSE
 )
@@ -164,36 +125,34 @@
 
 if(TRUE)
 {
-add.rule(s, name = 'ruleSignal',
+add.rule(strategy.st, name = 'ruleSignal',
 	arguments=list(sigcol='long' , sigval=TRUE,
 		replace=FALSE,
 		orderside='long',
 		ordertype='stoptrailing',
 		tmult=TRUE,
 		threshold=.stoptrailing,
-		TxnFees=.txn,
+		TxnFees=.txnfees,
 		orderqty='all',
 		orderset='ocolong'
 	),
-	type='chain',
-	parent='EnterLONG',
+	type='chain', parent='EnterLONG',
 	label='StopTrailingLONG',
 	storefun=FALSE
 )
 
-add.rule(s, name = 'ruleSignal',
+add.rule(strategy.st, name = 'ruleSignal',
 	arguments=list(sigcol='short' , sigval=TRUE,
 		replace=FALSE,
 		orderside='short',
 		ordertype='stoptrailing',
 		tmult=TRUE,
 		threshold=.stoptrailing,
-		TxnFees=.txn,
+		TxnFees=.txnfees,
 		orderqty='all',
 		orderset='ocoshort'
 	),
-	type='chain',
-	parent='EnterSHORT',
+	type='chain', parent='EnterSHORT',
 	label='StopTrailingSHORT',
 	storefun=FALSE
 )
@@ -201,48 +160,46 @@
 
 ### take-profit
 
-add.rule(s, name = 'ruleSignal',
+add.rule(strategy.st, name = 'ruleSignal',
 	arguments=list(sigcol='long' , sigval=TRUE,
 		replace=FALSE,
 		orderside='long',
 		ordertype='limit',
 		tmult=TRUE,
 		threshold=.takeprofit,
-		TxnFees=.txn,
+		TxnFees=.txnfees,
 		orderqty='all',
 		orderset='ocolong'
 	),
-	type='chain',
-	parent='EnterLONG',
+	type='chain', parent='EnterLONG',
 	label='TakeProfitLONG',
 	storefun=FALSE
 )
 
-add.rule(s, name = 'ruleSignal',
+add.rule(strategy.st, name = 'ruleSignal',
 	arguments=list(sigcol='short' , sigval=TRUE,
 		replace=FALSE,
 		orderside='short',
 		ordertype='limit',
 		tmult=TRUE,
 		threshold=.takeprofit,
-		TxnFees=.txn,
+		TxnFees=.txnfees,
 		orderqty='all',
 		orderset='ocoshort'
 	),
-	type='chain',
-	parent='EnterSHORT',
+	type='chain', parent='EnterSHORT',
 	label='TakeProfitSHORT',
 	storefun=FALSE
 )
 
 ### 
 
-add.rule(s, name = 'ruleSignal',
+add.rule(strategy.st, name = 'ruleSignal',
 	arguments=list(sigcol='long' , sigval=TRUE,
 		replace=TRUE,
 		orderside='short',
 		ordertype='market',
-		TxnFees=.txn,
+		TxnFees=.txnfees,
 		orderqty='all',
 		orderset='ocoshort'
 	),
@@ -252,12 +209,12 @@
 	storefun=FALSE
 )
 
-add.rule(s, name = 'ruleSignal',
+add.rule(strategy.st, name = 'ruleSignal',
 	arguments=list(sigcol='short', sigval=TRUE,
 		replace=TRUE,
 		orderside='long' ,
 		ordertype='market',
-		TxnFees=.txn,
+		TxnFees=.txnfees,
 		orderqty='all',
 		orderset='ocolong'
 	),
@@ -267,15 +224,15 @@
 	storefun=FALSE
 )
 
-add.rule(s, name = 'ruleSignal',
+add.rule(strategy.st, name = 'ruleSignal',
 	arguments=list(sigcol='long' , sigval=TRUE,
 		replace=FALSE,
 		orderside='long' ,
 		ordertype='stoplimit',
 		prefer='High',
-		threshold=.th,
+		threshold=.threshold,
 		TxnFees=0,
-		orderqty=+.qty,
+		orderqty=+.orderqty,
 		osFUN=osMaxPos,
 		orderset='ocolong'
 	),
@@ -285,15 +242,15 @@
 	storefun=FALSE
 )
 
-add.rule(s, name = 'ruleSignal',
+add.rule(strategy.st, name = 'ruleSignal',
 	arguments=list(sigcol='short', sigval=TRUE,
 		replace=FALSE,
 		orderside='short',
 		ordertype='stoplimit',
 		prefer='Low',
-		threshold=.th,
+		threshold=.threshold,
 		TxnFees=0,
-		orderqty=-.qty,
+		orderqty=-.orderqty,
 		osFUN=osMaxPos,
 		orderset='ocoshort'
 	),
@@ -307,24 +264,26 @@
 
 ###############################################################################
 
-applyStrategy(s, p, verbose = FALSE)
-#applyStrategy(s, p, prefer='Open', verbose = FALSE)
+applyStrategy(strategy.st, portfolio.st, verbose = FALSE)
+#applyStrategy(strategy.st, p, prefer='Open', verbose = FALSE)
 
-updatePortf(p, Symbols='GBPUSD', ,Dates=paste('::',as.Date(Sys.time()),sep=''))
+updatePortf(portfolio.st, Symbols='GBPUSD', ,Dates=paste('::',as.Date(Sys.time()),sep=''))
 
 ###############################################################################
 
-chart.Posn(p, "GBPUSD")
+chart.Posn(portfolio.st, "GBPUSD")
 
-print(getOrderBook(p))
+print(getOrderBook(portfolio.st))
 
-#txns <- getTxns(p, 'GBPUSD')
+#txns <- getTxns(portfolio.st, 'GBPUSD')
 #txns
 ##txns$Net 
 #cat('Net profit:', sum(txns$Net.Txn.Realized.PL), '\n')
 
-print(tradeStats(p, 'GBPUSD'))
+print(tradeStats(portfolio.st, 'GBPUSD'))
 
+save.strategy(strategy.st)
+
 ##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ################### 
 # book  = getOrderBook(port)
 # stats = tradeStats(port)

Modified: pkg/quantstrat/demo/luxor.6.paramset.stoploss.R
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.stoploss.R	2013-04-24 16:00:39 UTC (rev 1447)
+++ pkg/quantstrat/demo/luxor.6.paramset.stoploss.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -13,15 +13,6 @@
 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))
@@ -33,24 +24,17 @@
 #  {initDate="1999-12-31"
 #  endDate=Sys.Date()}
 
-initDate = '2002-10-21'
+source('luxor.include.R')
+source('luxor.getSymbols.R')
 
-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)
+            maxpos=.orderqty)
 
 initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
 

Modified: pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R	2013-04-24 16:00:39 UTC (rev 1447)
+++ pkg/quantstrat/demo/luxor.6.paramset.stoptrailing.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -13,15 +13,6 @@
 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))
@@ -33,22 +24,17 @@
 #  {initDate="1999-12-31"
 #  endDate=Sys.Date()}
 
-initDate = '2002-10-21'
+source('luxor.include.R')
+source('luxor.getSymbols.R')
 
-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)
+            maxpos=.orderqty)
 
 initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
 

Modified: pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R
===================================================================
--- pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R	2013-04-24 16:00:39 UTC (rev 1447)
+++ pkg/quantstrat/demo/luxor.6.paramset.takeprofit.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -13,15 +13,6 @@
 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))
@@ -33,22 +24,17 @@
 #  {initDate="1999-12-31"
 #  endDate=Sys.Date()}
 
-initDate = '2002-10-21'
+source('luxor.include.R')
+source('luxor.getSymbols.R')
 
-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)
+            maxpos=.orderqty)
 
 initAcct(account.st, portfolios=portfolio.st, initDate=initDate, currency='USD')
 

Copied: pkg/quantstrat/demo/luxor.7.MAE.stoploss.R (from rev 1447, pkg/quantstrat/demo/luxor-3.11.R)
===================================================================
--- pkg/quantstrat/demo/luxor.7.MAE.stoploss.R	                        (rev 0)
+++ pkg/quantstrat/demo/luxor.7.MAE.stoploss.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -0,0 +1,35 @@
+#!/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)
+################################################################

Copied: pkg/quantstrat/demo/luxor.7.MAE.stoptrailing.R (from rev 1447, pkg/quantstrat/demo/luxor-3.12.R)
===================================================================
--- pkg/quantstrat/demo/luxor.7.MAE.stoptrailing.R	                        (rev 0)
+++ pkg/quantstrat/demo/luxor.7.MAE.stoptrailing.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -0,0 +1,35 @@
+#!/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)
+################################################################

Copied: pkg/quantstrat/demo/luxor.7.MFE.takeprofit.R (from rev 1447, pkg/quantstrat/demo/luxor-3.16.R)
===================================================================
--- pkg/quantstrat/demo/luxor.7.MFE.takeprofit.R	                        (rev 0)
+++ pkg/quantstrat/demo/luxor.7.MFE.takeprofit.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -0,0 +1,35 @@
+#!/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)
+################################################################

Copied: pkg/quantstrat/demo/luxor.getSymbols.R (from rev 1447, pkg/quantstrat/demo/luxor.symbols.R)
===================================================================
--- pkg/quantstrat/demo/luxor.getSymbols.R	                        (rev 0)
+++ pkg/quantstrat/demo/luxor.getSymbols.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -0,0 +1,45 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - August 2012, revised April 2013
+#
+# Tested and found to work correctly using blotter r1420
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# 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)
+

Added: pkg/quantstrat/demo/luxor.include.R
===================================================================
--- pkg/quantstrat/demo/luxor.include.R	                        (rev 0)
+++ pkg/quantstrat/demo/luxor.include.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -0,0 +1,27 @@
+###
+
+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
+
+###

Deleted: pkg/quantstrat/demo/luxor.symbols.R
===================================================================
--- pkg/quantstrat/demo/luxor.symbols.R	2013-04-24 16:00:39 UTC (rev 1447)
+++ pkg/quantstrat/demo/luxor.symbols.R	2013-04-24 19:52:23 UTC (rev 1448)
@@ -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)
-



More information about the Blotter-commits mailing list