backtest(data,
in.var, ret.var, ...)
.in.var
:"character"
specifying
the in.var
values for this backtest.
ret.var
:"character"
containing
the ret.var
values for this backtest.
by.var
:"character"
containing
the by.var
, if specified, for this backtest.
date.var
:"character"
containing
the date.var
, if specified, for this backtest.
buckets
:"numeric"
containing
the number(s) of buckets used create quantiles from the
in.var
and by.var
values.
results
:"array"
containing the
results of the backtest.
ret.stats
:"array"
containing
return statistics for the backtest.
turnover
:"array"
containing
turnover statistics for the backtest.
natural
:"logical"
expressing
whether or not the intervals between observations, as specified by
date.var
, and returns, as specified by ret.var
,
match. If the interval between dates is one month, the interval
between returns should also be one month.
do.spread
:"logical"
. If TRUE the summary
method displays information about the spread between the extreme
quantiles. If FALSE this information is suppressed. Defaults to TRUE.
by.period
:"logical"
. If TRUE the quantiles are
recalculated within each date period. If FALSE the quantiles are
calculated all at once. Defaults to TRUE.
overlaps
:"numeric"
which specifies
the number of prior periods to include in the current period's
portfolio weights calculation. If overlaps
is the default of 1,
backtest behaves as usual and only uses a periods own data to
determine its portfolio. If overlaps
is set to
n > 1, a period's portfolio comprises the weighted mean of
portfolio weights from the previous n periods, with period n
having a weight of 1/n.
signature(object = "backtest")
: Prints the
variables used in this backtest.
signature(object = "backtest")
: Prints
the results of the backtest.
signature(object = "backtest")
:
Returns a data frame with spreads for each date.var
value and each
in.var
.
signature(object = "backtest")
: Returns a list
of matrices, with one matrix for each in.var
, where the
value of each cell is the mean of the returns for that
in.var
and by.var
combination.
signature(object = "backtest")
: Returns a list
of matrices, with one matrix for each in.var
, where the
value of each cell is the number of observations for that
in.var
and by.var
combination.
signature(object = "backtest")
: Returns a
data frame in the same format as the speads data frame returned by summaryStats
:
contains the sum of counts for all buckets (or high and
low buckets if argument low.high.only
is set to TRUE) of non-NA
in.var
values that went into the spread calculations.
signature(object = "backtest")
: Returns a
list of matrices, one matrix for each in.var
, where the
value of each cell is the number of observations for that
in.var
and by.var
combination. Different from
counts
because the marginal sums have been appended to the
matrices.
signature(object = "backtest")
: Returns a
list of matrices, with one matrix for each in.var
, where
the value of each cell is the number of NA observations for that
in.var
and by.var
combination.
signature(object = "backtest")
: Returns a
matrix of confidence intervals for spreads.
signature(object = "backtest")
: Returns a
data.frame
of the turnovers if the backtest
is natural
.
signature(x = "backtest", y = "missing")
: Plots
returns, cumulative returns, or turnover, when passed a
type
argument of return
, cumreturn
, or
turnover
, respectively.
The primary method for accessing the backtest
results is through
the summary
method. summary
provides different displays
depending on the type of backtest
object. These displays are
shown in the examples section. Accessor methods such as means
,
counts
, marginals
, naCounts
, turnover
, and
ci
may be used to extract other types of information from the object.
A backtest
object with a natural
value of TRUE may be
graphed by calling the plot
method. The default plot
method graphs return. The other plots, turnover and
cumulative return, must be explicitly specified as plot(object,
type = "turnover")
or plot(object, type = "cumreturn")
.
The backtest
object does not store the data frame used to create
the backtest.
It only stores the results and the names of the
vectors used in calculating these results.
The results of a backtest
are stored in a 5-dimensional array,
results
. The 1st dimension contains one value for every element
of ret.var
. The 2nd dimension contains one value for
every element of in.var
. The 3rd dimension contains one value
for every element in 1:buckets[1]
, a vector from 1 through the
number of by.var
buckets. The 4th dimension contains one value
for every element in 1:buckets[2]
, a vector from 1 through the
number of in.var
buckets. The 5th dimension contains 4
elements: means
, counts
, trim.means
, and
NAs
.
backtest
data(starmine)
bt <- backtest(starmine, in.var = "smi", ret.var = "ret.0.1.m", by.period = FALSE)
## Summary for a pooled backtest
summary(bt)
## A natural backtest
bt <- backtest(starmine, in.var = "smi", ret.var = "ret.0.1.m",
date.var = "date", id.var = "id", natural = TRUE, by.period = FALSE)
## Summary for a natural backtest
summary(bt)
## Other access methods
means(bt)
counts(bt)
marginals(bt)
naCounts(bt)
## Plotting methods
plot(bt, type = "turnover")
plot(bt, type = "return")
plot(bt, type = "cumreturn")
Run the code above in your browser using DataLab