This function calculates the \(B_{pT}\) statistic, which is part of the hypothesis testing procedure to determine whether the covariance matrix of asset returns is time-varying. It incorporates kernel-weighted local and global factor interactions along with residuals.
compute_B_pT(local_factors, global_factors, residuals, h, iT, ip, kernel_func)A numeric scalar \(B_{pT}\) representing the computed statistic based on kernel-weighted factor interactions and residuals.
A list where each element is a numeric matrix representing the local factor scores for a specific time period. Each matrix should have \(T\) rows (time periods) and \(m\) columns (factors).
A numeric matrix of global factor scores with \(T\) rows (time periods) and \(m\) columns (factors).
A numeric matrix of residuals with \(T\) rows (time periods) and \(p\) columns (assets).
A numeric value indicating the bandwidth parameter for the kernel function.
An integer specifying the number of time periods.
An integer specifying the number of assets.
A function representing the kernel used for weighting. Typically, an Epanechnikov kernel or another boundary kernel function.
The function performs the following steps:
Computes the sum of squared residuals for each time period \(s\).
Constructs the kernel matrix \(K[s,t]\) by applying the boundary_kernel
function to each pair of time periods \((s,t)\).
Calculates the local dot-product matrix \(L[s,t]\) as the dot product between the local factors at time \(s\) and \(t\).
Computes the global dot-product matrix \(G[s,t]\) as the dot product between the global factors at time \(s\) and \(t\).
Computes the element-wise squared difference between \(K * L\) and \(G\), multiplies it by the residuals, and sums over all \(s,t\).
Scales the aggregated value by \(\frac{\sqrt{h}}{T^2 \sqrt{p}}\) to obtain \(B_{pT}\).