[R-SIG-Finance] quantstrat for live trading - some questions

Brian G. Peterson brian at braverock.com
Tue Feb 22 16:15:35 CET 2011


On 02/21/2011 03:22 AM, me at censix.com wrote:
> this is mainly directed to the developers of the great "quantstrat"
> package. I am happy to continue this conversation with any of them
> individually.
>
> I have been backtesting some strategies on quantstrat. In order to take
> them live (through the ibrokers package) I have recently begun to write my
> own versions of some key quantstrat functions, i.e. applyStrategy,
> applyRules and ruleOrderProc (addOrder is to follow)
>
> One thing I have been looking at is how to make the "applyRules" function
> process only one timestamp at a time (process all rules only for one
> specific marketdata timestamp). I consider my solution to this problem to
> be a rather ugly fix that I would really like to avoid, since essentially
> it looks like the "applyRules" function has already been designed for that
> sort of thing, but the implementation seems to be buggy or I just don't
> understand it.
>
> I am asking for some help from the list. I have attached my slightly
> modified version of "applyRules" and am hoping to get some comments that
> will make me "see the light" here.
>
> Thanks and best regards

Soren,

Probably best a discussion for off-list.  I'll send this initial 
response to the list, since I think others might find it useful, but the 
technical discussion likely to follow should probably happen off-list.

The biggest difficulty is that basically everything needs to change a 
little to be handled with streaming data.

Let's assume for the moment that your indicator and signal generators 
are fast enough that you can get data from IB and run them using 
'applyIndicators' and 'applySignals' basically unchanged in your event 
loop.  This seems like a reasonable enough assumption, given that we can 
backtest strategies on tick data (millions of timestamps) in about a 
minute per day

In this case, you'd start by modifying/replacing applyStrategy with your 
IB event loop that will get data for the instrument(s) you're 
monitoring, and calculate your indicators and signals.

As you've noted, and as is mentioned in the quantstrat documentation, 
'ruleOrderProc', 'addOrder', and 'applyRules' also need to change.

'ruleOrderProc' probably goes away entirely in this mode.  it exists in 
the quantstrat package basically as the 'fill simulator' container for 
turning open orders into transactions in the trade blotter.  If you 
still wanted to keep a 'blotter' of fills, rather than or in addition to 
simply querying IB whenever you need your position, then it would make 
sense to modify rather than replace ruleOrderProc.

'addOrder' should in all likelihood be replaced (or overloaded) by a 
wrapper for the IB order functions.

Quickly, I'll talk about dindex in applyRules.  It's there predominantly 
for handling tick data, and can be seen as short for a 'dimension 
reduction' index.  By looking at places where we *might* have to do 
something, we routinely reduce millions of timestamps to a few hundred 
on a day of tick data, which, as one might imagine, massively improves 
the total time it takes to do a backtest. For streaming/periodic data, 
there is indeed no reason to use dindex, and curIndex can be set to FALSE.

It seems that technical implementation details will probably be best 
hand;ed off-list.

Regards,

   - Brian

-- 
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock



More information about the R-SIG-Finance mailing list