[Blotter-commits] r1438 - pkg/quantstrat/demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Apr 18 22:26:38 CEST 2013
Author: opentrades
Date: 2013-04-18 22:26:38 +0200 (Thu, 18 Apr 2013)
New Revision: 1438
Added:
pkg/quantstrat/demo/luxor.3.optimize.sma.R
pkg/quantstrat/demo/luxor.symbols.R
Removed:
pkg/quantstrat/demo/luxor.3.Parameters.R
pkg/quantstrat/demo/luxor.3.R
Modified:
pkg/quantstrat/demo/luxor.1.strategy.R
Log:
- added luxor.3.optimize.sma.R to apply.paramset() on SMA, using new apply.paramset() instead of old applyParameters()
- removed old luxor.3.Parameters.R and luxor.3.R
- introduced luxor.symbols.R to fetch symbol data
- adjusted luxor.1.strategy.R and luxor.3.optimize.sma.R accordingly
Modified: pkg/quantstrat/demo/luxor.1.strategy.R
===================================================================
--- pkg/quantstrat/demo/luxor.1.strategy.R 2013-04-18 20:08:22 UTC (rev 1437)
+++ pkg/quantstrat/demo/luxor.1.strategy.R 2013-04-18 20:26:38 UTC (rev 1438)
@@ -33,45 +33,14 @@
initDate = '2002-10-21'
-.from='2002-10-21'
-#.to='2008-07-04'
-.to='2002-10-31'
-
####
strategy.st = 'luxor'
portfolio.st = 'forex'
account.st = 'IB1'
-### packages
-#
-# quantstrat package will pull in some other packages:
-# FinancialInstrument, quantmod, blotter, xts
+source('luxor.symbols.R')
-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)
-
### blotter
initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
Deleted: pkg/quantstrat/demo/luxor.3.Parameters.R
===================================================================
--- pkg/quantstrat/demo/luxor.3.Parameters.R 2013-04-18 20:08:22 UTC (rev 1437)
+++ pkg/quantstrat/demo/luxor.3.Parameters.R 2013-04-18 20:26:38 UTC (rev 1438)
@@ -1,104 +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.3 Variation of the input parameters: optimisation and stability diagrams
-# uses luxor.3.R
-
-#verbose = 0
-verbose = 1
-
-method='expand'
-#method='random'
-#.sampleSize=8
-
-#.fastRange=(1:20)
-#.slowRange=(21:80)
-
-.fastRange=(41:45)
-.slowRange=(41:45)
-
-###############################################################################
-
-require(foreach,quietly=TRUE)
-#require(doMC)
-# 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'
-
-source('luxor.3.R')
-
-s<-getStrategy('luxor')
-
-#parameterTable<-getParameterTable(s)
-#parameterTable
-#stop()
-
-tPD2<-setParameterDistribution(strategy=s, component.type='indicator', component.label='nFast', distribution = list(nFast = .fastRange), label = 'nFast')
-tPD2<-setParameterDistribution(tPD2, strategy=s, component.type='indicator', component.label='nSlow', distribution = list(nSlow = .slowRange), label = 'nSlow')
-
-pConstraint2<-setParameterConstraint(constraintLabel='luxorPC',paramList=c('nFast','nSlow'),relationship='lt')
-
-registerDoMC(cores=2)
-
-if(method == 'random')
-{
- laststpar.rnd<-system.time(
- scan.results<-applyParameter(
- strategy=s,
- portfolios=portfolio.st,
- parameterPool=tPD2,
- method='random',
- sampleSize=.sampleSize,
- parameterConstraints=pConstraint2
- )
- )
- if(verbose >=1) laststpar.rnd
-}
-
-if(method == 'expand')
-{
- laststpar.exp<-system.time(
- scan.results<-applyParameter(
- strategy=s,
- portfolios=portfolio.st,
- parameterPool=tPD2,
- method='expand',
- parameterConstraints=pConstraint2
- )
- )
- if(verbose >=1) print(laststpar.exp)
-}
-
-#examine the stats from this parameter run:
-if(verbose >=1) print(scan.results$statsTable)
-
-stats <- scan.results$statsTable
-save(stats, file="luxor.parameters.RData")
-
-
-##### 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.R
===================================================================
--- pkg/quantstrat/demo/luxor.3.R 2013-04-18 20:08:22 UTC (rev 1437)
+++ pkg/quantstrat/demo/luxor.3.R 2013-04-18 20:26:38 UTC (rev 1438)
@@ -1,195 +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.3 Variation of the input parameters: optimisation and stability diagrams
-
-options(width = 240)
-#Sys.setenv(TZ="GMT")
-
-.fast = 1
-.slow = 44
-
-.qty=100000
-.th=0.0005
-.txn=-30
-
-##### 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'
-#.to='2002-12-31'
-
-####
-
-s = 'luxor'
-p = 'forex'
-a = 'IB1'
-
-###
-
-require(quantstrat)
-
-currency(c('GBP', 'USD'))
-
-exchange_rate(c('GBPUSD'), tick_size=0.0001)
-
-setSymbolLookup.FI(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 ######################################################################
-
-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")
-add_SMA(n=.slow,col='darkblue',on=1)
-add_SMA(n=.fast,col='lightblue',on=1)
-
-View(getOrderBook(p)$forex$GBPUSD)
-
-#txns <- getTxns(p, 'GBPUSD')
-#txns
-###txns$Net
-#cat('Net profit:', sum(txns$Net.Txn.Realized.PL), '\n')
-
-View(tradeStats(p, 'GBPUSD'))
-
-##### PLACE THIS BLOCK AT END OF DEMO SCRIPT ###################
-# book = getOrderBook(port)
-# stats = tradeStats(port)
-# rets = PortfReturns(acct)
-################################################################
Added: pkg/quantstrat/demo/luxor.3.optimize.sma.R
===================================================================
--- pkg/quantstrat/demo/luxor.3.optimize.sma.R (rev 0)
+++ pkg/quantstrat/demo/luxor.3.optimize.sma.R 2013-04-18 20:26:38 UTC (rev 1438)
@@ -0,0 +1,56 @@
+#!/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)
+
Property changes on: pkg/quantstrat/demo/luxor.3.optimize.sma.R
___________________________________________________________________
Added: svn:executable
+ *
Added: pkg/quantstrat/demo/luxor.symbols.R
===================================================================
--- pkg/quantstrat/demo/luxor.symbols.R (rev 0)
+++ pkg/quantstrat/demo/luxor.symbols.R 2013-04-18 20:26:38 UTC (rev 1438)
@@ -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)
+
More information about the Blotter-commits
mailing list