local_pca {TVMVP} | R Documentation |
Perform Local Principal Component Analysis
Description
This function performs a local principal component analysis (PCA) on asset returns, weighted by a specified kernel function. It extracts local factors and loadings from the weighted returns and computes a factor estimate. Optionally, previously estimated factors can be provided to align the new factors' directions.
Usage
local_pca(returns, r, bandwidth, m, kernel_func, prev_F = NULL)
Arguments
returns |
A numeric matrix of asset returns with dimensions |
r |
Integer. The current time index at which to perform the local PCA. |
bandwidth |
Numeric. The bandwidth used in the kernel weighting. |
m |
Integer. The number of factors to extract. |
kernel_func |
Function. The kernel function used for weighting observations (e.g., |
prev_F |
Optional. A numeric matrix of previously estimated factors (with dimensions |
Details
The function operates in the following steps:
**Kernel Weight Computation:** For each time point
t = 1, \dots, T
, the kernel weight is computed usingboundary_kernel(r, t, T, bandwidth, kernel_func)
. The weighted returns are given byX_r = \text{returns} \circ \sqrt{k_h},
where
\circ
denotes element-wise multiplication andk_h
is the vector of kernel weights.**Eigen Decomposition:** The function computes the eigen decomposition of the matrix
X_r X_r^\top
and orders the eigenvalues in descending order. The topm
eigenvectors are scaled by\sqrt{T}
to form the local factors:\hat{F}_r = \sqrt{T} \, \text{eigvecs}_{1:m}.
**Direction Alignment:** If previous factors (
prev_F
) are provided, the function aligns the signs of the new factors with the previous ones by checking the correlation and flipping the sign if the correlation is negative.**Loadings Computation:** The loadings are computed by projecting the weighted returns onto the factors:
\Lambda_r = \frac{1}{T} X_r^\top \hat{F}_r,
where the result is transposed to yield a
p × m
matrix.**One-Step-Ahead Factor Estimation:** A second pass computes the factor estimate for the current time index
r
by solving\hat{F}_r = \left(\Lambda_r^\top \Lambda_r\right)^{-1} \Lambda_r^\top R_r,
where
R_r
is the return vector at timer
.
Value
A list with the following components:
-
factors
: AT × m
matrix of local factors estimated from the weighted returns. -
f_hat
: A1 × m
vector containing the factor estimate for timer
. -
loadings
: Ap × m
matrix of factor loadings. -
w_r
: A numeric vector of kernel weights used in the computation.