# NOT RUN {
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)
# }
Run the code above in your browser using DataLab