[Blotter-commits] r1439 - pkg/quantstrat/demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Apr 18 22:34:28 CEST 2013
Author: opentrades
Date: 2013-04-18 22:34:27 +0200 (Thu, 18 Apr 2013)
New Revision: 1439
Added:
pkg/quantstrat/demo/luxor.3.sma.optimize.R
pkg/quantstrat/demo/luxor.3.sma.tradegraphs.R
Removed:
pkg/quantstrat/demo/luxor.3.Parameters.tradegraphs.R
pkg/quantstrat/demo/luxor.3.optimize.sma.R
pkg/quantstrat/demo/luxor.4.R
Log:
- adjusted more luxor demo code
Deleted: pkg/quantstrat/demo/luxor.3.Parameters.tradegraphs.R
===================================================================
--- pkg/quantstrat/demo/luxor.3.Parameters.tradegraphs.R 2013-04-18 20:26:38 UTC (rev 1438)
+++ pkg/quantstrat/demo/luxor.3.Parameters.tradegraphs.R 2013-04-18 20:34:27 UTC (rev 1439)
@@ -1,29 +0,0 @@
-#!/usr/bin/Rscript --vanilla
-
-require(quantstrat)
-
-load('../data/luxor.parameters.1-10.30-55.RData')
-
-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.3.optimize.sma.R
===================================================================
--- pkg/quantstrat/demo/luxor.3.optimize.sma.R 2013-04-18 20:26:38 UTC (rev 1438)
+++ pkg/quantstrat/demo/luxor.3.optimize.sma.R 2013-04-18 20:34:27 UTC (rev 1439)
@@ -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)
-
Copied: pkg/quantstrat/demo/luxor.3.sma.optimize.R (from rev 1438, pkg/quantstrat/demo/luxor.3.optimize.sma.R)
===================================================================
--- pkg/quantstrat/demo/luxor.3.sma.optimize.R (rev 0)
+++ pkg/quantstrat/demo/luxor.3.sma.optimize.R 2013-04-18 20:34:27 UTC (rev 1439)
@@ -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)
+
Copied: pkg/quantstrat/demo/luxor.3.sma.tradegraphs.R (from rev 1436, pkg/quantstrat/demo/luxor.3.Parameters.tradegraphs.R)
===================================================================
--- pkg/quantstrat/demo/luxor.3.sma.tradegraphs.R (rev 0)
+++ pkg/quantstrat/demo/luxor.3.sma.tradegraphs.R 2013-04-18 20:34:27 UTC (rev 1439)
@@ -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)
+################################################################
Deleted: pkg/quantstrat/demo/luxor.4.R
===================================================================
--- pkg/quantstrat/demo/luxor.4.R 2013-04-18 20:26:38 UTC (rev 1438)
+++ pkg/quantstrat/demo/luxor.4.R 2013-04-18 20:34:27 UTC (rev 1439)
@@ -1,210 +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
-
-options(width = 240)
-#Sys.setenv(TZ="GMT")
-
-.fast = 1
-.slow = 44
-
-.qty=100000
-.th=0.0005
-.txn=-30
-.timespan = 'T08:00/T12:00'
-
-##### 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'
-#.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
-
-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'
-)
-
-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')
-
-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'
-)
-
-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'
-)
-
-#
-
-###############################################################################
-
-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)
-################################################################
More information about the Blotter-commits
mailing list