Skip to content

Consolidating Backtests

3 messages · Akane Fortuna, Brian G. Peterson, Ilya Kipnis

#
Hi everyone,

I am trying to test a strategy with random parameters that change every
month as some kind of a benchmark to compare my other strategies against.
This strategy is applied to the same instrument every month.  I tried to
make a loop with applystrategy(), where in each iteration the different
random parameter values are passed, and the next month's data is used. The
first iteration is executed without problems but I cannot make the next
iterations work.

I want to be able to use chart.Posn(), tradeStats() (in consolidated form),
chart.ME(), getOrderBook(), getTxns() with the consolidated strategy
backtest.

How should I go about doing this? No code is necessary for an answer, but I
appreciate it if there is. Just outline/plan of the code is sufficient.
Thank you.
#
On Sun, 2015-08-16 at 20:19 +0300, Akane Fortuna wrote:
The challenge with what you're trying to do is that the indicators and
signals are presumed to be vectorized functions.  So they are applied to
the entire dataset at once.

You're talking about subsetting the data by months, and applying
different parameter values.

If your indicators and signals don't have any lookback period, or are
constant over the entire test, then you should be able to use a
rebalance rule, which will subset the data and let you change things
around on your rebalance periods.

Assuming that's not the case, your options are somewhat more limited.

You have no problems using the same portfolio and account over
progressively increasing time periods.  You're basically just adding new
transactions over time.

The slightly challenging point will be in controlling the start and end
periods for everything else.  You'll need to make sure you don't have
signals before the start of the subset period, or after the end of the
subset period.

A minimal reproducible example would help others help you.

Regards,

Brian
#
Set a seed.
Loop through months, using that seed to generate the integer value of your
lookback every month.
Loop through all unique integer lookback values.
Compute your indicator for those values.
Proceed as usual.

On Sun, Aug 16, 2015 at 3:02 PM, Brian G. Peterson <brian at braverock.com>
wrote: