SPB Git

spb/wp40_uqo

Public MIT
10.6 KB · 128 lines latex
1\section{Estimator definitions and conventions}2\label{sec:est}34The method registry (\texttt{docs/methods/registry.md} in the repository) records, for each method, the equation, the inputs, the reference implementation and its options, the test tolerance and the validation status. We reproduce the Tier~A definitions here because conventions---not formulas---are where implementations diverge. Throughout, $\I{\cdot}$ is the indicator function, $\abs{\cdot}$ the absolute value, and $u$ the unit roundoff of the floating-point format in use.56\subsection{Returns and sessions}78Let session $t$ contain the regular-hours bar closes $p_{t,0}, p_{t,1}, \dots, p_{t,M_t}$ (09:30 to 16:00~ET inclusive of the closing print). Intraday log returns are9\begin{equation}10r_{t,j} \;=\; \log \frac{p_{t,j}}{p_{t,j-1}}, \qquad j = 1, \dots, M_t,11\label{eq:returns}12\end{equation}13so that a complete normal session has $M_t = 390$ and a complete early-close session $M_t = 210$. Zero-volume minutes are absent at the source and are left absent; no return is formed across a session boundary. The overnight return $\log(p_{t,0}/p_{t-1,M_{t-1}})$ and the daily close-to-close return are separate outputs.1415\subsection{Realized measures}1617For one session with returns $r_1, \dots, r_M$ (the session index is dropped) and $\mu_p = \E\abs{Z}^p$ for $Z \sim N(0,1)$, so that $\mu_1 = \sqrt{2/\pi}$ and $\mu_{4/3} = 2^{2/3}\,\Gamma(7/6)/\Gamma(1/2)$,18\begin{align}19\RV &= \sum_{j=1}^{M} r_j^{2},20&21\BPV &= \mu_1^{-2}\,\frac{M}{M-1}\sum_{j=2}^{M} \abs{r_j}\,\abs{r_{j-1}},22\label{eq:rv-bpv}\\[2pt]23\RSV^{-} &= \sum_{j=1}^{M} r_j^{2}\,\I{r_j < 0},24&25\RSV^{+} &= \sum_{j=1}^{M} r_j^{2}\,\I{r_j > 0},26\label{eq:rsv}\\[2pt]27\RQ &= \frac{M}{3}\sum_{j=1}^{M} r_j^{4},28&29J &= \max\bigl(\RV - \BPV,\, 0\bigr),30\label{eq:rq-j}\\[2pt]31\TriPV &= \mu_{4/3}^{-3}\,\frac{M}{M-2}\sum_{j=3}^{M} \abs{r_j\, r_{j-1}\, r_{j-2}}^{4/3}.32\label{eq:tripv}33\end{align}34The finite-sample factors $M/(M-1)$ and $M/(M-2)$ are options. Two conventions of \texttt{highfrequency} differ from \eqref{eq:rv-bpv}--\eqref{eq:rq-j}: \texttt{rBPCov} with \texttt{makeReturns = FALSE} applies no $M/(M-1)$ factor, and \texttt{rQuar} uses $(M+1)/3$, the number of prices, instead of $M/3$; the reference tests compare after conversion. For $N$ assets with synchronised return vectors $\bm{r}_j \in \mathbb{R}^N$, the realized covariance is $\RCov = \sum_{j=1}^{M} \bm{r}_j \bm{r}_j'$ without demeaning, and the realized correlation is $\diag(\RCov)^{-1/2}\,\RCov\,\diag(\RCov)^{-1/2}$.3536\subsection{Regression and inference}3738For $\by \in \mathbb{R}^n$ and $\bX \in \mathbb{R}^{n \times k}$, OLS, WLS and ridge solve39\begin{equation}40\hat{\bbeta} \;=\; \argmin_{\bbeta}\; (\by - \bX\bbeta)'\,\bm{W}\,(\by - \bX\bbeta) \;+\; \lambda\,\bbeta'\bm{P}\bbeta,41\label{eq:ols}42\end{equation}43with $\bm{W}$ diagonal ($\bm{W} = \bm{I}$ for OLS) and $\bm{P}$ the identity on the penalised coefficients, by column-pivoting Householder QR of the (augmented) weighted design; the SVD minimum-norm solution is used when the design is rank deficient, and the reciprocal condition number is reported. With residuals $\be$ and leverages $h_{ii}$, the covariance estimators follow \texttt{statsmodels}:44\begin{align}45\widehat{\Var}_{\mathrm{cl}}(\hat\bbeta) &= s^2 (\bX'\bX)^{-1}, \qquad s^2 = \frac{\be'\be}{n-k},46\label{eq:cov-classical}\\47\widehat{\Var}_{\mathrm{HC}_m}(\hat\bbeta) &= (\bX'\bX)^{-1}\Bigl(\sum_{i=1}^{n} \omega_{m,i}\, e_i^{2}\, \bm{x}_i\bm{x}_i'\Bigr)(\bX'\bX)^{-1},48\label{eq:cov-hc}\\49&\qquad \omega_{0,i} = 1,\qquad \omega_{1,i} = \frac{n}{n-k},\qquad \omega_{2,i} = \frac{1}{1-h_{ii}},\qquad \omega_{3,i} = \frac{1}{(1-h_{ii})^{2}}, \nonumber\\50\widehat{\Var}_{\mathrm{HAC}}(\hat\bbeta) &= (\bX'\bX)^{-1}\Bigl(\bm{\Gamma}_0 + \sum_{\ell=1}^{L}\Bigl(1 - \frac{\ell}{L+1}\Bigr)\bigl(\bm{\Gamma}_\ell + \bm{\Gamma}_\ell'\bigr)\Bigr)(\bX'\bX)^{-1},51\quad \bm{\Gamma}_\ell = \sum_{i=\ell+1}^{n} e_i e_{i-\ell}\, \bm{x}_i \bm{x}_{i-\ell}',52\label{eq:cov-hac}\\53\widehat{\Var}_{\mathrm{CR}}(\hat\bbeta) &= \frac{G}{G-1}\,\frac{n-1}{n-k}\,(\bX'\bX)^{-1}\Bigl(\sum_{g=1}^{G} \bm{s}_g \bm{s}_g'\Bigr)(\bX'\bX)^{-1},54\quad \bm{s}_g = \sum_{i \in g} e_i\, \bm{x}_i,55\label{eq:cov-cluster}56\end{align}57with the Bartlett lag $L = \lfloor 4(n/100)^{2/9} \rfloor$ by default and no small-sample correction for HAC. Two-sided $p$-values use the $t_{n-k}$ distribution. Rolling OLS refits each window by QR; batched OLS accumulates $(\bX'\bX, \bX'\by, \by'\by)$ per series on the backend and solves in FP64.5859\subsection{HAR family}6061With daily realized variances $\RV_t$, averaging windows $\overline{\RV}^{(k)}_t = k^{-1}\sum_{j=0}^{k-1}\RV_{t-j}$ for $k \in \{1, 5, 22\}$, and horizon $h \ge 1$, the HAR-RV regression is62\begin{equation}63y_{t+h} \;=\; \beta_0 \;+\; \beta_d\,\RV_t \;+\; \beta_w\,\overline{\RV}^{(5)}_t \;+\; \beta_m\,\overline{\RV}^{(22)}_t \;+\; \varepsilon_{t+h},64\qquad65y_{t+h} = \frac{1}{h}\sum_{j=1}^{h} \RV_{t+j},66\label{eq:har}67\end{equation}68where the single-day target $y_{t+h} = \RV_{t+h}$ is an option. HARQ \citep{BollerslevPattonQuaedvlieg2016} adds the term69\begin{equation}70\beta_q\,\bigl(\sqrt{\RQ_t} - \sqrt{\overline{\RQ}}\,\bigr)\,\RV_t,71\qquad \overline{\RQ} = \frac{1}{T}\sum_{t=1}^{T}\RQ_t \ \text{over the estimation sample},72\label{eq:harq}73\end{equation}74in the demeaned form used by \texttt{highfrequency}; log-HAR applies \eqref{eq:har} to $\log\RV$ and back-transforms with $\exp$ (the smearing factor $T^{-1}\sum_t e^{\hat\varepsilon_t}$ is reported, not applied). Overlapping targets for $h > 1$ induce MA$(h-1)$ errors, so the HAC lag is at least $h-1$. Rolling estimation is strictly causal: the model fitted on observations up to $t$ forecasts $y_{t+h}$. Forecast losses are the mean squared error and75\begin{equation}76\mathrm{QLIKE}(y, \hat y) \;=\; \frac{y}{\hat y} \;-\; \log\frac{y}{\hat y} \;-\; 1,77\label{eq:qlike}78\end{equation}79the robust loss of \citet{Patton2011}.8081\subsection{GARCH family}8283With $\varepsilon_t = r_t - \mu$ and $z_t = \varepsilon_t/\sigma_t$, the conditional variance recursions are84\begin{align}85\text{GARCH}(1,1):\qquad & \sigma_t^{2} = \omega + \alpha\,\varepsilon_{t-1}^{2} + \beta\,\sigma_{t-1}^{2},86\label{eq:garch}\\87\text{GJR}(1,1):\qquad & \sigma_t^{2} = \omega + \bigl(\alpha + \gamma\,\I{\varepsilon_{t-1} < 0}\bigr)\varepsilon_{t-1}^{2} + \beta\,\sigma_{t-1}^{2},88\label{eq:gjr}\\89\text{EGARCH}(1,1):\qquad & \log\sigma_t^{2} = \omega + \alpha\bigl(\abs{z_{t-1}} - \E\abs{z}\bigr) + \gamma\, z_{t-1} + \beta\,\log\sigma_{t-1}^{2},90\label{eq:egarch}91\end{align}92with constraints $\omega > 0$, $\alpha, \beta \ge 0$, $\alpha + \beta < 1$ (GARCH), $\alpha + \gamma \ge 0$, $\alpha + \beta + \gamma/2 < 1$ (GJR) and $\abs{\beta} < 1$ (EGARCH). Errors are Gaussian or standardised Student-$t$ with $\nu \in (2.05, 500)$, the bounds of \texttt{arch}, and the quasi log-likelihood is93\begin{equation}94\ell_T(\btheta) \;=\; \sum_{t=1}^{T}\Bigl[\, c(\nu) \;-\; \tfrac12 \log\sigma_t^{2} \;-\; \tfrac{\nu+1}{2}\,\log\Bigl(1 + \frac{\varepsilon_t^{2}}{(\nu-2)\,\sigma_t^{2}}\Bigr)\Bigr],95\qquad96c(\nu) = \log\frac{\Gamma\bigl(\tfrac{\nu+1}{2}\bigr)}{\Gamma\bigl(\tfrac{\nu}{2}\bigr)\sqrt{\pi(\nu-2)}},97\label{eq:garch-ll}98\end{equation}99with the Gaussian case $\ell_T(\btheta) = \sum_t\bigl[-\tfrac12\log 2\pi - \tfrac12\log\sigma_t^2 - \varepsilon_t^2/(2\sigma_t^2)\bigr]$. The recursion starts at $\sigma_0^2 = \widehat{\Var}(\varepsilon)$, the sample variance, as in \texttt{rugarch}; \texttt{arch} uses a backcast, which explains the $5\times10^{-4}$ log-likelihood tolerance against it. Estimation maximises \eqref{eq:garch-ll} by BFGS on transformed parameters (Appendix~B), with central-difference gradients validated across step sizes; up to two alternative starting points are tried on non-convergence, and the number tried is reported. Standard errors are the Bollerslev--Wooldridge sandwich100\begin{equation}101\widehat{\Var}(\hat\btheta) \;=\; \hat{\bm{H}}^{-1}\Bigl(\sum_{t=1}^{T} \hat{\bm{s}}_t \hat{\bm{s}}_t'\Bigr)\hat{\bm{H}}^{-1},102\qquad \hat{\bm{H}} = -\frac{\partial^2 \ell_T}{\partial\btheta\,\partial\btheta'}\Big|_{\hat\btheta},\quad \hat{\bm{s}}_t = \frac{\partial \ell_t}{\partial\btheta}\Big|_{\hat\btheta},103\label{eq:qmle-cov}104\end{equation}105by default (Hessian and OPG are options). Forecasts are analytical for GARCH and GJR,106\begin{equation}107\hat\sigma^2_{T+1} = \omega + \bigl(\alpha + \gamma\,\I{\varepsilon_T < 0}\bigr)\varepsilon_T^{2} + \beta\,\sigma_T^{2},108\qquad109\hat\sigma^2_{T+h} = \omega + \bigl(\alpha + \tfrac{\gamma}{2} + \beta\bigr)\hat\sigma^2_{T+h-1},\quad h \ge 2,110\label{eq:garch-fc}111\end{equation}112and by seeded simulation beyond one step for EGARCH. The \texttt{rugarch} EGARCH parameterisation maps its \texttt{alpha1} to our $\gamma$ and its \texttt{gamma1} to our $\alpha$.113114\subsection{Bootstrap}115116The stationary bootstrap of \citet{PolitisRomano1994} draws blocks of geometric length with mean $b$ (default $b = n^{1/3}$) starting at uniform indices with circular wrap-around; the circular block bootstrap uses fixed length $b$; an iid option exists for comparison only. Replica $r$ uses the stream $(\text{seed}, r)$ of a counter-seeded xoshiro256++ generator, so replicas are independent of the thread that computes them and of the order of computation.117118\subsection{Tier B}119120For a panel $\by_t \in \mathbb{R}^N$, VAR$(p)$ with intercept $\by_t = \bm{c} + \sum_{i=1}^{p}\bA_i\by_{t-i} + \bu_t$ is estimated by multivariate least squares, with $\bSigma_u = (T-Np-1)^{-1}\sum_t \hat\bu_t\hat\bu_t'$ and moving-average matrices $\bPhi_0 = \bm{I}$, $\bPhi_h = \sum_{i=1}^{\min(h,p)}\bA_i\bPhi_{h-i}$. The generalized forecast-error variance decomposition at horizon $H$ \citep{KoopPesaranPotter1996,PesaranShin1998} and its row normalisation are121\begin{equation}122\theta_{ij}(H) = \frac{\sigma_{jj}^{-1}\sum_{h=0}^{H-1}\bigl(\be_i'\bPhi_h\bSigma_u\be_j\bigr)^{2}}{\sum_{h=0}^{H-1}\be_i'\bPhi_h\bSigma_u\bPhi_h'\be_i},123\qquad124\tilde\theta_{ij}(H) = \frac{\theta_{ij}(H)}{\sum_{j=1}^{N}\theta_{ij}(H)},125\label{eq:gfevd}126\end{equation}127and the Diebold--Yilmaz measures \citep{DieboldYilmaz2012,DieboldYilmaz2014} are the total connectedness $C(H) = 100\,N^{-1}\sum_{i \ne j}\tilde\theta_{ij}(H)$, the from-others $C_{i\leftarrow\bullet} = 100\sum_{j \ne i}\tilde\theta_{ij}$, the to-others $C_{\bullet\leftarrow j} = 100\sum_{i \ne j}\tilde\theta_{ij}$ and the net $C_{\bullet\leftarrow j} - C_{j\leftarrow\bullet}$, computed on rolling windows. Ledoit--Wolf shrinkage \citep{LedoitWolf2004} is $\bSigma^{\star} = (1-\delta^{\star})\bm{S} + \delta^{\star}\,\mu\,\bm{I}$ with $\mu = \tr(\bm{S})/N$ and the analytical $\delta^{\star}$. Realized GARCH, HEAVY, DCC, GARCH-MIDAS, state-space and change-point methods, pre-averaging, realized kernels and order-flow methods are \emph{not} implemented; the registry says so.128
Files · main
Menu

Theme