Description Usage Arguments Examples
Walk forward analysis backtest with the specified parameters on an object of class Strategy
. The backtest calibrates the parameters according to the specification given by the user (in-sample) and returns the trading signals for the following period (out-of-sample). This is iteratively repeated on a shifting time window. Computer performance is critical with this function.
1 2 3 4 5 6 7 8 9 10 | backtest(object, horizon = "6m", data.width = "24m", keep.history = F,
optim.param = NULL, optim.param.min = 1, optim.param.max = 10,
optim.param.scale = 0.1, from = NULL, until = NULL, which = NULL,
rf = 0, printSteps = F)
## S4 method for signature 'Strategy'
backtest(object, horizon = "6m", data.width = "24m",
keep.history = F, optim.param = NULL, optim.param.min = 1,
optim.param.max = 10, optim.param.scale = 0.1, from = NULL,
until = NULL, which = NULL, rf = 0, printSteps = F)
|
object |
An object of class |
horizon |
The out-of-sample period length. |
data.width |
The in-sample period length used for calibration. |
keep.history |
If set to |
optim.param |
A character vector providing the names of the parameters to be calibrated. Parameters that are not provided will be kept fix. |
optim.param.min |
A numeric vector providing the minimum values of the parameters that are calibrated. |
optim.param.max |
A numeric vector providing the maximum values of the parameters that are calibrated. |
optim.param.scale |
A numeric vector providing the scaling of the parameters that are calibrated. It is advisable to set scaling of the parameters to the smallest unit that makes sense. |
from |
The date in character format |
until |
The date in character format |
which |
Names or number of assets that should be included in backtest |
rf |
Risk free rate in decimal, e.g. |
printSteps |
This is a feature used mainly for debugging the constructor function in order to localize where unspecified errors occur. If set to true, the different steps run within the constructor is printed to the console. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | ##Not run:
# MA(200)-Strategy
params <- list(k=20)
# reduce dataset due to computation time
assets_r <- assets[tail(zoo::index(assets),100)]
myStrat.MA <- Strategy(assets=assets_r, strat="MA", strat.params=params)
# Perform backtest on MA(20)-Strategy with
# out-of-sample periods of 2 months
# and in-sample-calibration of 2 months
# This example requires a lot of computation time,
# so this is only performed for 1 asset and high scaling.
backtest(myStrat.MA, horizon="2m", data.width="2m"
, optim.param="k", optim.param.min=5, optim.param.max=10
, optim.param.scale=5, printSteps = TRUE, which=1)
##End(Not run)
|
[1] "Period Windows:"
[,1]
[1,] "2016-08-31 until 2016-09-30"
[2,] "2016-10-31 until 2016-11-30"
[1] "Parameter Combinations:"
k
1 5
2 10
[1] "Period 1 of 2 started."
[1] "Params: k=5"
[1] "Sharpe Ratios: asset1=0.228545221816036"
[1] "Params: k=10"
[1] "Sharpe Ratios: asset1=0.0125592031645784"
[1] "Params for out-of-sample for asset1 k=5"
[1] "Period 2 of 2 started."
[1] "Params: k=5"
[1] "Sharpe Ratios: asset1=-0.0714044858172619"
[1] "Params: k=10"
[1] "Sharpe Ratios: asset1=0.0335222233746849"
[1] "Params for out-of-sample for asset1 k=5"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.