Description Usage Arguments Details Value Author(s) References See Also
A wrapper for apply.paramset
and applyStrategy
,
implementing a Rolling Walk Forward Analysis (WFA).
1 2 3 4 5 6 | walk.forward(strategy.st, paramset.label, portfolio.st, account.st, period,
k.training, nsamples = 0, audit.prefix = NULL, k.testing,
obj.func = function(x) { which(x == max(x)) }, obj.args = list(x
= quote(tradeStats.list$Net.Trading.PL)), anchored = FALSE,
include.insamples = TRUE, ..., verbose = FALSE, savewf = FALSE,
saveenv = FALSE, psgc = TRUE)
|
strategy.st |
the name of the strategy object |
paramset.label |
a label uniquely identifying within the strategy the paramset to be tested |
portfolio.st |
the name of the portfolio object |
account.st |
the name of the account object |
period |
the period unit, as a character string, eg. 'days' or 'months' |
k.training |
the number of periods to use for training, eg. '3' months |
nsamples |
the number of sample param.combos to draw from the paramset for training; 0 means all samples (see also apply.paramset) |
audit.prefix |
default NULL. if not NULL, |
k.testing |
the number of periods to use for testing, eg. '1 month' |
obj.func |
a user provided function returning the best param.combo from the paramset, based on training results; defaults to 'max' |
obj.args |
a user provided argument to obj.func, defaults to quote(tradeStats.list$Net.Trading.PL) |
anchored |
whether to use a fixed start for the training window (TRUE), or a sliding start (FALSE); defaults to FALSE |
include.insamples |
will optionally run a full backtest for each param.combo in the paramset, and add the resulting in-sample portfolios and orderbooks to the audit environment; default TRUE |
... |
optional parameters to pass to apply.paramset() |
verbose |
dumps a lot of info during the run if set to TRUE, defaults to FALSE |
savewf |
boolean, default FALSE. if TRUE, saves audit information on training and testing periods to working directory for later analysis |
saveenv |
boolean, default FALSE. if TRUE, save the paramset environment information for each trial, and not just the tradeStats and chosen paramset |
psgc |
boolean, if TRUE, the default, run gc() in each worker session to conserve RAM. |
walk.forward executes a strategy on a portfolio, while rolling a re-optimization of one of the strategies parameter sets during a specified time period (training window), then selecting an optimal parameter combination from the parameter set using an obj function, then applying the selected parameter combo to the next out-of-sample time period immediately following the training window (testing window). Once completed, the training window is shifted forward by a time period equal to the testing window size, and the process is repeated. The final testing window may be shorter than the full testing window, if the length of the time series does not allow a full testing window.
'anchored' walk forward forces all training windows to start on the first
observation of the market data. This can be useful if the indicators make
use of all the data, e.g. for a risk metric such as a volatility estimator,
for a regime model, or for a long-memory process of some sort. If
anchored=TRUE
and you have specified k.training
, then the
performance of each paramset will only be evaluated on the rolling training
window, even though larger (anchored) periods are used for input calculations.
Note that walk.forward will generate out of sample (OOS) transactions using the chosen parameter set into the portfolio designated by portfolio.st. So walk.forward shoud be supplied with a 'clean' portfolio environment to avoid issues such as out of order transactions.
The psgc
argument is a tradeoff between memory efficiency and speed.
R does garbage collection promarily when it is running low on RAM, but this
automatic detection works poorly in parallel processes. If TRUE, the default,
walk.proward
and apply.paramset
will call gc()
at key points to limit RAM usage. For small tests, this is probably
unecessary and will only slow the test. For large tests, even on substantial
hardware, it may be the difference between completing the test and crashing R.
a list consisting of a slot containing detailed results for each training + testing period, as well as the portfolio and the tradeStats() for the portfolio
Jan Humme, Brian G. Peterson
Tomasini, E. and Jaekle, U. Trading Systems. 2009. Chapter 6
applyStrategy
,
apply.paramset
,
chart.forward
,
chart.forward.training
,
endpoints
,
tradeStats
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.