- prices
-
For a single asset, a matrix of prices with four
columns: open, high, low and close. For n
assets, a list of length four: prices[[1]]
is then a matrix with n columns containing
the open prices for the assets; prices[[2]]
is a matrix with the high prices, and so on. If
only close prices are used, then for a single asset
either a matrix of one column or a numeric vector;
for multiple assets a list of length one,
containing the matrix of close prices. For example,
with 100 close prices of 5 assets, the prices
should be arranged in a matrix p of size 100
times 5; and prices = list(p).
The series in prices are used both as
transaction prices and for valuing open
positions. If signals are to be based on other
series, such other series should be passed via the
... argument.
Prices must be ordered by time (though the
timestamps need not be provided).
- signal
-
A function that evaluates to the position in units
of the instruments suggested by the trading
rule. If convert.weights is TRUE,
signal should return the suggested position
as weights (which need not sum to 1). If signal
returns NULL, the current position is kept.
See Details.
- do.signal
-
Logical or numeric vector, a function that
evaluates to TRUE or FALSE, or a
string.
When a logical vector, its length must match the
number of observations in prices: do.signal
then corresponds to the rows in prices at
which a signal is computed. Alternatively, these
rows may also be specified as integers. If a
length-one TRUE or FALSE, the value
is recycled to match the number of observations in
prices. Default is TRUE: a signal is then
computed in every period.
do.signal may also be the string
“firstofmonth”, “lastofmonth”,
“firstofquarter” or “lastofquarter”;
in these cases, timestamp needs to specified
and must be coercable to Date.
If timestamp is specified, do.signal may
also be a vector of the same class as timestamp
(typically Date or POSIXct).
If the timestamps specified in do.signal do not
occur in timestamp, a signal is computed on the
next possible time instance.
- do.rebalance
Same as do.signal, but it may return a logical
vector of length equal to the number of assets, which
indicates which assets to rebalance. Can also be the
string "do.signal", in which case the value of
do.signal is copied. do.rebalance is called
after signal computation, so it can access the suggested
position of the current period (via SuggestedPortfolio(0).
- print.info
A function, called at the very end of each period,
i.e. after rebalancing. Can also be NULL, in
which case nothing is printed.
- cashflow
A function or NULL (default).
- b
burn-in (an integer). Defaults to 1. This may also
be a length-one timestamp of the same class as
timestamp, in which case the data up to (and
including) b are skipped.
- fraction
amount of rebalancing to be done: a scalar between
0 and 1
- initial.position
a numeric vector: initial portfolio in units of
instruments. If supplied, this will also be the
initial suggested position.
- initial.cash
a numeric vector of length 1. Defaults to 0.
- final.position
logical
- tc
transaction costs as a fraction of turnover (e.g.,
0.001 means 0.1%). May also be a function that
evaluates to such a fraction. More-complex
computations may be specified with
argument cashflow.
- ...
other named arguments. All functions (signal,
do.signal, do.rebalance, print.info, cashflow) will
have access to these arguments. See Details for
reserved argument names.
- add
Default is FALSE. TRUE is not
implemented -- but would mean that signal
should evaluate to changes in position,
i.e. orders.
- lag
default is 1
- convert.weights
Default is FALSE. If TRUE, the value
of signal will be considered a weight vector and
automatically translated into (fractional) position
sizes.
- trade.at.open
A logical vector of length one; default is TRUE.
- tol
A numeric vector of length one: only rebalance if
the maximum absolute suggested change for at least
one position is greater than tol. Default is
0.00001 (which practically means always rebalance).
- tol.p
A numeric vector of length one: only rebalance
those positions for which the relative suggested
change is greater than tol.p. Default is
NA: always rebalance.
- Globals
A list of named elements. See Details.
- prices0
-
A numeric vector (default is NULL). Only
used if b is 0 and an initial portfolio
(initial.position) is specified.
- include.data
-
logical. If TRUE, all passed data are stored
in final btest object. See Section
Value. See also argument include.timestamp.
- include.timestamp
-
logical. If TRUE, timestamp is stored
in final btest object. If timestamp
is missing, integers 1, 2, ... are used. See
Section Value. See also argument
include.data.
- timestamp
-
a vector of timestamps, along prices (optional; mainly used for
print method and journal)
- instrument
-
character vector of instrument names (optional; mainly used for
print method and journal)
- progressBar
logical: display txtProgressBar?
- variations
a list. See Details.
- variations.settings
a list. See Details.
- replications
-
an integer. If set, the function returns a list of
btest objects. Each btest has an
attribute replication, which records the
replication number.