methods for DBH objects {DriftBurstHypothesis} | R Documentation |
Methods for the DBH class
Description
These are the methods for the class DBH which are currently implemented.
Usage
## S3 method for class 'DBH'
print(x, ...)
## S3 method for class 'DBH'
plot(x, ...)
## S3 method for class 'DBH'
getDB(x)
## S3 method for class 'DBH'
getCriticalValues(x, alpha)
## S3 method for class 'DBH'
getMu(x, annualize = FALSE, nDays = 252)
## S3 method for class 'DBH'
getSigma(x, annualize = FALSE, nDays = 252)
## S3 method for class 'DBH'
getMean(x, which = 'all')
## S3 method for class 'DBH'
getVar(x, which = 'all', annualize = FALSE, nDays = 252)
Arguments
x |
DBH object |
... |
Additional arguments for the plotting and printing routines. See details |
alpha |
|
annualize |
|
nDays |
|
which |
|
Details
For the print
method, the ...
argument can be used to pass the following arguments:
criticalValue
:numeric
determining the critical value to use when determining whether a drift burst is present in the data. If this critical value is omitted, a method to determine the critical value based on a interpolations of simulated data-set of critical values for different confidence levels and auto-correlations of the test statistic. See appendix B in the article.alpha
:numeric
of length 1 which determines the confidence level of critical values extracted using the method above.
For the plot
method, the ...
argument can be used to pass the following arguments:
which
:character
Used for choosing which series to plot. Valid choices are:"DriftBursts"
,"DB"
,"Sigma"
,"Mu"
, andc("Sigma","Mu")
, the order of the latter is irrelevant. The case of the input does not matter. Default ="driftbursts"
price
:The price series which, if provided, will be overlayed in a red dotted line and the level will be shown at the right y-axis. (Only used ifwhich
is"DriftBursts"
). Default =NULL
time
:Timestamps for the trades in seconds after midnight, which will be used for the x-axis of the plot if the price is overlayed. Default =NULL
startTime
:Start of the trading day in seconds after midnight. Default =34200
endTime
:End of the trading day in seconds after midnight. Default =57600
leg.x
:X-position of the legend in the casewhich
is"DriftBursts"
AND the price is overlayed. Default ="topleft"
. Usage is as in the baseR
engine.leg.y
:Y-position of the legend in the casewhich
is"DriftBursts"
AND the price is overlayed. Default =NULL
. Usage is as in the baseR
engine.tz
:character
denoting the time-zone. Default ="GMT"
annualize
:logical
denoting whether to annualize in case which contains"mu"
,"sigma"
, or both. Default =FALSE
nDays
:numeric
denoting how many to use for annualization ifannualize
isTRUE
. Default =252
Value
For print
and plot
, nothing is returned.
For getCriticalValues
, the critical value, and the normalized critical value is returned in a list
.
For getDB
, getMu
, and getSigma
, vectors with the same length as testTimes, containing the test statistic, drift, or volatility respecitvely, is returned
For the methods getMean
and getVar
:
When the which
argument is 'all'
, getMean and getVar returns lists containing the mean or variance of the test statistic, drift, and volatility respectively.
When the which
argument is 'db'
(or 'driftbursts'
), 'mu'
, or 'sigma'
, doubles containing the mean or variance is returned.
Note that the reason for having the getMean and getVar methods is the possibility of testing being mandated while data is not present. This primarily happens when loading in tick data for an entire year in a loop, including for example Christmas Eve in the U.S. where the markets close early. In this case if the user reuses the same testTimes
, a warning will be thrown in driftBursts
, and no testing will be done, but the output series will be padded with zeros to keep the same size as testTimes
.
Author(s)
Emil Sjoerup
Examples
library(DriftBurstHypothesis)
set.seed(1)
# Set mean and variance bandwidth parameters
meanBandwidth = 300L
varianceBandwidth = 900L
# Simulate noise-less price series with 23400 observations, denoting 1 trader per second
# and generate corresponding timestamps.
iT = 23399
r = rnorm(iT, mean = 0, sd = 1)/sqrt(iT)
p = c(0,cumsum(r))
timestamps = seq(34200, 57600, length.out = iT+1)
# Test every minute after the instability period is over.
testTimes = seq(34260 + varianceBandwidth, 57600, 60L)
# Calculate drift burst test statistic
DBH = driftBursts(timestamps, p, testTimes, preAverage = 1, ACLag = -1,
meanBandwidth = meanBandwidth, varianceBandwidth = varianceBandwidth)
print(DBH)
# Plots the test statistic with prices overlaid.
plot(DBH, timestamps = timestamps, price = p)
# Plots the annualized volatility
plot(DBH, which = 'sigma', annualize = TRUE)
# Plots the annualized drift and volatility
plot(DBH, which = c('sigma', 'mu'), annualize = TRUE)
# Retrieve the critical values of the drift burst test statistic
getCriticalValues(DBH)
# Calculate the mean of the test statistic, drift, and volatility
getMean(DBH, which = 'all')
# Calculate the variance of the test statistic
getVar(DBH, which = 'db')
# Extracts the annualized drift
annualizedDrift = getMu(DBH, annualize = TRUE)
# Extracts the annualized volatility
annualizedVolatility = getSigma(DBH, annualize = TRUE)