[R-SIG-Finance] Quantstrat - trading not just Crossovers (e.g. Moving Average)

Brian G. Peterson brian at braverock.com
Fri Aug 26 19:54:51 CEST 2011


On Fri, 2011-08-26 at 14:39 +0200, igor_vilcek_external at tatrabanka.sk
wrote:
> 
> Thanks, works fine for me in this case. 
> 
> I am just wondering, however, how to use this solution in case i want
> to set my own order sizing function 

*Everything* in quantstrat is modular.  You can define your own
functions for indicators, signals, rules, order sizing, even the fill
simulator or P&L.  We've tried to provide reasonable default functions.

It  is typical when I am modeling 'real' strategies for me to write
custom indicators, signals, and order sizing functions.

We've provided two example order sizing functions.  osNoOp, and
osMaxPos.  You can use these as templates to code your own custom order
sizing function.

> (e.g. order size based on a % of current portfolio equity). 
> 
We'll get around to an equity-aware order sizing function, as Josh
pointed out in his most recent blog post:

http://blog.fosstrading.com/2011/08/tactical-asset-allocation-using.html

The challenge for us in doing this is making it fast.  On daily OHLC
data, speed is less of an issue, but on tick data, it would be very easy
to take a huge performance hit in recalculating account equity.

There are some possible 'shortcuts' to this, 

1> you could use realized transaction P&L as a proxy for account equity,
and not have to update all the statistics in the portfolio and account.

2> you could repeatedly call applyStrategy on different non-overlapping
time periods (e.g. months for daily data), calling updatePortf and and
updateAcct at the end of each period, and updating your maxPos for each
asset.  osMaxPos is already aware of the maximum position at any given
timestamp, so changing it periodically should be fine unless you're
levered up to nosebleed levels.

I've used variations on both the methods with quantstrat on tick data,
but haven't gotten around to reworking those things in a generic fashion
to put in to the package.

> In other words, how to trade my system (above Moving Average, not
> crossover) and use flexible order quantity as well.

Hope this helps,

  - Brian

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



More information about the R-SIG-Finance mailing list