fit_volume {intradayModel} | R Documentation |
Fit a Univariate State-Space Model on Intraday Trading Volume
Description
The main function for defining and fitting a univaraite state-space model on intraday trading volume. The model is proposed in (Chen et al., 2016) as
\mathbf{x}_{\tau+1} = \mathbf{A}_{\tau}\mathbf{x}_{\tau} + \mathbf{w}_{\tau},
y_{\tau} = \mathbf{C}\mathbf{x}_{\tau} + \phi_{\tau} + v_\tau,
where
\mathbf{x}_{\tau} = [\eta_{\tau}, \mu_{\tau}]^\top
is the hidden state vector containing the log daily component and the log intraday dynamic component;\mathbf{A}_{\tau} = \left[\begin{array}{cc}a_{\tau}^{\eta}&0\\0&a^{\mu}\end{array} \right]
is the state transition matrix witha_{\tau}^{\eta} = \left\{\begin{array}{cl}a^{\eta} & t = kI, k = 1,2,\dots\\0 & \textrm{otherwise};\end{array}\right.
\mathbf{C} = [1, 1]
is the observation matrix;\phi_{\tau}
is the corresponding element from\boldsymbol{\phi} = [\phi_1,\dots, \phi_I]^\top
, which is the log seasonal component;\mathbf{w}_{\tau} = [\epsilon_{\tau}^{\eta},\epsilon_{\tau}^{\mu}]^\top \sim \mathcal{N}(\mathbf{0}, \mathbf{Q}_{\tau})
represents the i.i.d. Gaussian noise in the state transition, with a time-varying covariance matrix\mathbf{Q}_{\tau} = \left[\begin{array}{cc}(\sigma_{\tau}^{\eta})^2&0\\ 0&(\sigma^{\mu})^2\end{array} \right]
and\sigma_\tau^{\eta} = \left\{\begin{array}{cl} \sigma^{\eta} & t = kI, k = 1,2,\dots\\0 & \textrm{otherwise};\end{array}\right.
v_\tau \sim \mathcal{N}(0, r)
is the i.i.d. Gaussian noise in the observation;\mathbf{x}_1
is the initial state at\tau = 1
, and it follows\mathcal{N}(\mathbf{x}_0, \mathbf{V}_0)
.
In the model, \boldsymbol{\Theta} = \left\{a^{\eta},a^{\mu},\sigma^{\eta},\sigma^{\mu},r,\boldsymbol{\phi}, \mathbf{x}_0, \mathbf{V}_0\right\}
are treated as parameters.
The model is fitted by expectation-maximization (EM) algorithms. The implementation follows (Chen et al., 2016), and the accelerated scheme is provided in (Varadhan and Roland, 2008).
The algorithm terminates when maxit
is reached or the condition \|\Delta \boldsymbol{\Theta}_i\| \le \textrm{abstol}
is satisfied.
Usage
fit_volume(
data,
fixed_pars = NULL,
init_pars = NULL,
verbose = 0,
control = NULL
)
Arguments
data |
An n_bin * n_day matrix or an |
fixed_pars |
A list of parameters' fixed values. The allowed parameters are listed below,
|
init_pars |
A list of unfitted parameters' initial values. The parameters are the same as |
verbose |
An integer specifying the print level of information during the algorithm (default
|
control |
A list of control values of EM algorithm:
|
Value
A list of class "volume_model
" with the following elements (if the algorithm converges):
par
: A list of parameters' fitted values.init
: A list of valid initial values from users.par_log
: A list of intermediate parameters' values iflog_switch = TRUE
.converged
: A list of logical values indicating whether each parameter is fitted.
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.
Varadhan, R., and Roland, C. (2008). Simple and globally convergent methods for accelerating the convergence of any EM algorithm. Scandinavian Journal of Statistics, 35(2), 335–353.
Examples
library(intradayModel)
data(volume_aapl)
volume_aapl_training <- volume_aapl[, 1:20]
# fit model with no prior knowledge
model_fit <- fit_volume(volume_aapl_training)
# fit model with fixed_pars and init_pars
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))
# fit model with other control options
model_fit <- fit_volume(volume_aapl_training, verbose = 2,
control = list(acceleration = FALSE, maxit = 1000, abstol = 1e-4, log_switch = FALSE))