[R-SIG-Finance] qantstrat same period execution

Brian G. Peterson brian at braverock.com
Sun Dec 9 15:04:24 CET 2012

On 12/09/2012 02:59 AM, af2tr wrote:
> I know that there has already been several posts regarding this matter, but I
> feel I still need clarification.
> I understand that if the signal triggered at time n, then order will be
> executed on tim n+1 if using daily of lower frequency data. It is possible
> to change the price by prefer parameter, but it is not possible to execute
> order at the same time as signal triggered. The lag parameter in ruleSignal
> function is useful, but only on lower frequency data as it does not account
> for weekends. The other option is to add a new column 'PervClose' and link
> it via add.signal FUN. However this is not convenient if you have many
> indicators and they depend not only on Closing price.
> I could live with this but... I was watching yollin slides I replicated his
> code. Outcome was that his orders executed 1 day earlier. Was this an
> update? what is the execution time linked to?
> Thanks to anyone who could help

Guy Yollin's slides are rather dated at this point, and some of the 
quantstrat code has moved on.  Major examples of the latter are in order 
sizing, rebalancing, and parameter testing for strategies, which Guy 
used 'brute force' (and slow!) approaches to accomplish.  All of these 
are now supported in the package in much more efficient forms.

We've gone back and forth on whether to allow 'same bar' execution for 
daily OHLC data. It was in the code that way for a little while. I think 
it is intellectually dishonest, and leads to unreliable tests.  I really 
don't like to encourage magical thinking.

It is a physical impossibility to make a decision and act at the same 
time.  The price you used to make the decision doesn't exist anymore.

In a real trading environment, you make a decision, and then enter an 
order.  We've been discussing a version of a 'fill or kill' limit order 
that would execute on the next bar or not at all.  This may be the best 
solution, preserving accuracy (there is no such thing as instant 
execution) while giving people (most) of what they say they want.

Other alternatives include using higher frequency data.  1-min data is 
readily available through long histories, and can be easily processed to 
whatever frequency makes sense.  The speed of a quantstrat test is a 
nearly linear function of the number of signals, and is largely 
indifferent to the frequency of your data.

To your point about adding columns, this can easily be done 
automatically by your indicator function.  If you want to add look-ahead 
biases to your code, feel free. (I understand that a 'PrevClose' column 
would not introduce look-ahead bias, but most of the time when people 
here have asked for same bar execution, that's what they're asking for). 
  Also, you can calculate your indicators and signals using whatever 
data you want.  A PrevClose column would only be for pricing your orders 
using the prefer= argument to getPrice(), and shouldn't impact your 
signal generation process at all.

I have no intention of allowing instant execution in the code.  It's 
just flat out wrong, as I'm certain anyone who thinks about it for a 
moment will realize.


     - Brian

Brian G. Peterson
Ph: 773-459-4973
IM: bgpbraverock

More information about the R-SIG-Finance mailing list