Title: | Covariance Matrix Estimation and Regularization for Finance |
---|---|
Description: | Estimation and regularization for covariance matrix of asset returns. For covariance matrix estimation, three major types of factor models are included: macroeconomic factor model, fundamental factor model and statistical factor model. For covariance matrix regularization, four regularized estimators are included: banding, tapering, hard-thresholding and soft- thresholding. The tuning parameters of these regularized estimators are selected via cross-validation. |
Authors: | YaChen Yan [aut, cre], FangZhu Lin [aut] |
Maintainer: | YaChen Yan <[email protected]> |
License: | GPL-2 |
Version: | 1.1.0 |
Built: | 2024-10-29 02:44:26 UTC |
Source: | https://github.com/yanyachen/fincovregularization |
Apply banding operator on a covariance matrix with a banding parameter.
banding(sigma, k = 0)
banding(sigma, k = 0)
sigma |
a p*p covariance matrix |
k |
banding parameter |
a regularized covariance matrix after banding operation
"High-Dimensional Covariance Estimation" by Mohsen Pourahmadi
data(m.excess.c10sp9003) cov.SAM <- cov(m.excess.c10sp9003) banding(cov.SAM, 7)
data(m.excess.c10sp9003) cov.SAM <- cov(m.excess.c10sp9003) banding(cov.SAM, 7)
Apply K-fold cross-validation for selecting tuning parameters for banding covariance matrix using grid search strategy
banding.cv(matrix, n.cv = 10, norm = "F", seed = 142857)
banding.cv(matrix, n.cv = 10, norm = "F", seed = 142857)
matrix |
a N*p matrix, N indicates sample size and p indicates the dimension |
n.cv |
times that cross-validation repeated, the default number is 10 |
norm |
the norms used to measure the cross-validation errors, which can be the Frobenius norm "F" or the operator norm "O" |
seed |
random seed, the default value is 142857 |
For cross-validation, this function split the sample randomly into two pieces of size n1 = n-n/log(n) and n2 = n/log(n), and repeat this k times
An object of class "CovCv" containing the cross-validation's result for covariance matrix regularization, including:
regularization |
regularization method, which is "Banding" |
parameter.opt |
selected optimal parameter by cross-validation |
cv.error |
the corresponding cross-validation errors |
n.cv |
times that cross-validation repeated |
norm |
the norm used to measure the cross-validation error |
seed |
random seed |
"High-Dimensional Covariance Estimation" by Mohsen Pourahmadi
data(m.excess.c10sp9003) retcov.cv <- banding.cv(m.excess.c10sp9003, n.cv = 10, norm = "F", seed = 142857) summary(retcov.cv) plot(retcov.cv) # Low dimension
data(m.excess.c10sp9003) retcov.cv <- banding.cv(m.excess.c10sp9003, n.cv = 10, norm = "F", seed = 142857) summary(retcov.cv) plot(retcov.cv) # Low dimension
Calculate the squared Frobenius norm of a matrix
F.norm2(matrix)
F.norm2(matrix)
matrix |
a matrix |
a scalar of the squared Frobenius norm
data(m.excess.c10sp9003) cov.SAM <- cov(m.excess.c10sp9003) F.norm2(cov.SAM)
data(m.excess.c10sp9003) cov.SAM <- cov(m.excess.c10sp9003) F.norm2(cov.SAM)
Estimation and regularization for covariance matrix of asset returns. For covariance matrix estimation, three major types of factor models are included: macroeconomic factor model, fundamental factor model and statistical factor model. For covariance matrix regularization, four regularized estimators are included: banding, tapering, hard-thresholding and soft-thresholding. The tuning parameters of these regularized estimators are selected via cross-validation.
Estimate covariance matrix by fitting a fundamental factor model using OLS or WLS regression
FundamentalFactor.Cov(assets, exposure, method = "WLS")
FundamentalFactor.Cov(assets, exposure, method = "WLS")
assets |
a N*p matrix of asset returns, N indicates sample size and p indicates the dimension of asset returns |
exposure |
a p*q matrix of exposure indicator for the fundamental factor model, p corresponds to the dimension of asset returns, q indicates the number of fundamental industries |
method |
a character, indicating regression method: "OLS" or "WLS" |
an estimated p*p covariance matrix
data(m.excess.c10sp9003) assets <- m.excess.c10sp9003[,1:10] Indicator <- matrix(0,10,3) dimnames(Indicator) <- list(colnames(assets),c("Drug","Auto","Oil")) Indicator[c("ABT","LLY","MRK","PFE"),"Drug"] <- 1 Indicator[c("F","GM"),"Auto"] <- 1 Indicator[c("BP","CVX","RD","XOM"),"Oil"] <- 1 FundamentalFactor.Cov(assets,exposure=Indicator,method="WLS")
data(m.excess.c10sp9003) assets <- m.excess.c10sp9003[,1:10] Indicator <- matrix(0,10,3) dimnames(Indicator) <- list(colnames(assets),c("Drug","Auto","Oil")) Indicator[c("ABT","LLY","MRK","PFE"),"Drug"] <- 1 Indicator[c("F","GM"),"Auto"] <- 1 Indicator[c("BP","CVX","RD","XOM"),"Oil"] <- 1 FundamentalFactor.Cov(assets,exposure=Indicator,method="WLS")
Computing a global minimum variance portfolio weights from the estimated covariance matrix of return series.
GMVP(cov.mat, short = TRUE)
GMVP(cov.mat, short = TRUE)
cov.mat |
an estimated p*p covariance matrix |
short |
logical flag, indicating whether shortsales on the risky assets are allowed |
a numerical vector containing the estimated portfolio weights
data(m.excess.c10sp9003) assets <- m.excess.c10sp9003[,1:10] GMVP(cov(assets), short=TRUE) GMVP(cov(assets), short=FALSE)
data(m.excess.c10sp9003) assets <- m.excess.c10sp9003[,1:10] GMVP(cov(assets), short=TRUE) GMVP(cov(assets), short=FALSE)
Apply hard-thresholding operator on a covariance matrix with a hard-thresholding parameter.
hard.thresholding(sigma, threshold = 0.5)
hard.thresholding(sigma, threshold = 0.5)
sigma |
a p*p covariance matrix |
threshold |
hard-thresholding parameter |
a regularized covariance matrix after hard-thresholding operation
"High-Dimensional Covariance Estimation" by Mohsen Pourahmadi
data(m.excess.c10sp9003) cov.SAM <- cov(m.excess.c10sp9003) hard.thresholding(cov.SAM, threshold = 0.001)
data(m.excess.c10sp9003) cov.SAM <- cov(m.excess.c10sp9003) hard.thresholding(cov.SAM, threshold = 0.001)
Apply independence model on a covariance matrix.
Ind.Cov(sigma)
Ind.Cov(sigma)
sigma |
a covariance matrix |
a regularized covariance matrix after applying independence model
data(m.excess.c10sp9003) cov.SAM <- cov(m.excess.c10sp9003) Ind.Cov(cov.SAM)
data(m.excess.c10sp9003) cov.SAM <- cov(m.excess.c10sp9003) Ind.Cov(cov.SAM)
A dataset containing monthly excess returns of 10 stocks and S$P 500 index return from January 1990 to December 2003
data(m.excess.c10sp9003)
data(m.excess.c10sp9003)
A matrix with 168 rows and 11 variables
Estimate covariance matrix by fitting a macroeconomic factor model using time series regression
MacroFactor.Cov(assets, factor)
MacroFactor.Cov(assets, factor)
assets |
a N*p matrix of asset returns, N indicates sample size and p indicates the dimension of asset returns |
factor |
a numerical vector of length N, or a N*q matrix of macroeconomic factor(s), q indicates the dimension of factors |
an estimated p*p covariance matrix
data(m.excess.c10sp9003) assets <- m.excess.c10sp9003[,1:10] factor <- m.excess.c10sp9003[,11] MacroFactor.Cov(assets, factor)
data(m.excess.c10sp9003) assets <- m.excess.c10sp9003[,1:10] factor <- m.excess.c10sp9003[,11] MacroFactor.Cov(assets, factor)
Calculate the squared Operator norm of a matrix
O.norm2(matrix)
O.norm2(matrix)
matrix |
a matrix |
a scalar of the squared Operator norm
data(m.excess.c10sp9003) cov.SAM <- cov(m.excess.c10sp9003) O.norm2(cov.SAM)
data(m.excess.c10sp9003) cov.SAM <- cov(m.excess.c10sp9003) O.norm2(cov.SAM)
Computing a Risk Parity portfolio weights from the estimated covariance matrix of return series.
RiskParity(cov.mat)
RiskParity(cov.mat)
cov.mat |
an estimated p*p covariance matrix |
a numerical vector containing the estimated portfolio weights
data(m.excess.c10sp9003) assets <- m.excess.c10sp9003[,1:10] RiskParity(cov(assets))
data(m.excess.c10sp9003) assets <- m.excess.c10sp9003[,1:10] RiskParity(cov(assets))
Apply soft-thresholding operator on a covariance matrix with a soft-thresholding parameter.
soft.thresholding(sigma, threshold = 0.5)
soft.thresholding(sigma, threshold = 0.5)
sigma |
a covariance matrix |
threshold |
soft-thresholding parameter |
a regularized covariance matrix after soft-thresholding operation
"High-Dimensional Covariance Estimation" by Mohsen Pourahmadi
data(m.excess.c10sp9003) cov.SAM <- cov(m.excess.c10sp9003) soft.thresholding(cov.SAM, threshold = 0.001)
data(m.excess.c10sp9003) cov.SAM <- cov(m.excess.c10sp9003) soft.thresholding(cov.SAM, threshold = 0.001)
Estimate covariance matrix by fitting a statistical factor model using principle components analysis
StatFactor.Cov(assets, k = 0)
StatFactor.Cov(assets, k = 0)
assets |
a matrix of asset returns |
k |
numbers of factors, if k = 0, automatically estimating by Kaiser method |
an estimated p*p covariance matrix
data(m.excess.c10sp9003) assets <- m.excess.c10sp9003[,1:10] StatFactor.Cov(assets, 3)
data(m.excess.c10sp9003) assets <- m.excess.c10sp9003[,1:10] StatFactor.Cov(assets, 3)
Apply tapering operator on a covariance matrix with tapering parameters.
tapering(sigma, l, h = 1/2)
tapering(sigma, l, h = 1/2)
sigma |
a p*p covariance matrix |
l |
tapering parameter |
h |
the ratio between taper l_h and parameter l |
a regularized covariance matrix after tapering operation
"High-Dimensional Covariance Estimation" by Mohsen Pourahmadi
data(m.excess.c10sp9003) cov.SAM <- cov(m.excess.c10sp9003) tapering(cov.SAM, l=7, h = 1/2)
data(m.excess.c10sp9003) cov.SAM <- cov(m.excess.c10sp9003) tapering(cov.SAM, l=7, h = 1/2)
Apply K-fold cross-validation for selecting tuning parameters for tapering covariance matrix using grid search strategy
tapering.cv(matrix, h = 1/2, n.cv = 10, norm = "F", seed = 142857)
tapering.cv(matrix, h = 1/2, n.cv = 10, norm = "F", seed = 142857)
matrix |
a N*p matrix, N indicates sample size and p indicates the dimension |
h |
the ratio between taper l_h and parameter l |
n.cv |
times that cross-validation repeated, the default number is 10 |
norm |
the norms used to measure the cross-validation errors, which can be the Frobenius norm "F" or the operator norm "O" |
seed |
random seed, the default value is 142857 |
For cross-validation, this function split the sample randomly into two pieces of size n1 = n-n/log(n) and n2 = n/log(n), and repeat this k times
An object of class "CovCv" containing the cross-validation's result for covariance matrix regularization, including:
regularization |
regularization method, which is "Tapering" |
parameter.opt |
selected optimal parameter by cross-validation |
cv.error |
the corresponding cross-validation errors |
n.cv |
times that cross-validation repeated |
norm |
the norm used to measure the cross-validation error |
seed |
random seed |
"High-Dimensional Covariance Estimation" by Mohsen Pourahmadi
data(m.excess.c10sp9003) retcov.cv <- tapering.cv(m.excess.c10sp9003, n.cv = 10, norm = "F", seed = 142857) summary(retcov.cv) plot(retcov.cv) # Low dimension
data(m.excess.c10sp9003) retcov.cv <- tapering.cv(m.excess.c10sp9003, n.cv = 10, norm = "F", seed = 142857) summary(retcov.cv) plot(retcov.cv) # Low dimension
Apply K-fold cross-validation for selecting tuning parameters for thresholding covariance matrix using grid search strategy
threshold.cv(matrix, method = "hard", thresh.len = 20, n.cv = 10, norm = "F", seed = 142857)
threshold.cv(matrix, method = "hard", thresh.len = 20, n.cv = 10, norm = "F", seed = 142857)
matrix |
a N*p matrix, N indicates sample size and p indicates the dimension |
method |
thresholding method, "hard" or "soft" |
thresh.len |
the number of thresholding values tested in
cross-validation, the thresholding values will be a sequence of
|
n.cv |
times that cross-validation repeated, the default number is 10 |
norm |
the norms used to measure the cross-validation errors, which can be the Frobenius norm "F" or the operator norm "O" |
seed |
random seed, the default value is 142857 |
For cross-validation, this function split the sample randomly into two pieces of size n1 = n-n/log(n) and n2 = n/log(n), and repeat this k times
An object of class "CovCv" containing the cross-validation's result for covariance matrix regularization, including:
regularization |
regularization method, which is "Hard Thresholding" or "Soft Thresholding" |
parameter.opt |
selected optimal parameter by cross-validation |
cv.error |
the corresponding cross-validation errors |
n.cv |
times that cross-validation repeated |
norm |
the norm used to measure the cross-validation error |
seed |
random seed |
threshold.grid |
thresholding values tested in cross-validation |
"High-Dimensional Covariance Estimation" by Mohsen Pourahmadi
data(m.excess.c10sp9003) retcov.cv <- threshold.cv(m.excess.c10sp9003, method = "hard", thresh.len = 20, n.cv = 10, norm = "F", seed = 142857) summary(retcov.cv) plot(retcov.cv) # Low dimension
data(m.excess.c10sp9003) retcov.cv <- threshold.cv(m.excess.c10sp9003, method = "hard", thresh.len = 20, n.cv = 10, norm = "F", seed = 142857) summary(retcov.cv) plot(retcov.cv) # Low dimension