[R-SIG-Finance] A simple variant of Luxor strategy with Dukascopy data
Tsvetan Stoyanov
tstoyc at gmail.com
Tue Sep 29 18:46:06 CEST 2015
Hi,
I am trying to replicate Table 3.1 in Jaekle&Tomasini using quantstrat and Dukascopy data.
While I have similar percentage of winning trades, net profit and drawdown are quite different.
For example, they have P&L of ~$66,000 while i get ~$19,500 for a period from 2003-05-04 to 2008-07-06
which is half a year shorter than their period.
It should not make such a difference I think, unless they used substantially different data.
The trade stats quantstrat code are included bellow, where I have set .threshold = 0.0001,
to reduce slippage and set .txnfees = 0.
I am new to quantstrat and will appreciate some help in reconciling this difference.
Thanks,
Tsvetan
> t(tradeStats(portfolio.st, 'GBPUSD'))
GBPUSD
Portfolio "luxor.simple"
Symbol "GBPUSD"
Num.Txns "4080"
Num.Trades "2038"
Net.Trading.PL "19486"
Avg.Trade.PL "9.561335"
Med.Trade.PL "-144.5"
Largest.Winner "4018"
Largest.Loser "-2002"
Gross.Profits "548109"
Gross.Losses "-528623"
Std.Dev.Trade.PL "753.0498"
Percent.Positive "37.43867"
Percent.Negative "62.56133"
Profit.Factor "1.036862"
Avg.Win.Trade "718.3604"
Med.Win.Trade "492.5"
Avg.Losing.Trade "-414.6063"
Med.Losing.Trade "-334"
Avg.Daily.PL "15.97213"
Med.Daily.PL "-113.5"
Std.Dev.Daily.PL "941.3955"
Ann.Sharpe "0.2693339"
Max.Drawdown "-20481"
Profit.To.Max.Draw "0.9514184"
Avg.WinLoss.Ratio "1.732633"
Med.WinLoss.Ratio "1.474551"
Max.Equity "29675.5"
Min.Equity "-11539"
End.Equity "19486”
————— luxor.simple.R --------------------
Sys.setenv(TZ="UTC")
library(quantstrat)
## ------------------------------------------------------------------------
initDate = '2003-05-04'
.from=initDate
##.to='2003-05-18' # 2 weeks
##.to='2003-07-27' # 12 weeks
##.to='2004-05-02' # 52 weeks
.to='2008-07-06' # 5 years
source('load.gbpusd.R') # load GBPUSD data
## setup
currency(c('GBP', 'USD'))
exchange_rate('GBPUSD', tick_size=0.0001)
## moving average lengths
.fast = 10
.slow = 30
# trade parameters
.threshold = 0.0001
.orderqty = 100000
.txnfees = 0 # round-trip fee
##
strategy.st = 'luxor.simple'
portfolio.st = strategy.st
account.st = strategy.st
## ------------------------------------------------------------------------
rm.strat(portfolio.st)
rm.strat(account.st)
## ----results='hide'------------------------------------------------------
initPortf(portfolio.st, symbols='GBPUSD', initDate=initDate, currency='USD')
initAcct(account.st, portfolios=portfolio.st,initDate=initDate,currency='USD')
initOrders(portfolio.st, initDate=initDate)
strategy(strategy.st, store=TRUE)
## ----results='hide'------------------------------------------------------
add.indicator(strategy.st, name = "SMA",
arguments = list(
x = quote(Cl(mktdata)[,1]),
n = .fast
),
label="nFast"
)
## ----results='hide'------------------------------------------------------
add.indicator(strategy.st, name="SMA",
arguments = list(
x = quote(Cl(mktdata)[,1]),
n = .slow
),
label="nSlow"
)
## ----results='hide'------------------------------------------------------
add.signal(strategy.st, name='sigCrossover',
arguments = list(
columns=c("nFast","nSlow"),
relationship="gte"
),
label='long'
)
## ----results='hide'------------------------------------------------------
add.signal(strategy.st, name='sigCrossover',
arguments = list(
columns=c("nFast","nSlow"),
relationship="lt"
),
label='short'
)
## ----results='hide'------------------------------------------------------
add.rule(strategy.st, name='ruleSignal',
arguments=list(sigcol='long' , sigval=TRUE,
orderside='long' ,
ordertype='stoplimit',
prefer='High',
threshold=.threshold,
orderqty=+.orderqty,
replace=FALSE
),
type='enter',
label='EnterLONG'
)
## ----results='hide'------------------------------------------------------
add.rule(strategy.st, name='ruleSignal',
arguments=list(sigcol='short', sigval=TRUE,
orderside='short',
ordertype='stoplimit',
prefer='Low',
threshold=-.threshold,
orderqty=-.orderqty,
replace=FALSE
),
type='enter',
label='EnterSHORT'
)
## ----results='hide'------------------------------------------------------
add.rule(strategy.st, name='ruleSignal',
arguments=list(sigcol='short', sigval=TRUE,
orderside='long' ,
ordertype='market',
orderqty='all',
TxnFees=.txnfees,
replace=TRUE
),
type='exit',
label='Exit2SHORT'
)
## ----results='hide'------------------------------------------------------
add.rule(strategy.st, name='ruleSignal',
arguments=list(sigcol='long' , sigval=TRUE,
orderside='short',
ordertype='market',
orderqty='all',
TxnFees=.txnfees,
replace=TRUE
),
type='exit',
label='Exit2LONG'
)
## ----results='hide'------------------------------------------------------
out <- applyStrategy(strategy.st, portfolio.st)
updatePortf(portfolio.st, Symbols='GBPUSD')
updateAcct(account.st) #,Dates=period.st)
updateEndEq(account.st) #,Dates=period.st)
View(t(tradeStats(portfolio.st, 'GBPUSD')))
More information about the R-SIG-Finance
mailing list