Learn R Programming

highfrequency (version 1.0.1)

spotDrift: Spot Drift Estimation

Description

Function used to estimate the spot drift of intraday (tick) stock prices/returns

Usage

spotDrift(
  data,
  method = "mean",
  alignBy = "minutes",
  alignPeriod = 5,
  marketOpen = "09:30:00",
  marketClose = "16:00:00",
  tz = NULL,
  ...
)

Value

An object of class "spotDrift" containing at least the estimated spot drift process. Input on what this class should contain and methods for it is welcome.

Arguments

data

Can be one of two input types, xts or data.table. It is assumed that the input comprises prices in levels.

method

Which method to be used to estimate the spot-drift. Currently, three methods are available, rolling mean and median as well as the kernel method of Christensen et al. (2018). The kernel is a left hand exponential kernel that will weigh newer observations more heavily than older observations.

alignBy

character, indicating the time scale in which alignPeriod is expressed. Possible values are: "ticks", "secs", "seconds", "mins", "minutes", "hours"

alignPeriod

How often should the estimation take place? If alignPeriod is 5 the estimation will be done every fifth unit of alignBy.

marketOpen

Opening time of the market, standard is "09:30:00".

marketClose

Closing time of the market, standard is "16:00:00".

tz

fallback time zone used in case we we are unable to identify the timezone of the data, by default: tz = NULL. We attempt to extract the timezone from the DT column (or index) of the data, which may fail. In case of failure we use tz if specified, and if it is not specified, we use "UTC".

...

Additional arguments for the individual methods. See `Details'.

Author

Emil Sjoerup.

Details

The additional arguments for the mean and median methods are:

  • periods for the rolling window length which is 5 by default.

  • align controls the alignment. The default is "right".

For the kernel mean estimator, the arguments meanBandwidth can be used to control the bandwidth of the drift estimator and the preAverage argument, which can be used to control the pre-averaging horizon. These arguments default to 300 and 5 respectively.

The following estimation methods can be specified in method:

Rolling window mean ("mean")

Estimates the spot drift by applying a rolling mean over returns. $$ \hat{\mu_{t}} = \sum_{t = k}^{T} \textrm{mean} \left(r_{t-k : t} \right), $$ where \(k\) is the argument periods. Parameters:

  • periods how big the window for the estimation should be. The estimator will have periods NAs at the beginning of each trading day.

  • align alignment method for returns. Defaults to "left", which includes only past data, but other choices, "center" and "right" are available. Warning: These values includes future data.

Outputs:

  • mu a matrix containing the spot drift estimates

Rolling window median ("median")

Estimates the spot drift by applying a rolling mean over returns. $$ \hat{\mu_{t}} = \sum_{t = k}^{T} \textrm{median} \left(r_{t-k : t} \right), $$ where \(k\) is the argument periods. Parameters:

  • periods How big the window for the estimation should be. The estimator will have periods NAs at the beginning of each trading day.

  • align Alignment method for returns. Defaults to "left", which includes only past data, but other choices, "center" and "right" are available. These values includes FUTURE DATA, so beware!

Outputs:

  • mu a matrix containing the spot drift estimates

kernel spot drift estimator ("kernel")

$$ dX_{t} = \mu_{t}dt + \sigma_{t}dW_{t} + dJ_{t}, $$ where \(\mu_{t}\), \(\sigma_{t}\), and \(J_{t}\) are the spot drift, the spot volatility, and a jump process respectively. However, due to microstructure noise, the observed log-price is $$ Y_{t} = X_{t} + \varepsilon_{t} $$

In order robustify the results to the presence of market microstructure noise, the pre-averaged returns are used: $$ \Delta_{i}^{n}\overline{Y} = \sum_{j=1}^{k_{n}-1}g_{j}^{n}\Delta_{i+j}^{n}Y, $$

where \(g(\cdot)\) is a weighting function, \(min(x, 1-x)\), and \(k_{n}\) is the pre-averaging horizon. The spot drift estimator is then: $$ \hat{\bar{\mu}}_{t}^{n} = \sum_{i=1}^{n-k_{n}+2}K\left(\frac{t_{i-1}-t}{h_{n}}\right)\Delta_{i-1}^{n}\overline{Y}, $$ The kernel estimation method has the following parameters:

  • preAverage a positive integer denoting the length of pre-averaging window for the log-prices. Default is 5

  • meanBandwidth an integer denoting the bandwidth for the left-sided exponential kernel for the mean. Default is 300L

Outputs:

  • mu a matrix containing the spot drift estimates

References

Christensen, K., Oomen, R., and Reno, R. (2020) The drift burst hypothesis. Journal of Econometrics. Forthcoming.

Examples

Run this code
# Example 1: Rolling mean and median estimators for 2 days
meandrift <- spotDrift(data = sampleTData, alignPeriod = 1)
mediandrift <- spotDrift(data = sampleTData, method = "median", 
                         alignBy = "seconds", alignPeriod = 30, tz = "EST")
plot(meandrift)
plot(mediandrift)
if (FALSE) {
# Example 2: Kernel based estimator for one day with data.table format
price <- sampleTData[as.Date(DT) == "2018-01-02", list(DT, PRICE)]
kerneldrift <- spotDrift(sampleTDataEurope, method = "driftKernel",
                         alignBy = "minutes", alignPeriod = 1)
plot(kerneldrift)
}

Run the code above in your browser using DataLab