roll_backtest | R Documentation |
Perform a backtest simulation of a trading strategy (model) over a vector of end points along a time series of prices.
roll_backtest(
xtsv,
train_func,
trade_func,
look_back = look_forward,
look_forward,
endpoints = rutils::calc_endpoints(xtsv, look_forward),
...
)
... |
additional parameters to the functions |
xtsv |
A time series of prices, asset returns, trading volumes, and other data, in xts format. |
train_func |
The name of the function for training (calibrating) a forecasting model, to be applied over a rolling look-back interval. |
trade_func |
The name of the trading model function, to be applied over a rolling look-forward interval. |
look_back |
The size of the look-back interval, equal to the number of rows of data used for training the forecasting model. |
look_forward |
The size of the look-forward interval, equal to the number of rows of data used for trading the strategy. |
endpoints |
A vector of end points along the rows of the |
The function roll_backtest()
performs a rolling backtest
simulation of a trading strategy over a vector of end points. At each end
point, it trains (calibrates) a forecasting model using past data taken
from the xtsv
time series over the look-back interval, and applies
the forecasts to the trade_func()
trading model, using out-of-sample
future data from the look-forward interval.
The function trade_func()
should simulate the trading model, and it
should return a named list with at least two elements: a named vector of
performance statistics, and an xts time series of out-of-sample
returns. The list returned by trade_func()
can also have additional
elements, like the in-sample calibrated model statistics, etc.
The function roll_backtest()
returns a named list containing the
listv returned by function trade_func()
. The list names are equal
to the endpoints dates.
The number of list elements is equal to the number of endpoints
minus two (because the first and last end points can't be included in the
backtest).
An xts time series with the number of rows equal to the number of end points minus two.
## Not run:
# Combine two time series of prices
prices <- cbind(rutils::etfenv$XLU, rutils::etfenv$XLP)
look_back <- 252
look_forward <- 22
# Define end points
endpoints <- rutils::calc_endpoints(prices, look_forward)
# Perform back-test
back_test <- roll_backtest(endpoints=endpoints,
look_forward=look_forward,
look_back=look_back,
train_func = train_model,
trade_func = trade_model,
model_params = model_params,
trading_params = trading_params,
xtsv=prices)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.