[Blotter-commits] r1054 - pkg/quantstrat/demo
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jun 17 17:22:24 CEST 2012
Author: opentrades
Date: 2012-06-17 17:22:24 +0200 (Sun, 17 Jun 2012)
New Revision: 1054
Added:
pkg/quantstrat/demo/luxor.p3_2.R
Log:
added luxor demo first version (paragraph 3.2 of Jaekle / Tomasini)
Added: pkg/quantstrat/demo/luxor.p3_2.R
===================================================================
--- pkg/quantstrat/demo/luxor.p3_2.R (rev 0)
+++ pkg/quantstrat/demo/luxor.p3_2.R 2012-06-17 15:22:24 UTC (rev 1054)
@@ -0,0 +1,154 @@
+#!/usr/bin/Rscript --no-save
+#
+# Jan Humme (@opentrades) - June 2012
+#
+# 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
+
+.qty=100000
+.th=0.0005
+.txn=-6
+
+initDate = '2002-10-21'
+.from='2002-10-21'
+.to='2008-07-04'
+#.to='2002-10-30'
+
+####
+
+p = 'forex'
+a = 'IB1'
+
+###
+require(quantstrat)
+
+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=FALSE,
+ 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=FALSE,
+ 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=.txn,
+ 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=.txn,
+ orderqty=-.qty,
+ orderset='ocoshort'
+ ),
+ type='enter',
+ label='EnterSHORT'
+)
+
+#
+
+#summary(s)
+
+###############################################################################
+
+applyStrategy(s, p, prefer='Open', verbose = FALSE)
+#applyStrategy(s, p, verbose = FALSE)
+
+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.p3_2.R
___________________________________________________________________
Added: svn:executable
+ *
More information about the Blotter-commits
mailing list