Package 'HDShOP'

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

Help Index


S3 class MeanVar_portfolio

Description

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:

Slots

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

See Also

summary.MeanVar_portfolio summary method for the class, new_MeanVar_portfolio class constructor, validate_MeanVar_portfolio class validator, MeanVar_portfolio class helper.


Covariance matrix estimator

Description

It is a function dispatcher for covariance matrix estimation. One can choose between traditional and shrinkage-based estimators.

Usage

CovarEstim(x, type = c("trad", "BGP14", "LW20"), ...)

Arguments

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

Details

The available estimation methods are:

Function Paper Type
Sigma_sample_estimator traditional
CovShrinkBGP14 Bodnar et al 2014 BGP14
nonlin_shrinkLW Ledoit & Wolf 2020 LW20

Value

an object of class matrix

Examples

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")

Linear shrinkage estimator of the covariance matrix (Bodnar et al. 2014)

Description

The optimal linear shrinkage estimator of the covariance matrix that minimizes the Frobenius norm:

Σ^OLSE=α^S+β^Σ0,\hat{\Sigma}_{OLSE} = \hat{\alpha} S + \hat{\beta} \Sigma_0,

where α^\hat{\alpha} and β^\hat{\beta} are optimal shrinkage intensities given in Eq. (4.3) and (4.4) of Bodnar et al. (2014). SS is the sample covariance matrix (SCM, see Sigma_sample_estimator) and Σ0\Sigma_0 is a positive definite symmetric matrix used as the target matrix (TM), for example, 1pI\frac{1}{p} I.

Usage

CovShrinkBGP14(n, TM, SCM)

Arguments

n

sample size.

TM

the target matrix for the shrinkage estimator.

SCM

sample covariance matrix.

Value

a list containing an object of class matrix (S) and the estimated shrinkage intensities α^\hat{\alpha} and β^\hat{\beta}.

References

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.

Examples

# 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]

Linear shrinkage estimator of the inverse covariance matrix (Bodnar et al. 2016)

Description

The optimal linear shrinkage estimator of the inverse covariance (precision) matrix that minimizes the Frobenius norm is given by:

Π^OLSE=α^Π^+β^Π0,\hat{\Pi}_{OLSE} = \hat{\alpha} \hat{\Pi} + \hat{\beta} \Pi_0,

where α^\hat{\alpha} and β^\hat{\beta} are optimal shrinkage intensities given in Eq. (4.4) and (4.5) of Bodnar et al. (2016). Π^\hat{\Pi} is the inverse of the sample covariance matrix (iSCM) and Π0\Pi_0 is a positive definite symmetric matrix used as the target matrix (TM), for example, I.

Usage

InvCovShrinkBGP16(n, p, TM, iSCM)

Arguments

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

Value

a list containing an object of class matrix (S) and the estimated shrinkage intensities α^\hat{\alpha} and β^\hat{\beta}.

References

Bodnar T, Gupta AK, Parolya N (2016). “Direct shrinkage estimation of large dimensional precision matrix.” Journal of Multivariate Analysis, 146, 223–236.

Examples

# 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]

BOP shrinkage estimator

Description

Shrinkage estimator of the high-dimensional mean vector as suggested in Bodnar et al. (2019). It uses the formula

μ^BOP=α^xˉ+β^μ0,\hat \mu_{BOP} = \hat \alpha \bar x + \hat \beta \mu_0,

where α^\hat \alpha and β^\hat \beta 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 μ0\mu_0 (shrinkage target). xˉ\bar x stands for the sample mean vector.

Usage

mean_bop19(x, mu_0 = rep(1, p))

Arguments

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.

Value

a numeric vector containing the shrinkage estimator of the mean vector

References

Bodnar T, Okhrin O, Parolya N (2019). “Optimal shrinkage estimator for high-dimensional mean vector.” Journal of Multivariate Analysis, 170, 63–79.

Examples

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

Description

Bayes-Stein shrinkage estimator of the mean vector as suggested in Jorion (1986). The estimator is given by

μ^BS=(1β)xˉ+βY01,\hat \mu_{BS} = (1-\beta) \bar x + \beta Y_0 1,

where xˉ\bar x is the sample mean vector, β\beta and Y0Y_0 are derived using Bayesian approach (see Eq.(14) and Eq.(17) in Jorion (1986)).

Usage

mean_bs(x)

Arguments

x

a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations.

Value

a numeric vector containing the Bayes-Stein shrinkage estimator of the mean vector

References

Jorion P (1986). “Bayes-Stein estimation for portfolio analysis.” Journal of Financial and Quantitative Analysis, 279–292.

Examples

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

Description

James-Stein shrinkage estimator of the mean vector as suggested in Jorion (1986). The estimator is given by

μ^JS=(1β)xˉ+βY01,\hat \mu_{JS} = (1-\beta) \bar x + \beta Y_0 1,

where xˉ\bar x is the sample mean vector, β\beta is the shrinkage coefficient which minimizes a quadratic loss given by Eq.(11) in Jorion (1986). Y0Y_0 is a prespecified value.

Usage

mean_js(x, Y_0 = 1)

Arguments

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.

Value

a numeric vector containing the James-Stein shrinkage estimator of the mean vector.

References

Jorion P (1986). “Bayes-Stein estimation for portfolio analysis.” Journal of Financial and Quantitative Analysis, 279–292.

Examples

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)

Mean vector estimator

Description

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.

Usage

MeanEstim(x, type, ...)

Arguments

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

Details

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

Value

a numeric vector— a value of the specified estimator of the mean vector.

References

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.

Examples

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 helper function for MeanVar_portfolio

Description

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

w^MV=Σ^111Σ^11+γ1Q^μ^,\hat w_{MV} = \frac{\hat{\Sigma}^{-1} 1}{1' \hat{\Sigma}^{-1} 1} + \gamma^{-1} \hat Q \hat{\mu},

where Σ^\hat{\Sigma} is an estimator for the covariance matrix, μ^\hat{\mu} is an estimator for the mean vector, γ\gamma is the coefficient of risk aversion, and Q^\hat Q is given by

Q^=Σ^1Σ^111Σ^11Σ^11.\hat Q = \hat{\Sigma}^{-1} - \frac{\hat{\Sigma}^{-1} 1 1' \hat{\Sigma}^{-1}}{1' \hat{\Sigma}^{-1} 1} .

The computation is made by new_MeanVar_portfolio and the result is validated by validate_MeanVar_portfolio.

Usage

MeanVar_portfolio(mean_vec, cov_mtrx, gamma)

Arguments

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.

Value

Mean-variance portfolio in the form of object of S3 class MeanVar_portfolio.

Examples

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)

Shrinkage mean-variance portfolio

Description

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.

Usage

MVShrinkPortfolio(x, gamma, type = c("shrinkage", "traditional"), ...)

Arguments

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

Details

The sample estimator of the mean-variance portfolio weights, which results in a traditional mean-variance portfolio, is calculated by

w^MV=S111S11+γ1Q^xˉ,\hat w_{MV} = \frac{S^{-1} 1}{1' S^{-1} 1} + \gamma^{-1} \hat Q \bar x,

where S1S^{-1} and xˉ\bar x are the inverse of the sample covariance matrix and the sample mean vector of asset returns respectively, γ\gamma is the coefficient of risk aversion and Q^\hat Q is given by

Q^=S1S111S11S11.\hat Q = S^{-1} - \frac{S^{-1} 1 1' S^{-1}}{1' S^{-1} 1} .

In the case when p>np>n, S1S^{-1} becomes S+S^{+}- Moore-Penrose inverse. The shrinkage estimator for the mean-variance portfolio weights in a high-dimensional setting is given by

w^ShMV=α^w^MV+(1α^)b,\hat w_{ShMV} = \hat \alpha \hat w_{MV} + (1- \hat \alpha)b,

where α^\hat \alpha is the estimated shrinkage intensity and bb is a target vector with the sum of the elements equal to one.

In the case γ\gamma \neq \infty, α^\hat{\alpha} 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 (γ=\gamma=\infty) leads to the traditional global minimum variance (GMV) portfolio with the weights given by

w^GMV=S111S11.\hat w_{GMV} = \frac{S^{-1} 1}{1' S^{-1} 1} .

The shrinkage estimator for the GMV portfolio is then calculated by

w^ShGMV=α^w^GMV+(1α^)b,\hat w_{ShGMV} = \hat\alpha \hat w_{GMV} + (1-\hat \alpha)b,

with α^\hat{\alpha} 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

Value

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.

References

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.

Examples

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 GMV portfolio object.

Description

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.

Usage

new_GMV_portfolio_weights_BDPS19(x, b, beta)

new_GMV_portfolio_weights_BDPS19_pgn(x, b, beta)

Arguments

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.

Value

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.

References

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.

Examples

# 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 constructor for class MeanVar_portfolio

Description

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.

Usage

new_MeanVar_portfolio(mean_vec, cov_mtrx, gamma)

Arguments

mean_vec

mean vector of asset returns

cov_mtrx

the covariance matrix of asset returns

gamma

a numeric variable. Coefficient of risk aversion.

Value

Mean-variance portfolio in the form of object of S3 class MeanVar_portfolio.

Examples

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)

Traditional mean-variance portfolio

Description

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.

Usage

new_MV_portfolio_traditional(x, gamma)

new_MV_portfolio_traditional_pgn(x, gamma)

Arguments

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.

Value

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

Examples

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 MV portfolio object

Description

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.

Usage

new_MV_portfolio_weights_BDOPS21(x, gamma, b, beta)

new_MV_portfolio_weights_BDOPS21_pgn(x, gamma, b, beta)

Arguments

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.

Value

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.

References

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.

Examples

# 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

nonlinear shrinkage estimator of the covariance matrix of Ledoit and Wolf (2020)

Description

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).

Usage

nonlin_shrinkLW(x)

Arguments

x

a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations.

Value

an object of class matrix

References

Ledoit O, Wolf M (2020). “Analytical nonlinear shrinkage of large-dimensional covariance matrices.” Annals of Statistics, 48(5), 3043–3065.

Examples

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)

Plot the Bayesian efficient frontier (Bauder et al. 2021) and the provided portfolios.

Description

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 xx-axis and the mean portfolio return in the yy-axis. The portfolios with the weights w\rm{w} are added to the plot by computing wSw\sqrt{\rm{w}^\prime S w} and wxˉ\rm w^\prime \bar x.

Usage

plot_frontier(x, weights.eff = rep(1/nrow(x), length = nrow(x)))

Arguments

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.

Value

a ggplot object

References

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.

Examples

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

Covariance matrix generator

Description

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.

Usage

RandCovMtrx(p = 200, eigenvalues = 0.1 * exp(5 * seq_len(p)/p))

Arguments

p

dimension of the covariance matrix

eigenvalues

the vector of positive eigenvalues

Details

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.

Value

covariance matrix

Examples

p<-1e1
# A non-diagonal covariance matrix
Mtrx <- RandCovMtrx(p=p)
Mtrx

Sample covariance matrix

Description

It computes the sample covariance of matrix SS as follows:

S=1n1j=1n(xjxˉ)(xjxˉ),xˉ=1nj=1nxj,S = \frac{1}{n-1} \sum_{j=1}^n (x_j - \bar x)(x_j - \bar x)' ,\quad \bar x = \frac{1}{n} \sum_{j=1}^n x_j ,

where xjx_j is the jj-th column of the data matrix xx.

Usage

Sigma_sample_estimator(x)

Arguments

x

a p by n matrix or a data frame of asset returns. Rows represent different assets, columns – observations.

Value

Sample covariance estimation

Examples

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 S&P500.

Description

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.

Usage

SP_daily_asset_returns

Format

a matrix with the first column containing the data and company names as column labels.

Source

Yahoo finance


Test for mean-variance portfolio weights

Description

A high-dimensional asymptotic test on the mean-variance efficiency of a given portfolio with the weights w0\rm{w}_0. The tested hypotheses are

H0:wMV=w0vsH1:wMVw0.H_0: w_{MV} = w_0 \quad vs \quad H_1: w_{MV} \neq w_0.

The test statistic is based on the shrinkage estimator of mean-variance portfolio weights (see Eq.(44) of Bodnar et al. 2021).

Usage

test_MVSP(gamma, x, w_0, beta = 0.05)

Arguments

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.

Details

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).

Value

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

References

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.

Examples

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

Description

A validator for objects of class MeanVar_portfolio

Usage

validate_MeanVar_portfolio(w)

Arguments

w

Object of class MeanVar_portfolio.

Value

If the object passes all the checks, then w itself is returned, otherwise an error is thrown.

Examples

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))