Skip to content

quantstrat maCross demo problem

5 messages · hifin, Brian G. Peterson

#
I'm using R 2.15.1 and latest version of all packages. When I ran the maCross
demo, (AAPL from 1999-12-31 and LONG only), I got the following results:

[1] "2001-06-27 00:00:00 AAPL 100 @ 11.67"
[1] "2001-09-07 00:00:00 AAPL -100 @ 8.64"
[1] "2002-01-07 00:00:00 AAPL 100 @ 11.45"
[1] "2002-07-10 00:00:00 AAPL -100 @ 8.66"
[1] "2003-05-16 00:00:00 AAPL 100 @ 9.4"
[1] "2006-06-22 00:00:00 AAPL -100 @ 59.58"
[1] "2006-09-26 00:00:00 AAPL 100 @ 77.61"
[1] "2008-03-07 00:00:00 AAPL -100 @ 122.25"
[1] "2008-05-19 00:00:00 AAPL 100 @ 183.6"
[1] "2008-09-24 00:00:00 AAPL -100 @ 128.71"
[1] "2009-05-14 00:00:00 AAPL 100 @ 122.95"

However, when I change the startdate from 1999-12-31 to 2005-12-31, it
returns

[1] "2008-03-07 00:00:00 AAPL -100 @ 122.25"
[1] "2008-05-19 00:00:00 AAPL 100 @ 183.6"
[1] "2008-09-24 00:00:00 AAPL -100 @ 128.71"
[1] "2009-05-14 00:00:00 AAPL 100 @ 122.95"

It starts with a SHORT position while the demo code should be LONG ONLY. 
Can anybody tell me what the problem is? Thanks!



--
View this message in context: http://r.789695.n4.nabble.com/quantstrat-maCross-demo-problem-tp4636089.html
Sent from the Rmetrics mailing list archive at Nabble.com.
1 day later
#
The demo code specifies that the strategy enters and exits on the long side.
How come it also enters on the short side. Is this a bug? 

stratMACROSS <- add.rule(strategy = stratMACROSS,name='ruleSignal',
arguments = list(sigcol="ma50.gt.ma200",sigval=TRUE, orderqty=100,
ordertype='market', orderside='long'),type='enter')

stratMACROSS <- add.rule(strategy = stratMACROSS,name='ruleSignal',
arguments = list(sigcol="ma50.lt.ma200",sigval=TRUE, orderqty=-100,
ordertype='market', orderside='long'),type='exit')



--
View this message in context: http://r.789695.n4.nabble.com/quantstrat-maCross-demo-problem-tp4636089p4636249.html
Sent from the Rmetrics mailing list archive at Nabble.com.
#
On 07/10/2012 09:15 PM, hifin wrote:
<snip>
<snip>
I don't know what the root cause it yet, but I was able to replicate it. 
  As a short workaround, using orderqty='all' for the exit order solves 
the problem, as does using osMaxPos.  I'll dig deeper on the root cause 
of why the exit order fires there when I have a bit more time.

Regards,

Brian
#
Thanks Brian. Setting orderqty='all' on the exit side solves the problem.
just wonder if this is a solution for this demo only or if it will cause
other problems when the strategy is more complicated. 

For the root cause, a previous thread mentioned a problem of how applyRules
handle the order of order types ("entry", "exit", etc). The thread is here
http://r.789695.n4.nabble.com/quantstrat-tp3208477p3237429.html


--
View this message in context: http://r.789695.n4.nabble.com/quantstrat-maCross-demo-problem-tp4636089p4636384.html
Sent from the Rmetrics mailing list archive at Nabble.com.
#
On 07/12/2012 08:53 PM, hifin wrote:
We've tried to correctly process orderqty='all' for risk and exit rules.

I suspect that the issue the -100 fires is that rcit orders can be 
entered before a position exists.  I think another 'fix' for this would 
be to use order sets.  This would give applyRules a 'hint' that the exit 
is tied to an enter that might not already exist.  As I said in my prior 
email, I haven't had/taken the time to look more closely at the root 
cause yet.
Order of operations can always affect things, of course, but I don't 
think it is an issue in this case, as there is no 'enter' rule trying to 
fire on the same timestamp.  Order of operations should be most 
carefully considered on 'stop and reverse' type strategies.

Regards,

   - Brian