[R-SIG-Finance] portfolios vs strategies in quantstrat

Brian G. Peterson brian at braverock.com
Wed Jan 18 18:58:18 CET 2012

On Wed, 2012-01-18 at 17:21 +0100, Faber Castell wrote:
> Hello,
> I am trying to determine what is the proper way to organize my work :
> I have several model (moving average, bollinger bands...) that I run using
> sevral set of lookback periods.
> Within quantstrat, should I have:
> - a strategy per unique combination of (model, lookback period) ?
> - a strategy per unique combination of model, so a strategy would be a
> model applied to a set of lookback period ?
> - something else ?
> Or am I mixing strategies and portfolios ? As I can read that
> "applyStrategy()" will run one strategies in one or many portfolios.
> Would it be possible for one of you to clarify what is the role of
> portfolios versus strategies and their link to models and look back period?
> In the end, my goal is to backtest my set of model x lookback period to see
> what is the result at an aggregated level.

A strategy in quantstrat is *only* a 'model'.

It is the unique combination of indicators, signals, and rules.

There is no explicit concept for 'look back period', and you didn't
follow the posting guide to provide reproducible code, so I'm just
guessing.  I would guess, given the limited context, that lookback
period is a *parameter*.  See both the simple parameters= named list
argument to applyStrategy and the more complicated and more powerful
applyParameters and related functions.

Now, how does all this relate to portfolios?  

Answer: That depends on how you want to use it.

the blotter package, which is used by quantstrat for all the transaction
accounting, was made intentionally flexible in the organization, only
requiring that portfolios aggregate to an account, and that the same
account may only contain one copy of a given portfolio (but different
accounts may contain the same portfolio, allowing you to do different
slicing and dicing, if you're careful).  quantstrat doesn't care about
any of this, just needing to know which portfolio to place trades into
for a specific instrument.

Most (all?) of the quantstrat demo scripts that trade more than one
instrument create one single portfolio that contains all the instruments
in the demo, which makes it a little easier to aggregate performance for
the entire 'portfolio' of instruments.  This type of aggregation would
also be required if you, for example, used some of the functions Guy
Yollin talked about in his UW quantstrat lectures[1] to do things like
capital-aware trade sizing.

applyParameters will create a separate portfolio for each unique
combination of strategy and parameter sets (with one or more instruments
tested per portfolio), which may create hundreds or thousands of
portfolios, depending on how many combinations you test.  This is useful
for evaluating the 'parameter robustness' of your strategy, and keeping
the results of different parameter combinations.

When I am comparing a mature strategy to the production trading logs I
use one portfolio per instrument (or group of instruments traded
together, as with an automated spreader).  This lets me use
reconciliation features built into the blotter package to evaluate the
differences between the model and the reality of our production trades.

That said, these are only three examples.  How you choose to subset your
instruments and parameters into portfolios and accounts may vary based
on how you want to use the resulting data.

Hopefully, this clears things up a little.

..and next time, please do everyone the courtesy of using your name[2].
I don't much like answering questions from pencils.  You get a hall pass
this time because it was a reasonable and intelligent question.[2] ;)


   - Brian

[1] http://www.r-programming.org/papers
[2] http://catb.org/~esr/faqs/smart-questions.html

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

More information about the R-SIG-Finance mailing list