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

double confidence level for the critical values to be extracted. Default = 0.95 designating 95%

annualize

logical determining whether or not to annualize the series.

nDays

numeric determining how many days to use for annualization. The standard of 252 reflects the average 252 trading days in a year.

which

character determining which series to retrieve the mean and variance of in getMean and getVar. This argument can also be used in the print and plot methods, see details for use in these methods.

Details

For the print method, the ... argument can be used to pass the following arguments:

For the plot method, the ... argument can be used to pass the following arguments:

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)

[Package DriftBurstHypothesis version 0.4.0.1 Index]