Hi,
I'm experimenting with the new Tradesys package, i.e. running sample
backtests for tradesystems etc, and I think it looks really good. The
approach that the package takes is very similar to my own ideas about
backtesting tradesystems with R and it looks like a lot of functionality is
already in the package. Congratulations to the author(s)!

After reading the docs I am wondering if the package supports (or will
support) trading systems with dynamic position sizing (where entry/exit
sizes can depend on for instance the actual total position at the time of
entry).

Further I ran into some issues when I tried to run some (simple) backtests:

1) An example spx dataset (OHLC end-of-day) is provided with the package.
This looks like a zoo type:
> class(spx)
[1] "zoo"

when I try to use a smaller subset of this spx dataset, I get an error when
calling tradesys():
--------------------------- start trace
----------------------------------------------------
> spxx = window(spx, start=as.Date("2009-01-02"), end=as.Date("2009-05-19"))
> tradesys(spxx, el=MA(Close, 60) > MA(Close, 120), es=MA(Close, 60) <=
MA(Close, 120))
Error in x[c(1, 1:(n - k))] :
  only 0's may be mixed with negative subscripts
---------------------------- end trace
-----------------------------------------------------

2) When I use an xts timeseries dataset, the equity() and trades() functions
do not calculate the expected results:
---------------------------- start trace
---------------------------------------------------
getSymbols("AAPL")

aapl = tradesys(AAPL, el=MA(AAPL.Close, 60) > MA(AAPL.Close, 120),
es=MA(AAPL.Close, 60) <= MA(AAPL.Close, 120))

> equity(aapl)
           trade states delta  price ror equity
2007-01-03     0      0     0  86.29   0      1
2007-01-04     0      0     0  84.05   0      1
2007-01-05     0      0     0  85.77   0      1
2007-01-08     0      0     0  85.96   0      1
....... (truncated for readability)
2007-06-14     0      0     0 117.20   0      1
2007-06-15     0      0     0 120.62   0      1
2007-06-18     0      0     0 123.28   0      1
2007-06-19     0      0     0 124.69   0      1
2007-06-20     0      0     0 123.87   0      1
2007-06-21     0      0     0 121.70   0      1
2007-06-22     0      0     0 123.85   0      1
2007-06-25    NA      1     0 124.19   0      1
2007-06-26     1      1     0 123.98   0      1
2007-06-27     1      1     0 120.61   0      1
2007-06-28     1      1     0 122.36   0      1
2007-06-29     1      1     0 121.97   0      1
2007-07-02     1      1     0 121.05   0      1
....... (truncated for readability)
------------------------------------ end trace
------------------------------------------------

Notice the NA in the trade column, no ror is calculated and equity remains
at 1.

The trades() function does not seems to calculate a ror either with this
dataset:
------------------------------------ start trace
------------------------------------------------
> trades(aapl)
  phase      etime      xtime time nobs eprice xprice    pnl ror
1    EL 2007-06-25 2008-02-25  245  168 124.19 118.59  -5.60   0
2    ES 2008-02-25 2008-05-28   93   65 118.59 187.41 -68.82   0
3    EL 2008-05-28 2008-09-09  104   72 187.41 156.86 -30.55   0
4    ES 2008-09-09 2009-04-06  209  144 156.86 114.94  41.92   0
5    EL 2009-04-06 2009-07-17  102   71 114.94 149.08  34.14   0
------------------------------------- end trace
--------------------------------------------------

3) I tried to use the RSI() function from the TTR package as an entry/exit
for a tradesystem but tradesys() gives me an error and warning:
----------------------------------- start trace
---------------------------------------------------
crosses_over <- function(indicator, value) {
lag(indicator, 1) <= value & indicator > value
}

crosses_under <- function(indicator, value) {
lag(indicator, 1) >= value & indicator < value
}

> tradesys(spx, el=crosses_over(RSI(spx$Close), 30),
xl=crosses_under(RSI(spx$Close), 70))
Error in tsts(d, order.by = index(data), states = s, ...) :
  length(states) must equal nrow(data)
In addition: Warning message:
In merge.zoo(..., all = all, fill = fill, suffixes = suffixes, retclass =
"zoo") :
  Index vectors are of different classes: Date integer Date integer
----------------------------------- end trace
------------------------------------------------------

I was also wondering if there are some more advanced examples for calling
tradesys(), especially ones that use the other parameters. The documentation
is quite abstract and some examples could clarify this I think.
An example with futures as an instrument would help me to specify roll dates
etc.

Great stuff so far!

-Mark-

	[[alternative HTML version deleted]]

