Skip to content
Prev 4569 / 15274 Next

Backtesting trade systems

I'll add to Jeff's comments a little, but I think he's absolutely right
about working towards integration of various components.

PerformanceAnalytics has always been intended for statistical evaluation
of the resulting returns generated by trading systems, and has been
carefully scoped that way.  Although we started writing it before zoo or
xts came along, we had long wished for a time series package such that we
could concentrate on the objectives of the package rather worry about
underlying mechanics.  For me, zoo and xts are key components not only
because they make development easier, but because they should also make
integration easier.  That's why we're continuing to work to  move away
from our own (legacy?) code and take advantage of all that xts offers.

Blotter is another example of a component.  blotter takes it's name from
the "trade blotter," which is used by traders for recording transactions. 
blotter is *not* about creating trading strategies, but only about
managing trades, positions, and calculating p&l on those trades/positions.
 We will be extending it shortly to handle multiple instrument types and
currencies, as our requirements are for worldwide markets and multiple
different asset classes.  So, in that paradigm, the "trading system" would
generate a list of trades, and 'blotter' would be an interface for
evaluating performance, keeping records, etc., completely agnostic of the
process that generates trades.

Although blotter is still immature code, it's pretty functional already
given that it benefits so much from the existence of xts.  To see how to
use blotter, install it from r-forge and take a look at:
library(blotter)
example(blotter)
demo(turtles)

The example is a relatively simple one with a few trades in a few stocks. 
The demo is a more developed example of a trading system.  In this case,
it's a trend following system originally developed by Josh Ulrich that
uses signals from TTR, charts and prices from quantmod, and blotter to
calculate P&L.  There's a lot to do still, but I think it hints at the
possibilities here.

pcc