decompose_volume {intradayModel} | R Documentation |
Decompose Intraday Volume into Several Components
Description
This function decomposes the intraday volume into daily, seasonal, and intraday dynamic components according to (Chen et al., 2016).
If purpose = “analysis”
(aka Kalman smoothing), the optimal components are conditioned on both the past and future observations.
Its mathematical expression is \hat{x}_{\tau} = E[x_{\tau}|\{y_{j}\}_{j=1}^{M}]
,
where M
is the total number of bins in the dataset.
If purpose = “forecast”
(aka Kalman forecasting), the optimal components are conditioned on only the past observations.
Its mathematical expression is \hat{x}_{\tau+1} = E[x_{\tau+1}|\{y_{j}\}_{j=1}^{\tau}]
.
Three measures are used to evaluate the model performance:
Mean absolute error (MAE):
\frac{1}{M}\sum_{\tau=1}^M|\hat{y}_{\tau} - y_{\tau}|
;Mean absolute percent error (MAPE):
\frac{1}{M}\sum_{\tau=1}^M\frac{|\hat{y}_{\tau} - y_{\tau}|}{y_{\tau}}
;Root mean square error (RMSE):
\sqrt{\sum_{\tau=1}^M\frac{\left(\hat{y}_{\tau} - y_{\tau}\right)^2}{M}}
.
Usage
decompose_volume(purpose, model, data, burn_in_days = 0)
Arguments
purpose |
String |
model |
A model object of class " |
data |
An n_bin * n_day matrix or an |
burn_in_days |
Number of initial days in the burn-in period for forecast. Samples from the first |
Value
A list containing the following elements:
original_signal
: A vector of original intraday volume;smooth_signal
/forecast_signal
: A vector of smooth/forecast intraday volume;smooth_components
/forecast_components
: A list of smooth/forecast components: daily, seasonal, intraday dynamic, and residual components.error
: A list of three error measures: mae, mape, and rmse.
Author(s)
Shengjie Xiu, Yifan Yu and Daniel P. Palomar
References
Chen, R., Feng, Y., and Palomar, D. (2016). Forecasting intraday trading volume: A Kalman filter approach. Available at SSRN 3101695.
Examples
library(intradayModel)
data(volume_aapl)
volume_aapl_training <- volume_aapl[, 1:20]
volume_aapl_testing <- volume_aapl[, 21:50]
model_fit <- fit_volume(volume_aapl_training, fixed_pars = list(a_mu = 0.5, var_mu = 0.05),
init_pars = list(a_eta = 0.5))
# analyze training volume
analysis_result <- decompose_volume(purpose = "analysis", model_fit, volume_aapl_training)
# forecast testing volume
forecast_result <- decompose_volume(purpose = "forecast", model_fit, volume_aapl_testing)
# forecast testing volume with burn-in
forecast_result <- decompose_volume(purpose = "forecast", model_fit, volume_aapl[, 1:50],
burn_in_days = 20)