covFactorModel: Covariance Matrix Estimation Using Factor Model

Description Usage Arguments Details Value Author(s) References Examples

Description

Estimate covariance matrix through factor model.

Usage

1
2
3
covFactorModel(X, type = "Stat-PCA", econ_fact = NA, K = 1,
  orthonormal = "factor", max_iter = 10, tol = 0.001, epsilon = 0,
  Psi_struct = "diag", stock_sector_info = NA)

Arguments

X

xts object of dimension T x N, with T number of observations and N number of assets

type

string object indicating the type of factor model to be used:

  • "Macro" - macroeconomic factor model, requires user to pass econ_fact

  • "Barra" - BARRA Industry factor model, requires user to pass stock_sector_info or colnames of X to be contained in the in-built database data(stock_sector_database)

  • "Stat-PCA" - statistical factor model, requires user to pass number of factors K (default)

  • "stat-ML" - Maximum likelihood estimation under factor model structure

econ_fact

xts object of dimension T x K, required and used when type = "Macro"

K

number of factors when build a statistical factor model, used when type = "Stat-PCA"/"Stat-ML" (default: 1)

orthonormal

string object indicating position of normalization in the statistical factor model, used when type = "Stat-PCA"

  • "factor" - covariance matrix of factors is identity (default)

  • "beta" - columns of beta are orthonormal

max_iter

positive integer indicating maximum number of iterations, used when type = "Stat-PCA"/"Stat-ML" (default: 10)

tol

double object indicating relative tolerance to determine convergence, used when type = "Stat-PCA"/"Stat-ML" (default: 0.001)

epsilon

nonnegative scale indicating lower bound of residual covariance matrix's diagonal elements, used when type = "Stat-ML" (default: 0)

Psi_struct

string indicating type of structure imposed on the covariance matrix of the residuals, Psi, used when rtn_Sigma = TRUE

  • "scaled_identity" - Psi is a scale identity matrix

  • "diag" - Psi is a diagonal matrix (default)

  • "block_diag" - Psi is a block diagonal matrix, user required to pass stock_sector_info to determine the structure of the blocks

  • "full" - Psi is a full matrix

stock_sector_info

positive integer vector of length N, used when type = "Barra" or Psi_struct = "block_diag"

Details

see factorModel

Value

matrix of dimension N x N, the covariance matrix

Author(s)

ZHOU Rui & Daniel P. Palomar

References

K. Khamaru and R. Mazumder, “Computation of the maximum likelihood estimator in low-rank factor analysis,” arXiv preprint arXiv:1801.05935, 2018.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# generate synthetic data
set.seed(234)
K <- 1   # number of factors
N <- 400  # number of stocks
mu <- rep(0, N)
beta <- mvrnorm(N, rep(1,K), diag(K)/10)
Sigma <- beta %*% t(beta) + diag(N)

# estimate error by loop
err_scm_vs_T <- c()
err_statPCA_diag_vs_T <- c()
index_T <- c()

for (T in N*seq(5)) {
  X <- xts(mvrnorm(T, mu, Sigma), order.by = as.Date('1995-03-15') + 1:T)
  # use statistical factor model by PCA
  cov_statPCA_diag <- covFactorModel(X, K = K, max_iter = 10)
  err_statPCA_diag_vs_T <- c(err_statPCA_diag_vs_T, norm(Sigma - cov_statPCA_diag, "F")^2)
  # use sample covariance matrix
  err_scm_vs_T <- c(err_scm_vs_T, norm(Sigma - cov(X), "F")^2)
  index_T <- c(index_T, T)
}
res <- rbind(index_T/N, err_scm_vs_T, err_statPCA_diag_vs_T)
rownames(res) <- c("T/N", "SCM", "stat-PCA + diag")
print(res)

dppalomar/covFactorModel documentation built on May 17, 2019, 2:14 a.m.