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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 10 16:47:18 CEST 2012


Author: opentrades
Date: 2012-07-10 16:47:17 +0200 (Tue, 10 Jul 2012)
New Revision: 1105

Added:
   pkg/quantstrat/demo/luxor.R
Removed:
   pkg/quantstrat/demo/luxor.R
   pkg/quantstrat/demo/luxor.p3_2.R
Modified:
   pkg/quantstrat/demo/luxorParameters.R
Log:
added new versions for luxor.R and luxorParameters.R



Deleted: pkg/quantstrat/demo/luxor.R
===================================================================
--- pkg/quantstrat/demo/luxor.R	2012-07-10 02:39:31 UTC (rev 1104)
+++ pkg/quantstrat/demo/luxor.R	2012-07-10 14:47:17 UTC (rev 1105)
@@ -1,175 +0,0 @@
-#!/usr/bin/Rscript --vanilla
-#
-# Jan Humme (@opentrades) - June 2012
-#
-# Tested and found to work correctly using blotter r1082
-#
-# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
-#
-# Paragraph 3.2: luxor without any optimizations, but with $30 tnx costs + slippage
-
-.qty=100000
-.th=0.0005
-.txn=-30
-#.txn=0
-
-initDate = '2002-10-21'
-.from='2002-10-21'
-#.to='2008-07-04'
-.to='2002-10-31'
-#.to='2003-12-31'
-
-####
-
-s = 'luxor'
-p = 'forex'
-a = 'IB1'
-
-options(width = 240)
-#Sys.setenv(TZ="GMT")
-
-###
-
-require(quantstrat)
-
-currency(c('GBP', 'USD'))
-
-exchange_rate(c('GBPUSD'), tick_size=0.0001)
-
-#setSymbolLookup.FI('~/R.symbols/', 'GBPUSD')
-setSymbolLookup.FI('../sandbox/', 'GBPUSD')
-
-###
-
-getSymbols('GBPUSD', from=.from, to=.to, verbose=FALSE)
-GBPUSD = to.minutes30(GBPUSD)
-GBPUSD = align.time(to.minutes30(GBPUSD), 1800)
-
-###
-
-initPortf(p, symbols='GBPUSD', initDate=initDate, currency='USD')
-initAcct(a, portfolios=p, initDate=initDate, currency='USD')
-
-###
-
-initOrders(p, initDate=initDate)
-
-### strategy ######################################################################
-
-strategy(s, store=TRUE)
-
-### indicators
-
-add.indicator(s, name = "SMA",
-	arguments = list(
-		x = quote(Cl(mktdata)),
-		n = 10
-	),
-	label="nFast"
-)
-
-add.indicator(s, name="SMA",
-	arguments = list(
-		x = quote(Cl(mktdata)),
-		n = 30
-	),
-	label="nSlow"
-)
-
-### signals
-
-add.signal(s, 'sigCrossover',
-	arguments = list(
-		columns=c("nFast","nSlow"),
-		relationship="gte"
-	),
-	label='long'
-)
-
-add.signal(s, 'sigCrossover',
-	arguments = list(
-		columns=c("nFast","nSlow"),
-		relationship="lt"
-	),
-	label='short'
-)
-
-### rules
-
-add.rule(s, 'ruleSignal',
-	arguments=list(sigcol='long' , sigval=TRUE,
-		replace=TRUE,
-		orderside='short',
-		ordertype='market',
-		TxnFees=.txn,
-		orderqty='all',
-		orderset='ocoshort'
-	),
-	type='exit',
-	label='Exit2LONG'
-)
-
-add.rule(s, 'ruleSignal',
-	arguments=list(sigcol='short', sigval=TRUE,
-		replace=TRUE,
-		orderside='long' ,
-		ordertype='market',
-		TxnFees=.txn,
-		orderqty='all',
-		orderset='ocolong'
-	),
-	type='exit',
-	label='Exit2SHORT')
-
-add.rule(s, 'ruleSignal',
-	arguments=list(sigcol='long' , sigval=TRUE,
-		replace=FALSE,
-		orderside='long' ,
-		ordertype='stoplimit',
-		prefer='High',
-		threshold=.th,
-		TxnFees=0,
-		orderqty=+.qty,
-		orderset='ocolong'
-	),
-	type='enter',
-	label='EnterLONG'
-)
-
-add.rule(s, 'ruleSignal',
-	arguments=list(sigcol='short', sigval=TRUE,
-		replace=FALSE,
-		orderside='short',
-		ordertype='stoplimit',
-		prefer='Low',
-		threshold=-.th,
-		TxnFees=0,
-		orderqty=-.qty,
-		orderset='ocoshort'
-	),
-	type='enter',
-	label='EnterSHORT'
-)
-
-#
-
-###############################################################################
-
-#applyStrategy(s, p, verbose = FALSE)
-applyStrategy(s, p, prefer='Open', verbose = FALSE)
-
-updatePortf(p, Symbols='GBPUSD', ,Dates=paste('::',as.Date(Sys.time()),sep=''))
-
-###############################################################################
-
-chart.Posn(p, "GBPUSD")
-
-print(getOrderBook(p))
-
-txns <- getTxns(p, 'GBPUSD')
-txns
-##txns$Net 
-cat('Net profit:', sum(txns$Net.Txn.Realized.PL), '\n')
-
-tradeStats(p, 'GBPUSD')
-

Added: pkg/quantstrat/demo/luxor.R
===================================================================
--- pkg/quantstrat/demo/luxor.R	                        (rev 0)
+++ pkg/quantstrat/demo/luxor.R	2012-07-10 14:47:17 UTC (rev 1105)
@@ -0,0 +1,177 @@
+#!/usr/bin/Rscript --vanilla
+#
+# Jan Humme (@opentrades) - June 2012
+#
+# Tested and found to work correctly using blotter r1082
+#
+# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
+#
+# Paragraph 3.2: luxor without any optimizations, but with $30 tnx costs + slippage
+
+.fast = 1
+.slow = 44
+
+.qty=100000
+.th=0.0005
+.txn=-30
+#.txn=0
+
+initDate = '2002-10-21'
+.from='2002-10-21'
+.to='2008-07-04'
+#.to='2003-12-31'
+
+####
+
+s = 'luxor'
+p = 'forex'
+a = 'IB1'
+
+options(width = 240)
+#Sys.setenv(TZ="GMT")
+
+###
+
+require(quantstrat)
+
+currency(c('GBP', 'USD'))
+
+exchange_rate(c('GBPUSD'), tick_size=0.0001)
+
+setSymbolLookup.FI('~/R.symbols/', 'GBPUSD')
+#setSymbolLookup.FI('../sandbox/', 'GBPUSD')
+
+###
+
+getSymbols('GBPUSD', from=.from, to=.to, verbose=FALSE)
+GBPUSD = to.minutes30(GBPUSD)
+GBPUSD = align.time(to.minutes30(GBPUSD), 1800)
+
+###
+
+initPortf(p, symbols='GBPUSD', initDate=initDate, currency='USD')
+initAcct(a, portfolios=p, initDate=initDate, currency='USD')
+
+###
+
+initOrders(p, initDate=initDate)
+
+### strategy ######################################################################
+
+strategy(s, store=TRUE)
+
+### indicators
+
+add.indicator(s, name = "SMA",
+	arguments = list(
+		x = quote(Cl(mktdata)),
+		n = .fast
+	),
+	label="nFast"
+)
+
+add.indicator(s, name="SMA",
+	arguments = list(
+		x = quote(Cl(mktdata)),
+		n = .slow
+	),
+	label="nSlow"
+)
+
+### signals
+
+add.signal(s, 'sigCrossover',
+	arguments = list(
+		columns=c("nFast","nSlow"),
+		relationship="gte"
+	),
+	label='long'
+)
+
+add.signal(s, 'sigCrossover',
+	arguments = list(
+		columns=c("nFast","nSlow"),
+		relationship="lt"
+	),
+	label='short'
+)
+
+### rules
+
+add.rule(s, 'ruleSignal',
+	arguments=list(sigcol='long' , sigval=TRUE,
+		replace=TRUE,
+		orderside='short',
+		ordertype='market',
+		TxnFees=.txn,
+		orderqty='all',
+		orderset='ocoshort'
+	),
+	type='exit',
+	label='Exit2LONG'
+)
+
+add.rule(s, 'ruleSignal',
+	arguments=list(sigcol='short', sigval=TRUE,
+		replace=TRUE,
+		orderside='long' ,
+		ordertype='market',
+		TxnFees=.txn,
+		orderqty='all',
+		orderset='ocolong'
+	),
+	type='exit',
+	label='Exit2SHORT')
+
+add.rule(s, 'ruleSignal',
+	arguments=list(sigcol='long' , sigval=TRUE,
+		replace=FALSE,
+		orderside='long' ,
+		ordertype='stoplimit',
+		prefer='High',
+		threshold=.th,
+		TxnFees=0,
+		orderqty=+.qty,
+		orderset='ocolong'
+	),
+	type='enter',
+	label='EnterLONG'
+)
+
+add.rule(s, 'ruleSignal',
+	arguments=list(sigcol='short', sigval=TRUE,
+		replace=FALSE,
+		orderside='short',
+		ordertype='stoplimit',
+		prefer='Low',
+		threshold=-.th,
+		TxnFees=0,
+		orderqty=-.qty,
+		orderset='ocoshort'
+	),
+	type='enter',
+	label='EnterSHORT'
+)
+
+#
+
+###############################################################################
+
+applyStrategy(s, p, verbose = FALSE)
+#applyStrategy(s, p, prefer='Open', verbose = FALSE)
+
+updatePortf(p, Symbols='GBPUSD', ,Dates=paste('::',as.Date(Sys.time()),sep=''))
+
+###############################################################################
+
+chart.Posn(p, "GBPUSD")
+
+print(getOrderBook(p))
+
+txns <- getTxns(p, 'GBPUSD')
+txns
+##txns$Net 
+cat('Net profit:', sum(txns$Net.Txn.Realized.PL), '\n')
+
+tradeStats(p, 'GBPUSD')
+


Property changes on: pkg/quantstrat/demo/luxor.R
___________________________________________________________________
Added: svn:executable
   + *

Deleted: pkg/quantstrat/demo/luxor.p3_2.R
===================================================================
--- pkg/quantstrat/demo/luxor.p3_2.R	2012-07-10 02:39:31 UTC (rev 1104)
+++ pkg/quantstrat/demo/luxor.p3_2.R	2012-07-10 14:47:17 UTC (rev 1105)
@@ -1,174 +0,0 @@
-#!/usr/bin/Rscript --vanilla
-#
-# Jan Humme (@opentrades) - June 2012
-#
-# Tested and found to work correctly using blotter r1082
-#
-# From Jaekle & Tamasini: A new approach to system development and portfolio optimisation (ISBN 978-1-905641-79-6)
-#
-# Paragraph 3.2: luxor without any optimizations, but with $30 tnx costs + slippage
-
-.qty=100000
-.th=0.0005
-.txn=-30
-#.txn=0
-
-initDate = '2002-10-21'
-#.from='2002-10-21'
-.from='2002-10-21'
-#.to='2008-07-04'
-.to='2002-10-31'
-
-####
-
-p = 'forex'
-a = 'IB1'
-
-options(width = 240)
-#Sys.setenv(TZ="GMT")
-
-###
-
-require(quantstrat)
-
-currency(c('GBP', 'USD'))
-
-exchange_rate(c('GBPUSD'), tick_size=0.0001)
-
-#setSymbolLookup.FI('~/R.symbols/', 'GBPUSD')
-setSymbolLookup.FI('../sandbox/', '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 ######################################################################
-
-s <- strategy(p)
-
-### indicators
-
-s <- add.indicator(s, name = "SMA",
-	arguments = list(
-		x = quote(Cl(mktdata)),
-		n = 10
-	),
-	label="SmaFAST"
-)
-
-s <- add.indicator(s, name="SMA",
-	arguments = list(
-		x = quote(Cl(mktdata)),
-		n=30
-	),
-	label="SmaSLOW"
-)
-
-### signals
-
-s <- add.signal(s, 'sigCrossover',
-	arguments = list(
-		columns=c("SmaFAST","SmaSLOW"),
-		relationship="gte"
-	),
-	label='long'
-)
-
-s <- add.signal(s, 'sigCrossover',
-	arguments = list(
-		columns=c("SmaFAST","SmaSLOW"),
-		relationship="lt"
-	),
-	label='short'
-)
-
-### rules
-
-s <- add.rule(s, 'ruleSignal',
-	arguments=list(sigcol='long' , sigval=TRUE,
-		replace=TRUE,
-		orderside='short',
-		ordertype='market',
-		TxnFees=.txn,
-		orderqty='all',
-		orderset='ocoshort'
-	),
-	type='exit',
-	label='Exit2LONG'
-)
-
-s <- add.rule(s, 'ruleSignal',
-	arguments=list(sigcol='short', sigval=TRUE,
-		replace=TRUE,
-		orderside='long' ,
-		ordertype='market',
-		TxnFees=.txn,
-		orderqty='all',
-		orderset='ocolong'
-	),
-	type='exit',
-	label='Exit2SHORT')
-
-s <- add.rule(s, 'ruleSignal',
-	arguments=list(sigcol='long' , sigval=TRUE,
-		replace=FALSE,
-		orderside='long' ,
-		ordertype='stoplimit',
-		prefer='High',
-		threshold=.th,
-		TxnFees=0,
-		orderqty=+.qty,
-		orderset='ocolong'
-	),
-	type='enter',
-	label='EnterLONG'
-)
-
-s <- add.rule(s, 'ruleSignal',
-	arguments=list(sigcol='short', sigval=TRUE,
-		replace=FALSE,
-		orderside='short',
-		ordertype='stoplimit',
-		prefer='Low',
-		threshold=-.th,
-		TxnFees=0,
-		orderqty=-.qty,
-		orderset='ocoshort'
-	),
-	type='enter',
-	label='EnterSHORT'
-)
-
-#
-
-###############################################################################
-
-#applyStrategy(s, p, prefer='Open', verbose = FALSE)
-applyStrategy(s, p, verbose = FALSE)
-
-updatePortf(p, Symbols='GBPUSD', ,Dates=paste('::',as.Date(Sys.time()),sep=''), Prices=GBPUSD)
-
-###############################################################################
-
-chart.Posn(p, "GBPUSD")
-
-print(getOrderBook(p))
-
-txns <- getTxns(p, 'GBPUSD')
-txns
-##txns$Net 
-cat('Net profit:', sum(txns$Net.Txn.Realized.PL), '\n')
-
-tradeStats(p, 'GBPUSD')
-

Modified: pkg/quantstrat/demo/luxorParameters.R
===================================================================
--- pkg/quantstrat/demo/luxorParameters.R	2012-07-10 02:39:31 UTC (rev 1104)
+++ pkg/quantstrat/demo/luxorParameters.R	2012-07-10 14:47:17 UTC (rev 1105)
@@ -3,9 +3,17 @@
 #verbose = 0
 verbose = 1
 
+#method='expand'
+method='random'
+.sampleSize=20
+
+.fastRange=(1:20)
+.slowRange=(21:80)
+
+###############################################################################
+
 #require(foreach,quietly=TRUE)
 require(doMC)
-
 require(quantstrat)
 
 portfolio.st = 'forex'
@@ -17,24 +25,41 @@
 parameterTable<-getParameterTable(s)
 #parameterTable
 
-tPD2<-setParameterDistribution(type = 'indicator', indexnum = 1, distribution = list(nFast = (1:20)), label = 'nFast')
-tPD2<-setParameterDistribution(tPD2, type = 'indicator', indexnum = 2, distribution = list(nSlow = (21:50)), label = 'nSlow')
+tPD2<-setParameterDistribution(type = 'indicator', indexnum = 1, distribution = list(nFast = .fastRange), label = 'nFast')
+tPD2<-setParameterDistribution(tPD2, type = 'indicator', indexnum = 2, distribution = list(nSlow = .slowRange), label = 'nSlow')
 
 pConstraint2<-setParameterConstraint(constraintLabel='luxorPC',paramList=c('nFast','nSlow'),relationship='lt')
 
 registerDoMC(cores=2)
 
-# Please run either random mode or expand mode, since the latter run will overwrite the objects in .blotter.
-laststpar.rnd<-system.time(
-		testPackListPL<-applyParameter(strategy=s,portfolios=portfolio.st,parameterPool=tPD2,method='random',sampleSize=20,parameterConstraints=pConstraint2)
-)
-if(verbose >=1) laststpar.rnd
+if(method == 'random')
+{
+	laststpar.rnd<-system.time(
+			testPackListPL<-applyParameter(
+				strategy=s,
+				portfolios=portfolio.st,
+				parameterPool=tPD2,
+				method='random',
+				sampleSize=.sampleSize,
+				parameterConstraints=pConstraint2
+			)
+	)
+	if(verbose >=1) laststpar.rnd
+}
 
-# Please run either random mode or expand mode, since the latter run will overwrite the objects in .blotter.
-#laststpar.exp<-system.time(
-#		testPackListPL<-applyParameter(strategy=s,portfolios=portfolio.st,parameterPool=tPD2,method='expand',sampleSize=20,parameterConstrains=pConstraint2)
-#)
-#if(verbose >=1) print(laststpar.exp)
+if(method == 'expand')
+{
+	laststpar.exp<-system.time(
+			testPackListPL<-applyParameter(
+				strategy=s,
+				portfolios=portfolio.st,
+				parameterPool=tPD2,
+				method='expand',
+				parameterConstraints=pConstraint2
+			)
+	)
+	if(verbose >=1) print(laststpar.exp)
+}
 
 #examine the stats from this parameter run:
 if(verbose >=1) print(testPackListPL$statsTable)



More information about the Blotter-commits mailing list