Learn R Programming

BayesianFactorZoo (version 0.0.0.3)

continuous_ss_sdf_v2: SDF model selection with continuous spike-and-slab prior (tradable factors are treated as test assets)

Description

This function provides the SDF model selection procedure using the continuous spike-and-slab prior. See Propositions 3 and 4 in bryzgalova2023bayesian;textualBayesianFactorZoo. Unlike continuous_ss_sdf, tradable factors are treated as test assets in this function.

Usage

continuous_ss_sdf_v2(
  f1,
  f2,
  R,
  sim_length,
  psi0 = 1,
  r = 0.001,
  aw = 1,
  bw = 1,
  type = "OLS",
  intercept = TRUE
)

Value

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\) if intercept = TRUE. 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. If intercept = FALSE, lambda_path is a sim_length\(\times k\) matrix of the risk prices, without the estimates of \(\lambda_c\).

  • sdf_path: A sim_length\(\times t\) matrix of posterior draws of SDFs. Each row represents a draw.

  • bma_sdf: BMA-SDF.

Arguments

f1

A matrix of nontradable factors with dimension \(t \times k_1\), where \(k_1\) is the number of nontradable factors and \(t\) is the number of periods.

f2

A matrix of tradable factors with dimension \(t \times k_2\), where \(k_2\) is the number of tradable factors and \(t\) is the number of periods.

R

A matrix of test assets with dimension \(t \times N\), where \(t\) is the number of periods and \(N\) is the number of test assets (R should NOT contain tradable factors f2);

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 \(\gamma\) (see Details);

bw

The hyper-parameter related to the prior of \(\gamma\) (see Details);

type

If type = 'OLS' (type = 'GLS'), the function returns Bayesian OLS (GLS) estimates of risk prices. The default is 'OLS'.

intercept

If intercept = TRUE (intercept = FALSE), we include (exclude) the common intercept in the cross-sectional regression. The default is intercept = TRUE.

Details

See the description in the twin function continuous_ss_sdf.

References

bryzgalova2023bayesianBayesianFactorZoo

Examples

Run this code

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



Run the code above in your browser using DataLab