localPCA: Perform Local PCA Over Time

View source: R/pca_function.R

localPCAR Documentation

Perform Local PCA Over Time

Description

This function performs a local principal component analysis (PCA) on asset returns for each time period, aggregating the results over time. It calls an internal function local_pca() at each time index to extract local factors, loadings, and one-step-ahead factor estimates, and stores these results in lists. It uses previously computed factors to align the sign of the new factors.

Usage

localPCA(returns, bandwidth, m, kernel_func = epanechnikov_kernel)

Arguments

returns

A numeric matrix of asset returns with dimensions T × p, where T is the number of time periods and p is the number of assets.

bandwidth

Numeric. The bandwidth parameter used in the kernel weighting for the local PCA.

m

Integer. The number of factors to extract.

kernel_func

Function. The kernel function used for weighting observations. Default is epanechnikov_kernel.

Details

The function processes the input returns over T time periods by iteratively calling the local_pca() function. For each time t_i:

  1. Kernel weights are computed using the specified kernel_func and bandwidth.

  2. The returns are weighted by the square root of these kernel weights.

  3. An eigen decomposition is performed on the weighted returns' covariance matrix to extract the top m eigenvectors, which are scaled by sqrt(T) to form the local factors.

  4. The signs of the new factors are aligned with those of the previous factors.

  5. The factor loadings are computed by projecting the weighted returns onto the local factors, normalized by T.

  6. A second pass computes a one-step-ahead factor estimate for the current time period.

Value

A list with the following components:

  • factors: A list of length T, where each element is a T × m matrix of local factors.

  • loadings: A list of length T, where each element is a p × m matrix of factor loadings.

  • m: The number of factors extracted.

  • weights: A list of length T, where each element is a vector of kernel weights used at that time point.

  • f_hat: A T × m matrix of one-step-ahead factor estimates.

References

Su, L., & Wang, X. (2017). On time-varying factor models: Estimation and testing. Journal of Econometrics, 198(1), 84–101.


TVMVP documentation built on June 28, 2025, 1:08 a.m.