continuous_ss_sdf_v2 {BayesianFactorZoo} | R Documentation |
This function provides the SDF model selection procedure using the continuous spike-and-slab prior.
See Propositions 3 and 4 in Bryzgalova et al. (2023).
Unlike continuous_ss_sdf
, tradable factors are treated as test assets in this function.
continuous_ss_sdf_v2(
f1,
f2,
R,
sim_length,
psi0 = 1,
r = 0.001,
aw = 1,
bw = 1,
type = "OLS"
)
f1 |
A matrix of nontradable factors with dimension |
f2 |
A matrix of tradable factors with dimension |
R |
A matrix of test assets with dimension |
sim_length |
The length of monte-carlo simulations; |
psi0 |
The hyper-parameter in the prior distribution of risk prices (see Details); |
r |
The hyper-parameter related to the prior of risk prices (see Details); |
aw |
The hyper-parameter related to the prior of |
bw |
The hyper-parameter related to the prior of |
type |
If |
See the description in the twin function continuous_ss_sdf
.
The return of continuous_ss_sdf_v2
is a list of the following elements:
gamma_path
: A sim_length
\times k
matrix of the posterior draws of \gamma
(k = k_1 + k_2
). Each row represents
a draw. If \gamma_j = 1
in one draw, factor j
is included in the model in this draw and vice verse.
lambda_path
: A sim_length
\times (k+1)
matrix of the risk prices \lambda
. Each row represents
a draw. Note that the first column is \lambda_c
corresponding to the constant term. The next k
columns (i.e., the 2-th – (k+1)
-th columns) are the risk prices of the k
factors.
sdf_path
: A sim_length
\times t
matrix of posterior draws of SDFs. Each row represents a draw.
bma_sdf
: BMA-SDF.
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.
library(timeSeries)
## 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
## sim_f: simulated strong factor
## uf: simulated useless factor
psi_hat <- psi_to_priorSR(sim_R, cbind(sim_f,uf,sim_R[,1]), priorSR=0.1)
## We include the first test asset, sim_R[,1], into factors, so f2 = sim_R[,1,drop=FALSE].
## Also remember excluding sim_R[,1,drop=FALSE] from test assets, so R = sim_R[,-1].
shrinkage <- continuous_ss_sdf_v2(cbind(sim_f,uf), sim_R[,1,drop=FALSE], sim_R[,-1], 1000,
psi0=psi_hat, r=0.001, aw=1, bw=1)
cat("Null hypothesis: lambda =", 0, "for each of these three factors", "\n")
cat("Posterior probabilities of rejecting the above null hypotheses are:",
colMeans(shrinkage$gamma_path), "\n")
## We also have the posterior draws of SDF: m(t) = 1 - lambda_g %*% (f(t) - mu_f)
sdf_path <- shrinkage$sdf_path
## We also provide the Bayesian model averaging of the SDF (BMA-SDF)
bma_sdf <- shrinkage$bma_sdf
## We can further estimate the posterior distributions of model-implied Sharpe ratios:
cat("The 5th, 50th, and 95th quantiles of model-implied Sharpe ratios:",
quantile(colSds(t(sdf_path)), probs=c(0.05, 0.5, 0.95)), "\n")
## Finally, we can estimate the posterior distribution of model dimensions:
cat("The posterior distribution of model dimensions (= 0, 1, 2, 3):",
prop.table(table(rowSums(shrinkage$gamma_path))), "\n")
## We now use the 17th test asset, sim_R[,17,drop=FALSE], as the tradable factor,
## so f2 = sim_R[,17,drop=FALSE].
## Also remember excluding sim_R[,17,drop=FALSE] from test assets, so R = sim_R[,-17].
psi_hat <- psi_to_priorSR(sim_R, cbind(sim_f,uf,sim_R[,17]), priorSR=0.1)
shrinkage <- continuous_ss_sdf_v2(cbind(sim_f,uf), sim_R[,17,drop=FALSE], sim_R[,-17],
1000, psi0=psi_hat, r=0.001, aw=1, bw=1)
cat("Null hypothesis: lambda =", 0, "for each of these three factors", "\n")
cat("Posterior probabilities of rejecting the above null hypotheses are:",
colMeans(shrinkage$gamma_path), "\n")