Title: | High-Dimensional Shrinkage Optimal Portfolios |
---|---|
Description: | Constructs shrinkage estimators of high-dimensional mean-variance portfolios and performs high-dimensional tests on optimality of a given portfolio. The techniques developed in Bodnar et al. (2018 <doi:10.1016/j.ejor.2017.09.028>, 2019 <doi:10.1109/TSP.2019.2929964>, 2020 <doi:10.1109/TSP.2020.3037369>, 2021 <doi:10.1080/07350015.2021.2004897>) are central to the package. They provide simple and feasible estimators and tests for optimal portfolio weights, which are applicable for 'large p and large n' situations where p is the portfolio dimension (number of stocks) and n is the sample size. The package also includes tools for constructing portfolios based on shrinkage estimators of the mean vector and covariance matrix as well as a new Bayesian estimator for the Markowitz efficient frontier recently developed by Bauder et al. (2021) <doi:10.1080/14697688.2020.1748214>. |
Authors: | Taras Bodnar [aut] , Solomiia Dmytriv [aut] , Yarema Okhrin [aut] , Dmitry Otryakhin [aut, cre] , Nestor Parolya [aut] |
Maintainer: | Dmitry Otryakhin <[email protected]> |
License: | GPL-3 |
Version: | 0.1.5 |
Built: | 2024-11-22 04:21:30 UTC |
Source: | https://github.com/otryakhin-dmitry/global-minimum-variance-portfolio |
Class MeanVar_portfolio is designed to construct mean-variance portfolios with provided estimators of the mean vector, covariance matrix, and inverse covariance matrix. It includes the following elements:
Element | Description |
call | the function call with which it was created |
cov_mtrx | the sample covariance matrix of the asset returns |
inv_cov_mtrx | the inverse of the sample covariance matrix |
means | sample mean vector of the asset returns |
weights | portfolio weights |
Port_Var | portfolio variance |
Port_mean_return | expected portfolio return |
Sharpe | portfolio Sharpe ratio |
summary.MeanVar_portfolio summary method for the class, new_MeanVar_portfolio class constructor, validate_MeanVar_portfolio class validator, MeanVar_portfolio class helper.
It is a function dispatcher for covariance matrix estimation. One can choose between traditional and shrinkage-based estimators.
CovarEstim(x, type = c("trad", "BGP14", "LW20"), ...)
CovarEstim(x, type = c("trad", "BGP14", "LW20"), ...)
x |
a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations. |
type |
a character. The estimation method to be used. |
... |
arguments to pass to estimators |
The available estimation methods are:
Function | Paper | Type |
Sigma_sample_estimator |
traditional | |
CovShrinkBGP14 |
Bodnar et al 2014 | BGP14 |
nonlin_shrinkLW |
Ledoit & Wolf 2020 | LW20 |
an object of class matrix
n<-3e2 # number of realizations p<-.5*n # number of assets x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) Mtrx_trad <- CovarEstim(x, type="trad") TM <- matrix(0, p, p) diag(TM) <- 1 Mtrx_bgp <- CovarEstim(x, type="BGP14", TM=TM) Mtrx_lw <- CovarEstim(x, type="LW20")
n<-3e2 # number of realizations p<-.5*n # number of assets x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) Mtrx_trad <- CovarEstim(x, type="trad") TM <- matrix(0, p, p) diag(TM) <- 1 Mtrx_bgp <- CovarEstim(x, type="BGP14", TM=TM) Mtrx_lw <- CovarEstim(x, type="LW20")
The optimal linear shrinkage estimator of the covariance matrix that minimizes the Frobenius norm:
where and
are optimal shrinkage
intensities given in Eq. (4.3) and (4.4) of
Bodnar et al. (2014).
is the sample covariance
matrix (SCM, see
Sigma_sample_estimator
) and
is a positive definite symmetric matrix used as the target matrix (TM),
for example,
.
CovShrinkBGP14(n, TM, SCM)
CovShrinkBGP14(n, TM, SCM)
n |
sample size. |
TM |
the target matrix for the shrinkage estimator. |
SCM |
sample covariance matrix. |
a list containing an object of class matrix (S) and the estimated
shrinkage intensities and
.
Bodnar T, Gupta AK, Parolya N (2014). “On the strong convergence of the optimal linear shrinkage estimator for large dimensional covariance matrix.” Journal of Multivariate Analysis, 132, 215–228.
# Parameter setting n<-3e2 c<-0.7 p<-c*n mu <- rep(0, p) Sigma <- RandCovMtrx(p=p) # Generating observations X <- t(MASS::mvrnorm(n=n, mu=mu, Sigma=Sigma)) # Estimation TM <- matrix(0, nrow=p, ncol=p) diag(TM) <- 1/p SCM <- Sigma_sample_estimator(X) Sigma_shr <- CovShrinkBGP14(n=n, TM=TM, SCM=SCM) Sigma_shr$S[1:6, 1:6]
# Parameter setting n<-3e2 c<-0.7 p<-c*n mu <- rep(0, p) Sigma <- RandCovMtrx(p=p) # Generating observations X <- t(MASS::mvrnorm(n=n, mu=mu, Sigma=Sigma)) # Estimation TM <- matrix(0, nrow=p, ncol=p) diag(TM) <- 1/p SCM <- Sigma_sample_estimator(X) Sigma_shr <- CovShrinkBGP14(n=n, TM=TM, SCM=SCM) Sigma_shr$S[1:6, 1:6]
The optimal linear shrinkage estimator of the inverse covariance (precision) matrix that minimizes the Frobenius norm is given by:
where and
are optimal shrinkage
intensities given in Eq. (4.4) and (4.5) of Bodnar et al. (2016).
is the inverse of the sample covariance matrix (iSCM) and
is a positive definite symmetric matrix used as the target
matrix (TM), for example, I.
InvCovShrinkBGP16(n, p, TM, iSCM)
InvCovShrinkBGP16(n, p, TM, iSCM)
n |
the number of observations |
p |
the number of variables (rows of the covariance matrix) |
TM |
the target matrix for the shrinkage estimator |
iSCM |
the inverse of the sample covariance matrix |
a list containing an object of class matrix (S) and the estimated
shrinkage intensities and
.
Bodnar T, Gupta AK, Parolya N (2016). “Direct shrinkage estimation of large dimensional precision matrix.” Journal of Multivariate Analysis, 146, 223–236.
# Parameter setting n <- 3e2 c <- 0.7 p <- c*n mu <- rep(0, p) Sigma <- RandCovMtrx(p=p) # Generating observations X <- t(MASS::mvrnorm(n=n, mu=mu, Sigma=Sigma)) # Estimation TM <- matrix(0, nrow=p, ncol=p) diag(TM) <- 1 iSCM <- solve(Sigma_sample_estimator(X)) Sigma_shr <- InvCovShrinkBGP16(n=n, p=p, TM=TM, iSCM=iSCM) Sigma_shr$S[1:6, 1:6]
# Parameter setting n <- 3e2 c <- 0.7 p <- c*n mu <- rep(0, p) Sigma <- RandCovMtrx(p=p) # Generating observations X <- t(MASS::mvrnorm(n=n, mu=mu, Sigma=Sigma)) # Estimation TM <- matrix(0, nrow=p, ncol=p) diag(TM) <- 1 iSCM <- solve(Sigma_sample_estimator(X)) Sigma_shr <- InvCovShrinkBGP16(n=n, p=p, TM=TM, iSCM=iSCM) Sigma_shr$S[1:6, 1:6]
Shrinkage estimator of the high-dimensional mean vector as suggested in Bodnar et al. (2019). It uses the formula
where
and
are shrinkage coefficients given by
Eq.(6) and Eg.(7) of Bodnar et al. (2019) that minimize
weighted quadratic loss for a given target vector
(shrinkage target).
stands for the sample mean vector.
mean_bop19(x, mu_0 = rep(1, p))
mean_bop19(x, mu_0 = rep(1, p))
x |
a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations. |
mu_0 |
a numeric vector. The target vector used in the construction of the shrinkage estimator. |
a numeric vector containing the shrinkage estimator of the mean vector
Bodnar T, Okhrin O, Parolya N (2019). “Optimal shrinkage estimator for high-dimensional mean vector.” Journal of Multivariate Analysis, 170, 63–79.
n<-7e2 # number of realizations p<-.5*n # number of assets x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) mm <- mean_bop19(x=x, mu_0=rep(1,p))
n<-7e2 # number of realizations p<-.5*n # number of assets x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) mm <- mean_bop19(x=x, mu_0=rep(1,p))
Bayes-Stein shrinkage estimator of the mean vector as suggested in Jorion (1986). The estimator is given by
where
is the sample mean vector,
and
are
derived using Bayesian approach (see Eq.(14) and Eq.(17) in
Jorion (1986)).
mean_bs(x)
mean_bs(x)
x |
a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations. |
a numeric vector containing the Bayes-Stein shrinkage estimator of the mean vector
Jorion P (1986). “Bayes-Stein estimation for portfolio analysis.” Journal of Financial and Quantitative Analysis, 279–292.
n <- 7e2 # number of realizations p <- .5*n # number of assets x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) mm <- mean_bs(x=x)
n <- 7e2 # number of realizations p <- .5*n # number of assets x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) mm <- mean_bs(x=x)
James-Stein shrinkage estimator of the mean vector as suggested in Jorion (1986). The estimator is given by
where is the sample mean vector,
is the shrinkage
coefficient which minimizes a quadratic loss given by Eq.(11) in
Jorion (1986).
is a prespecified value.
mean_js(x, Y_0 = 1)
mean_js(x, Y_0 = 1)
x |
a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations. |
Y_0 |
a numeric variable. Shrinkage target coefficient. |
a numeric vector containing the James-Stein shrinkage estimator of the mean vector.
Jorion P (1986). “Bayes-Stein estimation for portfolio analysis.” Journal of Financial and Quantitative Analysis, 279–292.
n<-7e2 # number of realizations p<-.5*n # number of assets x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) mm <- mean_js(x=x, Y_0 = 1)
n<-7e2 # number of realizations p<-.5*n # number of assets x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) mm <- mean_js(x=x, Y_0 = 1)
A user-friendly function for estimation of the mean vector. Essentially, it is a function dispatcher for estimation of the mean vector that chooses a method accordingly to the type argument.
MeanEstim(x, type, ...)
MeanEstim(x, type, ...)
x |
a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations. |
type |
a character. The estimation method to be used. |
... |
arguments to pass to estimators |
The available estimation methods for the mean are:
Function | Paper | Type |
.rowMeans | trad | |
mean_bs |
Jorion 1986 | bs |
mean_js |
Jorion 1986 | js |
mean_bop19 |
Bodnar et al 2019 | BOP19 |
a numeric vector— a value of the specified estimator of the mean vector.
Jorion P (1986). “Bayes-Stein estimation for portfolio analysis.” Journal of Financial and Quantitative Analysis, 279–292.
Bodnar T, Okhrin O, Parolya N (2019). “Optimal shrinkage estimator for high-dimensional mean vector.” Journal of Multivariate Analysis, 170, 63–79.
n<-3e2 # number of realizations p<-.5*n # number of assets x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) Mean_trad <- MeanEstim(x, type="trad") mu_0 <- rep(1/p, p) Mean_BOP <- MeanEstim(x, type="BOP19", mu_0=mu_0)
n<-3e2 # number of realizations p<-.5*n # number of assets x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) Mean_trad <- MeanEstim(x, type="trad") mu_0 <- rep(1/p, p) Mean_BOP <- MeanEstim(x, type="BOP19", mu_0=mu_0)
A user-friendly function making mean-variance portfolios for assets with customly computed covariance matrix and mean returns. The weights are computed in accordance with the formula
where is an estimator for the covariance matrix,
is an estimator for the mean vector,
is
the coefficient of risk aversion, and
is given by
The computation is made by new_MeanVar_portfolio
and
the result is validated by validate_MeanVar_portfolio
.
MeanVar_portfolio(mean_vec, cov_mtrx, gamma)
MeanVar_portfolio(mean_vec, cov_mtrx, gamma)
mean_vec |
mean vector of asset returns provided in the form of a vector or a list. |
cov_mtrx |
the covariance matrix of asset returns. It could be a matrix or a data frame. |
gamma |
a numeric variable. Coefficient of risk aversion. |
Mean-variance portfolio in the form of object of S3 class MeanVar_portfolio.
n<-3e2 # number of realizations p<-.5*n # number of assets gamma<-1 x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) # Simple MV portfolio cov_mtrx <- Sigma_sample_estimator(x) means <- rowMeans(x) cust_port_simp <- MeanVar_portfolio(mean_vec=means, cov_mtrx=cov_mtrx, gamma=2) str(cust_port_simp)
n<-3e2 # number of realizations p<-.5*n # number of assets gamma<-1 x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) # Simple MV portfolio cov_mtrx <- Sigma_sample_estimator(x) means <- rowMeans(x) cust_port_simp <- MeanVar_portfolio(mean_vec=means, cov_mtrx=cov_mtrx, gamma=2) str(cust_port_simp)
The main function for mean-variance (also known as expected utility) portfolio construction. It is a dispatcher using methods according to argument type, values of gamma and dimensionality of matrix x.
MVShrinkPortfolio(x, gamma, type = c("shrinkage", "traditional"), ...)
MVShrinkPortfolio(x, gamma, type = c("shrinkage", "traditional"), ...)
x |
a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations. |
gamma |
a numeric variable. Coefficient of risk aversion. |
type |
a character. The type of methods to use to construct the portfolio. |
... |
arguments to pass to portfolio constructors |
The sample estimator of the mean-variance portfolio weights, which results in a traditional mean-variance portfolio, is calculated by
where and
are the inverse of the sample covariance
matrix and the sample mean vector of asset returns respectively,
is the coefficient of risk aversion and
is given by
In the case when ,
becomes
- Moore-Penrose
inverse. The shrinkage estimator for the mean-variance portfolio weights in
a high-dimensional setting is given by
where is the estimated shrinkage intensity and
is
a target vector with the sum of the elements equal to one.
In the case ,
is computed following
Eq. (2.22) of Bodnar et al. (2023) for c<1 and following
Eq. (2.29) of Bodnar et al. (2023) for c>1.
The case of a fully risk averse investor () leads to the
traditional global minimum variance (GMV) portfolio with the weights given by
The shrinkage estimator for the GMV portfolio is then calculated by
with given in
Eq. (2.31) of Bodnar et al. (2018) for c<1 and in
Eq. (2.33) of Bodnar et al. (2018) for c>1.
These estimation methods are available as separate functions employed by MVShrinkPortfolio accordingly to the following parameter configurations:
Function | Paper | Type | gamma | p/n |
new_MV_portfolio_weights_BDOPS21 |
Bodnar et al. (2023) | shrinkage | < Inf | <1 |
new_MV_portfolio_weights_BDOPS21_pgn |
Bodnar et al. (2023) | shrinkage | < Inf | >1 |
new_GMV_portfolio_weights_BDPS19 |
Bodnar et al. (2018) | shrinkage | Inf | <1 |
new_GMV_portfolio_weights_BDPS19_pgn |
Bodnar et al. (2018) | shrinkage | Inf | >1 |
new_MV_portfolio_traditional |
traditional | > 0 | <1 | |
new_MV_portfolio_traditional_pgn |
traditional | > 0 | >1 | |
A portfolio in the form of an object of class MeanVar_portfolio
potentially with a subclass.
See Class_MeanVar_portfolio
for the details of the class.
Bodnar T, Okhrin Y, Parolya N (2023).
“Optimal shrinkage-based portfolio selection in high dimensions.”
Journal of Business & Economic Statistics, 41, 140-156.
Bodnar T, Parolya N, Schmid W (2018).
“Estimation of the global minimum variance portfolio in high dimensions.”
European Journal of Operational Research, 266(1), 371–390.
n<-3e2 # number of realizations gamma<-1 # The case p<n p<-.5*n # number of assets b<-rep(1/p,p) x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) test <- MVShrinkPortfolio(x=x, gamma=gamma, type='shrinkage', b=b, beta = 0.05) str(test) test <- MVShrinkPortfolio(x=x, gamma=Inf, type='shrinkage', b=b, beta = 0.05) str(test) test <- MVShrinkPortfolio(x=x, gamma=gamma, type='traditional') str(test) # The case p>n p<-1.2*n # Re-define the number of assets b<-rep(1/p,p) x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) test <- MVShrinkPortfolio(x=x, gamma=gamma, type='shrinkage', b=b, beta = 0.05) str(test) test <- MVShrinkPortfolio(x=x, gamma=Inf, type='shrinkage', b=b, beta = 0.05) str(test)
n<-3e2 # number of realizations gamma<-1 # The case p<n p<-.5*n # number of assets b<-rep(1/p,p) x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) test <- MVShrinkPortfolio(x=x, gamma=gamma, type='shrinkage', b=b, beta = 0.05) str(test) test <- MVShrinkPortfolio(x=x, gamma=Inf, type='shrinkage', b=b, beta = 0.05) str(test) test <- MVShrinkPortfolio(x=x, gamma=gamma, type='traditional') str(test) # The case p>n p<-1.2*n # Re-define the number of assets b<-rep(1/p,p) x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) test <- MVShrinkPortfolio(x=x, gamma=gamma, type='shrinkage', b=b, beta = 0.05) str(test) test <- MVShrinkPortfolio(x=x, gamma=Inf, type='shrinkage', b=b, beta = 0.05) str(test)
Constructor of global minimum variance portfolio.
new_GMV_portfolio_weights_BDPS19 is for the case p<n, while
new_GMV_portfolio_weights_BDPS19_pgn is for p>n, where p is the number of
assets and n is the number of observations. For more details
of the method, see MVShrinkPortfolio
.
new_GMV_portfolio_weights_BDPS19(x, b, beta) new_GMV_portfolio_weights_BDPS19_pgn(x, b, beta)
new_GMV_portfolio_weights_BDPS19(x, b, beta) new_GMV_portfolio_weights_BDPS19_pgn(x, b, beta)
x |
a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations. |
b |
a numeric vector. 1-beta is the confidence level of the symmetric confidence interval, constructed for each weight. |
beta |
a numeric variable. The confidence level for weight intervals. |
an object of class MeanVar_portfolio with subclass GMV_portfolio_weights_BDPS19.
Element | Description |
call | the function call with which it was created |
cov_mtrx | the sample covariance matrix of the asset returns |
inv_cov_mtrx | the inverse of the sample covariance matrix |
means | sample mean vector estimate of the asset returns |
w_GMVP | sample estimator of portfolio weights |
weights | shrinkage estimator of portfolio weights |
alpha | shrinkage intensity for the weights |
Port_Var | portfolio variance |
Port_mean_return | expected portfolio return |
Sharpe | portfolio Sharpe ratio |
weight_intervals | A data frame, see details |
weight_intervals contains a shrinkage estimator of portfolio weights, asymptotic confidence intervals for the true portfolio weights, the value of test statistic and the p-value of the test on the equality of the weight of each individual asset to zero (see Section 4.3 of Bodnar et al. 2023). weight_intervals is only computed when p<n.
Bodnar T, Dmytriv S, Parolya N, Schmid W (2019). “Tests for the weights of the global minimum variance portfolio in a high-dimensional setting.” IEEE Transactions on Signal Processing, 67(17), 4479–4493.
Bodnar T, Parolya N, Schmid W (2018). “Estimation of the global minimum variance portfolio in high dimensions.” European Journal of Operational Research, 266(1), 371–390.
Bodnar T, Dette H, Parolya N, Thorsén E (2023). “Corrigendum to "Sampling Distributions of Optimal Portfolio Weights and Characteristics in Low and Large Dimensions.".” Random Matrices: Theory and Applications, 12, 2392001. doi:10.1142/S2010326323920016.
# c<1 n <- 3e2 # number of realizations p <- .5*n # number of assets b <- rep(1/p,p) # Assets with a diagonal covariance matrix x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) test <- new_GMV_portfolio_weights_BDPS19(x=x, b=b, beta=0.05) str(test) # Assets with a non-diagonal covariance matrix Mtrx <- RandCovMtrx(p=p) x <- t(MASS::mvrnorm(n=n , mu=rep(0,p), Sigma=Mtrx)) test <- new_GMV_portfolio_weights_BDPS19(x=x, b=b, beta=0.05) summary(test) # c>1 p <- 1.3*n # number of assets b <- rep(1/p,p) # Assets with a diagonal covariance matrix x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) test <- new_GMV_portfolio_weights_BDPS19_pgn(x=x, b=b, beta=0.05) str(test)
# c<1 n <- 3e2 # number of realizations p <- .5*n # number of assets b <- rep(1/p,p) # Assets with a diagonal covariance matrix x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) test <- new_GMV_portfolio_weights_BDPS19(x=x, b=b, beta=0.05) str(test) # Assets with a non-diagonal covariance matrix Mtrx <- RandCovMtrx(p=p) x <- t(MASS::mvrnorm(n=n , mu=rep(0,p), Sigma=Mtrx)) test <- new_GMV_portfolio_weights_BDPS19(x=x, b=b, beta=0.05) summary(test) # c>1 p <- 1.3*n # number of assets b <- rep(1/p,p) # Assets with a diagonal covariance matrix x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) test <- new_GMV_portfolio_weights_BDPS19_pgn(x=x, b=b, beta=0.05) str(test)
A light-weight constructor of objects of S3 class MeanVar_portfolio.
This function is for development purposes. A helper function equipped with
error messages and allowing more flexible input is
MeanVar_portfolio
.
new_MeanVar_portfolio(mean_vec, cov_mtrx, gamma)
new_MeanVar_portfolio(mean_vec, cov_mtrx, gamma)
mean_vec |
mean vector of asset returns |
cov_mtrx |
the covariance matrix of asset returns |
gamma |
a numeric variable. Coefficient of risk aversion. |
Mean-variance portfolio in the form of object of S3 class MeanVar_portfolio.
n<-3e2 # number of realizations p<-.5*n # number of assets gamma<-1 x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) # Simple MV portfolio cov_mtrx <- Sigma_sample_estimator(x) means <- rowMeans(x) cust_port_simp <- new_MeanVar_portfolio(mean_vec=means, cov_mtrx=cov_mtrx, gamma=2) str(cust_port_simp) # Portfolio with Bayes-Stein shrunk means # and a Ledoit and Wolf estimator for covariance matrix TM <- matrix(0, p, p) diag(TM) <- 1 cov_mtrx <- CovarEstim(x, type="LW20", TM=TM) means <- mean_bs(x) cust_port_BS_LW <- new_MeanVar_portfolio(mean_vec=means$means, cov_mtrx=cov_mtrx, gamma=2) str(cust_port_BS_LW)
n<-3e2 # number of realizations p<-.5*n # number of assets gamma<-1 x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) # Simple MV portfolio cov_mtrx <- Sigma_sample_estimator(x) means <- rowMeans(x) cust_port_simp <- new_MeanVar_portfolio(mean_vec=means, cov_mtrx=cov_mtrx, gamma=2) str(cust_port_simp) # Portfolio with Bayes-Stein shrunk means # and a Ledoit and Wolf estimator for covariance matrix TM <- matrix(0, p, p) diag(TM) <- 1 cov_mtrx <- CovarEstim(x, type="LW20", TM=TM) means <- mean_bs(x) cust_port_BS_LW <- new_MeanVar_portfolio(mean_vec=means$means, cov_mtrx=cov_mtrx, gamma=2) str(cust_port_BS_LW)
Mean-variance portfolios with the traditional (sample) estimators for
the mean vector and the covariance matrix of asset returns.
For more details of the method, see MVShrinkPortfolio
.
new_MV_portfolio_traditional is for the case p<n, while
new_MV_portfolio_traditional_pgn is for p>n, where p is the number of
assets and n is the number of observations.
new_MV_portfolio_traditional(x, gamma) new_MV_portfolio_traditional_pgn(x, gamma)
new_MV_portfolio_traditional(x, gamma) new_MV_portfolio_traditional_pgn(x, gamma)
x |
a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations. |
gamma |
a numeric variable. Coefficient of risk aversion. |
an object of class MeanVar_portfolio
Element | Description |
call | the function call with which it was created |
cov_mtrx | the sample covariance matrix of asset returns |
inv_cov_mtrx | the inverse of the sample covariance matrix |
means | sample mean estimator of the asset returns |
W_mv_hat | sample estimator of portfolio weights |
Port_Var | portfolio variance |
Port_mean_return | expected portfolio return |
Sharpe | portfolio Sharpe ratio |
n <- 3e2 # number of realizations p <- .5*n # number of assets gamma <- 1 x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) test <- new_MV_portfolio_traditional(x=x, gamma=gamma) str(test)
n <- 3e2 # number of realizations p <- .5*n # number of assets gamma <- 1 x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) test <- new_MV_portfolio_traditional(x=x, gamma=gamma) str(test)
Constructor of mean-variance shrinkage portfolios.
new_MV_portfolio_weights_BDOPS21 is for the case p<n, while
new_MV_portfolio_weights_BDOPS21_pgn is for p>n, where p is the number of
assets and n is the number of observations.
For more details of the method, see MVShrinkPortfolio
.
new_MV_portfolio_weights_BDOPS21(x, gamma, b, beta) new_MV_portfolio_weights_BDOPS21_pgn(x, gamma, b, beta)
new_MV_portfolio_weights_BDOPS21(x, gamma, b, beta) new_MV_portfolio_weights_BDOPS21_pgn(x, gamma, b, beta)
x |
a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations. |
gamma |
a numeric variable. Coefficient of risk aversion. |
b |
a numeric variable. 1-beta is the confidence level of the symmetric confidence interval, constructed for each weight. |
beta |
a numeric variable. The confidence level for weight intervals. |
an object of class MeanVar_portfolio with subclass MV_portfolio_weights_BDOPS21.
Element | Description |
call | the function call with which it was created |
cov_mtrx | the sample covariance matrix of the asset returns |
inv_cov_mtrx | the inverse of the sample covariance matrix |
means | sample mean vector of the asset returns |
W_mv_hat | sample estimator of the portfolio weights |
weights | shrinkage estimator of the portfolio weights |
alpha | shrinkage intensity for the weights |
Port_Var | portfolio variance |
Port_mean_return | expected portfolio return |
Sharpe | portfolio Sharpe ratio |
weight_intervals | A data frame, see details |
weight_intervals contains a shrinkage estimator of portfolio weights, asymptotic confidence intervals for the true portfolio weights, value of the test statistic and the p-value of the test on the equality of the weight of each individual asset to zero (see Section 4.3 of Bodnar et al. 2023) weight_intervals is only computed when p<n.
Bodnar T, Dmytriv S, Okhrin Y, Parolya N, Schmid W (2021). “Statistical Inference for the Expected Utility Portfolio in High Dimensions.” IEEE Transactions on Signal Processing, 69, 1-14.
Bodnar T, Dette H, Parolya N, Thorsén E (2023). “Corrigendum to "Sampling Distributions of Optimal Portfolio Weights and Characteristics in Low and Large Dimensions.".” Random Matrices: Theory and Applications, 12, 2392001. doi:10.1142/S2010326323920016.
# c<1 # Assets with a diagonal covariance matrix n <- 3e2 # number of realizations p <- .5*n # number of assets b <- rep(1/p,p) gamma <- 1 x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) test <- new_MV_portfolio_weights_BDOPS21(x=x, gamma=gamma, b=b, beta=0.05) summary(test) # Assets with a non-diagonal covariance matrix Mtrx <- RandCovMtrx(p=p) x <- t(MASS::mvrnorm(n=n , mu=rep(0,p), Sigma=Mtrx)) test <- new_MV_portfolio_weights_BDOPS21(x=x, gamma=gamma, b=b, beta=0.05) str(test) # c>1 n <-2e2 # number of realizations p <-1.2*n # number of assets b <-rep(1/p,p) x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) test <- new_MV_portfolio_weights_BDOPS21_pgn(x=x, gamma=gamma, b=b, beta=0.05) summary(test) # Assets with a non-diagonal covariance matrix
# c<1 # Assets with a diagonal covariance matrix n <- 3e2 # number of realizations p <- .5*n # number of assets b <- rep(1/p,p) gamma <- 1 x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) test <- new_MV_portfolio_weights_BDOPS21(x=x, gamma=gamma, b=b, beta=0.05) summary(test) # Assets with a non-diagonal covariance matrix Mtrx <- RandCovMtrx(p=p) x <- t(MASS::mvrnorm(n=n , mu=rep(0,p), Sigma=Mtrx)) test <- new_MV_portfolio_weights_BDOPS21(x=x, gamma=gamma, b=b, beta=0.05) str(test) # c>1 n <-2e2 # number of realizations p <-1.2*n # number of assets b <-rep(1/p,p) x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) test <- new_MV_portfolio_weights_BDOPS21_pgn(x=x, gamma=gamma, b=b, beta=0.05) summary(test) # Assets with a non-diagonal covariance matrix
The nonlinear shrinkage estimator of the covariance matrix, that minimizes the minimum variance loss functions as defined in Eq (2.1) of Ledoit and Wolf (2020).
nonlin_shrinkLW(x)
nonlin_shrinkLW(x)
x |
a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations. |
an object of class matrix
Ledoit O, Wolf M (2020). “Analytical nonlinear shrinkage of large-dimensional covariance matrices.” Annals of Statistics, 48(5), 3043–3065.
n<-3e2 c<-0.7 p<-c*n mu <- rep(0, p) Sigma <- RandCovMtrx(p=p) X <- t(MASS::mvrnorm(n=n, mu=mu, Sigma=Sigma)) Sigma_shr <- nonlin_shrinkLW(X)
n<-3e2 c<-0.7 p<-c*n mu <- rep(0, p) Sigma <- RandCovMtrx(p=p) X <- t(MASS::mvrnorm(n=n, mu=mu, Sigma=Sigma)) Sigma_shr <- nonlin_shrinkLW(X)
The plotted Bayesian efficient frontier is provided by
Eq. (8) in Bauder et al. (2021).
It is the set of optimal portfolios obtained
by employing the posterior predictive distribution on the asset returns.
This efficient frontier can be used to assess the mean-variance efficiency
of various estimators of the portfolio weights. The standard deviation of
the portfolio return is plotted in the -axis and the mean portfolio
return in the
-axis. The portfolios with the weights
are added to the plot by computing
and
.
plot_frontier(x, weights.eff = rep(1/nrow(x), length = nrow(x)))
plot_frontier(x, weights.eff = rep(1/nrow(x), length = nrow(x)))
x |
a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations. |
weights.eff |
matrix of portfolio weights. Each column contains p values of the weights for a given portfolio. Default: equally weighted portfolio. |
a ggplot object
Bauder D, Bodnar T, Parolya N, Schmid W (2021). “Bayesian mean–variance analysis: optimal portfolio selection under parameter uncertainty.” Quantitative Finance, 21(2), 221–242.
p <- 150 n <- 300 gamma <- 10 mu <- seq(0.2,-0.2, length.out=p) Sigma <- RandCovMtrx(p=p) x <- t(MASS::mvrnorm(n=n , mu=mu, Sigma=Sigma)) EW_port <- rep(1/p, length=p) MV_shr_port <- new_MV_portfolio_weights_BDOPS21(x=x, gamma=gamma, b=EW_port, beta=0.05)$weights GMV_shr_port <- new_MV_portfolio_weights_BDOPS21(x=x, gamma=Inf, b=EW_port, beta=0.05)$weights MV_trad_port <- new_MV_portfolio_traditional(x=x, gamma=gamma)$weights GMV_trad_port <- new_MV_portfolio_traditional(x=x, gamma=Inf)$weights weights.eff <- cbind(EW_port, MV_shr_port, GMV_shr_port, MV_trad_port, GMV_trad_port) colnames(weights.eff) <- c("EW", "MV_shr", "GMV_shr", "MV_trad", "GMV_trad") Fplot <- plot_frontier(x, weights.eff) Fplot
p <- 150 n <- 300 gamma <- 10 mu <- seq(0.2,-0.2, length.out=p) Sigma <- RandCovMtrx(p=p) x <- t(MASS::mvrnorm(n=n , mu=mu, Sigma=Sigma)) EW_port <- rep(1/p, length=p) MV_shr_port <- new_MV_portfolio_weights_BDOPS21(x=x, gamma=gamma, b=EW_port, beta=0.05)$weights GMV_shr_port <- new_MV_portfolio_weights_BDOPS21(x=x, gamma=Inf, b=EW_port, beta=0.05)$weights MV_trad_port <- new_MV_portfolio_traditional(x=x, gamma=gamma)$weights GMV_trad_port <- new_MV_portfolio_traditional(x=x, gamma=Inf)$weights weights.eff <- cbind(EW_port, MV_shr_port, GMV_shr_port, MV_trad_port, GMV_trad_port) colnames(weights.eff) <- c("EW", "MV_shr", "GMV_shr", "MV_trad", "GMV_trad") Fplot <- plot_frontier(x, weights.eff) Fplot
Generates a covariance matrix from Wishart distribution with given eigenvalues or with exponentially decreasing eigenvalues. Useful for examples and tests when an arbitrary covariance matrix is needed.
RandCovMtrx(p = 200, eigenvalues = 0.1 * exp(5 * seq_len(p)/p))
RandCovMtrx(p = 200, eigenvalues = 0.1 * exp(5 * seq_len(p)/p))
p |
dimension of the covariance matrix |
eigenvalues |
the vector of positive eigenvalues |
This function generates a symmetric positive definite covariance matrix with given eigenvalues. The eigenvalues can be specified explicitly. Or, by default, they are generated with exponential decay.
covariance matrix
p<-1e1 # A non-diagonal covariance matrix Mtrx <- RandCovMtrx(p=p) Mtrx
p<-1e1 # A non-diagonal covariance matrix Mtrx <- RandCovMtrx(p=p) Mtrx
It computes the sample covariance of matrix as follows:
where is the
-th column of the data matrix
.
Sigma_sample_estimator(x)
Sigma_sample_estimator(x)
x |
a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations. |
Sample covariance estimation
p<-5 # number of assets n<-1e1 # number of realizations x <-matrix(data = rnorm(n*p), nrow = p, ncol = n) Sigma_sample_estimator(x)
p<-5 # number of assets n<-1e1 # number of realizations x <-matrix(data = rnorm(n*p), nrow = p, ncol = n) Sigma_sample_estimator(x)
Daily log-returns of selected constituents of S&P500 in percents. The data are sampled in business time, i.e., weekends and holidays are omitted.
SP_daily_asset_returns
SP_daily_asset_returns
a matrix with the first column containing the data and company names as column labels.
Yahoo finance
A high-dimensional asymptotic test on the mean-variance efficiency of a given
portfolio with the weights . The tested hypotheses are
The test statistic is based on the shrinkage estimator of mean-variance portfolio weights (see Eq.(44) of Bodnar et al. 2021).
test_MVSP(gamma, x, w_0, beta = 0.05)
test_MVSP(gamma, x, w_0, beta = 0.05)
gamma |
a numeric variable. Coefficient of risk aversion. |
x |
a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations. |
w_0 |
a numeric vector of tested weights. |
beta |
a significance level for the test. |
Note: when gamma == Inf, we get the test for the weights of the global minimum variance portfolio as in Theorem 2 of Bodnar et al. (2019).
Element | Description |
alpha_hat | the estimated shrinkage intensity |
alpha_sd | the standard deviation of the shrinkage intensity |
alpha_lower | the lower bound for the shrinkage intensity |
alpha_upper | the upper bound for the shrinkage intensity |
T_alpha | the value of the test statistic |
p_value | the p-value for the test |
Bodnar T, Dmytriv S, Okhrin Y, Parolya N, Schmid W (2021).
“Statistical Inference for the Expected Utility Portfolio in High Dimensions.”
IEEE Transactions on Signal Processing, 69, 1-14.
Bodnar T, Dmytriv S, Parolya N, Schmid W (2019).
“Tests for the weights of the global minimum variance portfolio in a high-dimensional setting.”
IEEE Transactions on Signal Processing, 67(17), 4479–4493.
n<-3e2 # number of realizations p<-.5*n # number of assets b<-rep(1/p,p) gamma<-1 x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) T_alpha <- test_MVSP(gamma=gamma, x=x, w_0=b, beta=0.05) T_alpha
n<-3e2 # number of realizations p<-.5*n # number of assets b<-rep(1/p,p) gamma<-1 x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) T_alpha <- test_MVSP(gamma=gamma, x=x, w_0=b, beta=0.05) T_alpha
A validator for objects of class MeanVar_portfolio
validate_MeanVar_portfolio(w)
validate_MeanVar_portfolio(w)
w |
Object of class MeanVar_portfolio. |
If the object passes all the checks, then w itself is returned, otherwise an error is thrown.
n<-3e2 # number of realizations p<-.5*n # number of assets gamma<-1 x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) # Simple MV portfolio cov_mtrx <- Sigma_sample_estimator(x) means <- rowMeans(x) cust_port_simp <- new_MeanVar_portfolio(mean_vec=means, cov_mtrx=cov_mtrx, gamma=2) str(validate_MeanVar_portfolio(cust_port_simp))
n<-3e2 # number of realizations p<-.5*n # number of assets gamma<-1 x <- matrix(data = rnorm(n*p), nrow = p, ncol = n) # Simple MV portfolio cov_mtrx <- Sigma_sample_estimator(x) means <- rowMeans(x) cust_port_simp <- new_MeanVar_portfolio(mean_vec=means, cov_mtrx=cov_mtrx, gamma=2) str(validate_MeanVar_portfolio(cust_port_simp))