Description Usage Arguments Details Value Author(s) See Also Examples
Conducts a backtest and returns the results as an object of class backtest.
1 2 3 4 5 6 7 8 9 10 11 12 |
x |
A data frame containing the data to be analysed in the backtest. The details of what this data frame must contain are given below. |
in.var |
A character vector which indicates the name of the
column or columns in |
ret.var |
A character vector which indicates the name of the
column or columns in |
by.var |
An optional character value, specifying a second
variable in |
id.var |
An optional character value which indicates the name of
the column in |
date.var |
An optional character vector which indicates the name
of the column in |
buckets |
An optional numeric vector which specifies how many
quantiles to create according to |
universe |
An optional expression for selecting a subset of |
natural |
An optional logical value. If TRUE, the |
do.spread |
Object of class |
by.period |
Object of class |
overlaps |
An object of class |
Data frames for backtest must, at a minimum, contain a column of class
numeric to be referenced by the in.var and ret.var arguments.
The in.var is the primary variable by which the backtest categorises
observations. It must reference a numeric column in x. Using the
values in x, backtest breaks the values into equal sized
quantiles, or buckets.
The by.var is the secondary variable by which the backtest categorises
observations. When specifying both in.var and by.var, backtest
organises the observations into a n by j matrix where n is the
number of quantiles or categories created for the by.var and j is
the number of quantiles created for the in.var. By default,
backtest creates 5 quantiles.
If natural is TRUE, the data and arguments must meet certain
requirements. First, the frequency of the observations and ret.var
must be the same. Second, an id.var and date.var are
required. Third, a by.var is not allowed. Note that the code
does not verify that the backtest is truly natural; backtest
accepts the value passed by the user as valid.
Returns an object of class backtest.
The functions show and summary are used to obtain and
print a short description and longer summary of the results of the
backtest. The accessor functions counts, totalCounts,
marginals, means, naCounts, and turnover
extract different parts of the value returned by backtest.
Kyle Campbell kyle.w.campbell@williams.edu and Jeff Enos jeff@kanecap.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | data(starmine)
## Backtest with 1 'in.var' and 1 'ret.var'
bt <- backtest(starmine, in.var = "smi", ret.var = "ret.0.1.m", by.period = FALSE)
summary(bt)
## Backtest with 2 'in.var' values, 1 'ret.var', and a 'by.var'
bt <- backtest(starmine, in.var = c("smi", "cap.usd"),
ret.var = "ret.0.1.m", by.var = "sector", by.period = FALSE)
summary(bt)
## Backtest with 1 'in.var', 1 'by.var', and 1 'ret.var'. Number of
## buckets changed from default of 5 to 4. Change in number of buckets
## only affects the 'in.var' because the 'by.var' column in 'starmine'
## contains character data. For each value in this column there is a
## unique category.
bt <- backtest(starmine, in.var = "smi", by.var = "sector",
ret.var = "ret.0.1.m", buckets = 4, by.period = FALSE)
summary(bt)
## Backtest with 1 'in.var', multiple 'ret.var', and a
## universe restriction
bt <- backtest(starmine, in.var = "smi",
ret.var = c("ret.0.1.m", "ret.0.6.m"),
universe = sector == "HiTec", by.period = FALSE)
summary(bt)
## Running a natural backtest with 2 'in.vars', 1 'ret.var'
## 10 buckets
bt <- backtest(starmine, in.var = c("smi","cap.usd"),
ret.var = "ret.0.1.m", date.var = "date",
id.var = "id", buckets = 10,
natural = TRUE, by.period = FALSE)
summary(bt)
## The same backtest, but calculating quantiles within periods.
bt <- backtest(starmine, in.var = c("smi","cap.usd"),
ret.var = "ret.0.1.m", date.var = "date",
id.var = "id", buckets = 10,
natural = TRUE, by.period = TRUE)
summary(bt)
plot(bt, type = "turnover")
plot(bt, type = "return")
plot(bt, type = "cumreturn")
plot(bt, type = "cumreturn.split")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.