factorModel: Factor Model Decomposition

Description Usage Arguments Details Value Author(s) Examples

Description

Decomposes data matrix into factors and residual idiosyncratic component.

Usage

1
2
3
4
factorModel(X, type = c("Stat-PCA", "Macro", "Barra"), econ_fact, K = 1,
  orthonormal = c("factor", "beta"), max_iter = 10, tol = 0.001,
  Psi_struct = c("diag", "block_diag", "scaled_identity", "full"),
  stock_sector_info = NA, rtn_Sigma = FALSE)

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 by PCA, requires user to pass number of factors K (default)

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" (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 when build statistical factor model, used when type = "Stat-PCA" (default: 10)

tol

double object indicating relative tolerance to determine convergence when estimate statistical factor model, used when type = "Stat-PCA" (default: 0.001)

Psi_struct

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

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

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

  • "scaled_identity" - Psi is a scale identity matrix

  • "full" - Psi is a full matrix

stock_sector_info

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

rtn_Sigma

logical variable indicating whether to calculate and return the covariance matrix

Details

Decomposes data matrix into factors and residual idiosyncratic component. The user can choose different types of factor models, namely, macroeconomic, BARRA, or statistical. For macroeconomic factor model, set type = "Macro" and pass argument econ_fact; for BARRA Industry factor model, set type = "Barra" and pass argument stock_sector_info (or make column names of X be in the in-built database data(stock_sector_database)); for statistical factors model, set type = "Stat-PCA" and pass argument K, max_iter, tol and Psi_struct, and possibly stock_sector_info if a block diagonal structure for Psi is required. This function can also estimate covariance matrix when set rtn_Sigma = TRUE. User can choose different type of residual covariance matrix, namely, scaled identity, diagonal, block diagonal or full.

Value

A list with following components:

alpha

vector of length N, the constant part

beta

matrix of dimension N x K, the loading matrix

factors

xts object of dimension T x K, the factor data matrix

residual

xts object of dimension T x N, the residual data matrix

Sigma

matrix of dimension N x N, the covariance matrix, only returned when rtn_Sigma = TRUE

Author(s)

ZHOU Rui & Daniel P. Palomar

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
26
# generate synthetic data
set.seed(234)
N <- 3  # number of stocks
T <- 5  # number of samples
mu <- rep(0, N)
Sigma <- diag(N)/1000

# generate asset returns TxN data matrix
X <- xts(mvrnorm(T, mu, Sigma), order.by = as.Date('2017-04-15') + 1:T) 
colnames(X) <- c("A", "B", "C")

# generate K=2 macroeconomic factors
econ_fact <- xts(mvrnorm(T, c(0, 0), diag(2)/1000), order.by = index(X))
colnames(econ_fact) <- c("factor1", "factor2")

# build a macroeconomic factor model
macro_econ_model <- factorModel(X, type = "Macro", econ_fact = econ_fact)

# build a BARRA industry factor model 
# (assuming assets A and C belong to sector 1 and asset B to sector 2)
stock_sector_info <- c(1, 2, 1)
barra_model <- factorModel(X, type = "Barra", stock_sector_info = stock_sector_info)

# build a statistical factor model
# set factor dimension as K=2
stat_model <- factorModel(X, K = 2)

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