rBACov: rBACov

View source: R/realizedMeasures.R

rBACovR Documentation

rBACov

Description

The Beta Adjusted Covariance (BAC) equals the pre-estimator plus a minimal adjustment matrix such that the covariance-implied stock-ETF beta equals a target beta.

The BAC estimator works by applying a minimum correction factor to a pre-estimated covariance matrix such that a target beta derived from the ETF is reached.

Let

\bar{β}

denote the implied beta derived from the pre-estimator, and

β_{\bullet}

denote the target beta, then the correction factor is calculated as:

L≤ft(\bar{β}-β_{\bullet}\right),

where

L=≤ft(I_{d^{2}}-\frac{1}{2}{\cal Q}\right)\bar{W}^{\prime}≤ft(I_{d^{2}}≤ft(∑_{k=1}^{d}\frac{∑_{k=1}^{n_{k}}≤ft(w_{t_{m-1}^{k}}^{k}\right)^{2}}{n_{k}}\right)-\frac{\bar{W}{\cal Q}\bar{W}^{\prime}}{2}\right)^{-1},

where d is the number of assets in the ETF, and n_{k} is the number of trades in the kth asset, and

\bar{W}^{k}=≤ft(0_{≤ft(k-1\right)d}^{\prime},\frac{1}{n_{1}}∑_{m=1}^{n_{1}}w_{t_{m-1}^{1}}^{1},…,\frac{1}{n_{d}}∑_{m=1}^{n_{d}}w_{t_{m-1}^{d}}^{d},0_{≤ft(d-k\right)d}^{\prime}\right),

where w_{t_{m-1}^{k}}^{k} is the weight of the kth asset in the ETF.

and

{\cal Q}^{≤ft(i-1\right)d+j}

is defined by the following two cases:

≤ft(0_{≤ft(i-1\right)d+j-1}^{\prime},1,0_{≤ft(d-i+1\right)d-j}^{\prime}\right)+≤ft(0_{≤ft(j-1\right)d+i-1}^{\prime},-1,0_{≤ft(d-j+1\right)d-i}^{\prime}\right) \quad \textrm{if }i\neq j;

0_{d^{2}}^{\prime} \quad \textrm{otherwise}.

\bar{W}^k has dimensions d \times d^2 and {\cal Q}^{≤ft(i-1\right)d+j} has dimensions d^2 \times d^2.

The Beta-Adjusted Covariance is then

Σ^{\textrm{BAC}} = Σ - L≤ft(\bar{β}-β_{\bullet}\right),

where Σ is the pre-estimated covariance matrix.

Usage

rBACov(
  pData,
  shares,
  outstanding,
  nonEquity,
  ETFNAME = "ETF",
  unrestricted = TRUE,
  targetBeta = c("HY", "VAB", "expert"),
  expertBeta = NULL,
  preEstimator = "rCov",
  noiseRobustEstimator = rTSCov,
  noiseCorrection = FALSE,
  returnL = FALSE,
  ...
)

Arguments

pData

a named list. Each list-item contains an xts or data.table object with the intraday price data of an ETF and it's component stocks. xts objects are turned into data.tables

shares

a numeric with length corresponding to the number of component stocks in the ETF. The entries are the stock holdings of the ETF in the corresponding stock. The order of these entries should correspond to the order the stocks are listed in the list passed in the pData argument.

outstanding

number of shares outstanding of the ETF

nonEquity

aggregated value of the additional components (like cash, money-market funds, bonds, etc.) of the ETF which are not included in the components in pData.

ETFNAME

a character denoting which entry in the pData list is the ETF. Default is "ETF"

unrestricted

a logical denoting whether to use the unrestricted estimator, which is an extension that also affects the diagonal. Default is FALSE

targetBeta

a character, one of c("HY", "VAB", "expert") (default) denoting which target beta to use, only the first entry will be used. A value "HY" means using the Hayashi-Yoshida estimator to estimate the empirical beta. A value of "VAB" denotes using the variance adjusted beta. A value of "expert" denotes using a user-supplied target beta, which can be supplied in the expertBeta argument.

expertBeta

a numeric containing the user supplied expert beta used when targetBeta is "expert". The expertBeta must be of length equal to the number of assets in the ETF. Default is NULL

preEstimator

a function which estimates the integrated covariance matrix. Default is rCov

noiseRobustEstimator

a function which estimates the integrated (co)variance and is robust to microstructure noise (only the diagonal will be estimated). This function is only used when noiseCorrection is TRUE. Default is rTSCov

noiseCorrection

a logical which denotes whether to use the extension of the estimator which corrects for microstructure noise by using the noiseRobustEstimator function. Default is FALSE

returnL

a logical which denotes whether to return the L matrix. Default is FALSE

...

extra arguments passed to preEstimator and noiseRobustEstimator.

Author(s)

Emil Sjoerup, (Kris Boudt and Kirill Dragun for the Python version)

References

Boudt, K., Dragun, K., Omauri, S., and Vanduffel, S. (2021) Beta-Adjusted Covariance Estimation (working paper).

See Also

ICov for a list of implemented estimators of the integrated covariance.

Examples

## Not run: 
# Since we don't have any data in this package that is of the required format we must simulate it.
library(xts)
library(highfrequency)
# The mvtnorm package is needed for this example
# Please install this package before running this example
library("mvtnorm")
# Set the seed for replication
set.seed(123)
iT <- 23400 # Number of observations
# Simulate returns
rets <- rmvnorm(iT * 3 + 1, mean = rep(0,4), 
                sigma = matrix(c(0.1, -0.03 , 0.02, 0.04,
                                -0.03, 0.05, -0.03, 0.02,
                                 0.02, -0.03, 0.05, -0.03,  
                                 0.04, 0.02, -0.03, 0.08), ncol = 4))
# We assume that the assets don't trade in a synchronous manner
w1 <- rets[sort(sample(1:nrow(rets), size = nrow(rets) * 0.5)), 1]
w2 <- rets[sort(sample(1:nrow(rets), size = nrow(rets) * 0.75)), 2]
w3 <- rets[sort(sample(1:nrow(rets), size = nrow(rets) * 0.65)), 3]
w4 <- rets[sort(sample(1:nrow(rets), size = nrow(rets) * 0.8)), 4]
w5 <- rnorm(nrow(rets) * 0.9, mean = 0, sd = 0.005)
timestamps1 <- seq(34200, 57600, length.out = length(w1))
timestamps2 <- seq(34200, 57600, length.out = length(w2))
timestamps3 <- seq(34200, 57600, length.out = length(w3))
timestamps4 <- seq(34200, 57600, length.out = length(w4))
timestamps4 <- seq(34200, 57600, length.out = length(w4))
timestamps5 <- seq(34200, 57600, length.out = length(w5))

w1 <- xts(w1 * c(0,sqrt(diff(timestamps1) / (max(timestamps1) - min(timestamps1)))),
          as.POSIXct(timestamps1, origin = "1970-01-01"), tzone = "UTC")
w2 <- xts(w2 * c(0,sqrt(diff(timestamps2) / (max(timestamps2) - min(timestamps2)))),
          as.POSIXct(timestamps2, origin = "1970-01-01"), tzone = "UTC")
w3 <- xts(w3 * c(0,sqrt(diff(timestamps3) / (max(timestamps3) - min(timestamps3)))),
          as.POSIXct(timestamps3, origin = "1970-01-01"), tzone = "UTC")
w4 <- xts(w4 * c(0,sqrt(diff(timestamps4) / (max(timestamps4) - min(timestamps4)))),
          as.POSIXct(timestamps4, origin = "1970-01-01"), tzone = "UTC")
w5 <- xts(w5 * c(0,sqrt(diff(timestamps5) / (max(timestamps5) - min(timestamps5)))),
          as.POSIXct(timestamps5, origin = "1970-01-01"), tzone = "UTC")

p1  <- exp(cumsum(w1))
p2  <- exp(cumsum(w2))
p3  <- exp(cumsum(w3))
p4  <- exp(cumsum(w4))

weights <- runif(4) * 1:4
weights <- weights / sum(weights)
p5 <- xts(rowSums(cbind(w1 * weights[1], w2 * weights[2], w3 * weights[3], w4 * weights[4]),
                   na.rm = TRUE),
                   index(cbind(p1, p2, p3, p4)))
p5 <- xts(cumsum(rowSums(cbind(p5, w5), na.rm = TRUE)), index(cbind(p5, w5)))

p5 <- exp(p5[sort(sample(1:length(p5), size = nrow(rets) * 0.9))])


BAC <- rBACov(pData = list(
                     "ETF" = p5, "STOCK 1" = p1, "STOCK 2" = p2, "STOCK 3" = p3, "STOCK 4" = p4
                   ), shares = 1:4, outstanding = 1, nonEquity = 0, ETFNAME = "ETF", 
                   unrestricted = FALSE, preEstimator = "rCov", noiseCorrection = FALSE, 
                   returnL = FALSE, K = 2, J = 1)

# Noise robust version of the estimator
noiseRobustBAC <- rBACov(pData = list(
                     "ETF" = p5, "STOCK 1" = p1, "STOCK 2" = p2, "STOCK 3" = p3, "STOCK 4" = p4
                   ), shares = 1:4, outstanding = 1, nonEquity = 0, ETFNAME = "ETF", 
                   unrestricted = FALSE, preEstimator = "rCov", noiseCorrection = TRUE, 
                   noiseRobustEstimator = rHYCov, returnL = FALSE, K = 2, J = 1)

# Use the Variance Adjusted Beta method
# Also use a different pre-estimator.
VABBAC <- rBACov(pData = list(
                     "ETF" = p5, "STOCK 1" = p1, "STOCK 2" = p2, "STOCK 3" = p3, "STOCK 4" = p4
                   ), shares = 1:4, outstanding = 1, nonEquity = 0, ETFNAME = "ETF", 
                   unrestricted = FALSE, targetBeta = "VAB", preEstimator = "rHYov", 
                   noiseCorrection = FALSE, returnL = FALSE, Lin = FALSE, L = 0, K = 2, J = 1)                    
                   

## End(Not run)

jonathancornelissen/highfrequency documentation built on Jan. 10, 2023, 7:29 p.m.