dirac_ss_sdf_pvalue {BayesianFactorZoo} | R Documentation |
Hypothesis testing for risk prices (Bayesian p-values) with Dirac spike-and-slab prior
Description
This function tests the null hypothesis, , when
.
When
, we compare factor models using the algorithm in Proposition 1 of Bryzgalova et al. (2023).
When
, this function corresponds to Corollary 2 in Section II.A.2 of Bryzgalova et al. (2023).
The function can also be used to compute the posterior probabilities of all possible models with up to a
given maximum number of factors (see examples).
Usage
dirac_ss_sdf_pvalue(f, R, sim_length, lambda0, psi0 = 1, max_k = NULL)
Arguments
f |
A matrix of factors with dimension |
R |
A matrix of test assets with dimension |
sim_length |
The length of Monte-Carlo simulations; |
lambda0 |
A |
psi0 |
The hyper-parameter in the prior distribution of risk price |
max_k |
The maximal number of factors in models ( |
Details
Let denote a diagonal matrix with elements
, and
the submatrix of
corresponding to model
, where
is a small positive number corresponding to the common cross-sectional intercept
(
). The prior for the prices of risk (
) of model
is then
We choose
, where
is the cross-sectionally
demeaned vector of factor
's correlations with asset returns. In the codes,
is equal to the value of
psi0
.
Value
The return of dirac_ss_sdf_pvalue
is a list of the following elements:
-
gamma_path
: Asim_length
matrix of the posterior draws of
. Each row represents a draw. If
in one draw, factor
is included in the model in this draw and vice verse.
-
lambda_path
: Asim_length
matrix of the risk prices
. Each row represents a draw. Note that the first column is
corresponding to the constant term. The next
columns (i.e., the 2-th –
-th columns) are the risk prices of the
factors;
-
model_probs
: Amatrix of posterior model probabilities, where the first k columns are the model indices and the final column is a vector of model probabilities.
References
Bryzgalova S, Huang J, Julliard C (2023). “Bayesian solutions for the factor zoo: We just ran two quadrillion models <https://doi.org/10.1111/jofi.13197>.” Journal of Finance, 78(1), 487–557.
Examples
## <-------------------------------------------------------------------------------->
## Example: Bayesian p-value (with the dirac spike-and-slab prior)
## <-------------------------------------------------------------------------------->
# Load the example data
data("BFactor_zoo_example")
HML <- BFactor_zoo_example$HML
lambda_ols <- BFactor_zoo_example$lambda_ols
R2.ols.true <- BFactor_zoo_example$R2.ols.true
sim_f <- BFactor_zoo_example$sim_f
sim_R <- BFactor_zoo_example$sim_R
uf <- BFactor_zoo_example$uf
### Now we estimate the Bayesian p-values defined in Corollary 2.
#
### Prior Sharpe ratio of factor model for different values of psi: see equation (27):
#
cat("--------------- Choose psi based on prior Sharpe ratio ----------------\n")
cat("if psi = 1, prior Sharpe ratio is", psi_to_priorSR(sim_R, sim_f, psi0=1), "\n")
cat("if psi = 2, prior Sharpe ratio is", psi_to_priorSR(sim_R, sim_f, psi0=2), "\n")
cat("if psi = 5, prior Sharpe ratio is", psi_to_priorSR(sim_R, sim_f, psi0=5), "\n")
## Test whether factors' risk prices equal 'matrix(lambda_ols[2]*sd(HML),ncol=1)'
## Bayesian p-value is given by mean(shrinkage$gamma_path)
shrinkage <- dirac_ss_sdf_pvalue(sim_f, sim_R, 1000, matrix(lambda_ols[2]*sd(HML),ncol=1))
cat("Null hypothesis: lambda =", matrix(lambda_ols[2]*sd(HML)), "\n")
cat("Posterior probability of rejecting the above null hypothesis is:",
mean(shrinkage$gamma_path), "\n")
## Test whether the risk price of factor 'sim_f' is equal to 0
shrinkage <- dirac_ss_sdf_pvalue(sim_f, sim_R, 1000, 0, psi0=1)
cat("Null hypothesis: lambda =", 0, "\n")
cat("Posterior probability of rejecting the above null hypothesis is:",
mean(shrinkage$gamma_path), "\n")
## One can also put more than one factor into the test
two_f = cbind(sim_f,uf) # sim_f is the strong factor while uf is the useless factor
# Test1: lambda of sim_f = 0, Test2: lambda of uf = 0
lambda0_null_vec = t(cbind(0,0)) # 2x1 vector
shrinkage <- dirac_ss_sdf_pvalue(two_f, sim_R, 1000, lambda0_null_vec, psi0=1)
cat("Null hypothesis: lambda =", 0, "for each factor", "\n")
cat("Posterior probabilities of rejecting the above null hypothesis are:",
colMeans(shrinkage$gamma_path), "\n")
## We can also print the posterior model probabilities:
cat('Posterior model probabilities are:\n')
print(shrinkage$model_probs)
## One can compute the posterior probabilities of all possible models with up to
## a given maximum number of factors. For example, we consider two factors, but
## the number of factors is restricted to be less than two.
lambda0_null_vec = t(cbind(0,0)) # 2x1 vector
shrinkage <- dirac_ss_sdf_pvalue(two_f, sim_R, 1000, lambda0_null_vec, psi0=1, max_k=1)
cat('Posterior model probabilities are:\n')
print(shrinkage$model_probs)
## Comment: You may notice that the model with index (1, 1) has a posterior probability
## of exactly zero since the maximal number of factors is one.