portVaRDecomp: Decompose portfolio VaR into individual factor contributions

View source: R/portVaRDecomp.R

portVaRDecompR Documentation

Decompose portfolio VaR into individual factor contributions

Description

Compute the factor contributions to Value-at-Risk (VaR) of portfolio returns based on Euler's theorem, given the fitted factor model. The partial derivative of VaR w.r.t. factor beta is computed as the expected factor return given portfolio return is equal to its VaR and approximated by a kernel estimator. Option to choose between non-parametric and Normal.

Usage

portVaRDecomp(object, ...)

## S3 method for class 'tsfm'
portVaRDecomp(
  object,
  weights = NULL,
  factor.cov,
  p = 0.05,
  type = c("np", "normal"),
  invert = FALSE,
  use = "pairwise.complete.obs",
  ...
)

## S3 method for class 'ffm'
portVaRDecomp(
  object,
  weights = NULL,
  factor.cov,
  p = 0.05,
  type = c("np", "normal"),
  invert = FALSE,
  ...
)

Arguments

object

fit object of class tsfm, or ffm.

...

other optional arguments passed to quantile and optional arguments passed to cov

weights

a vector of weights of the assets in the portfolio. Default is NULL, in which case an equal weights will be used.

factor.cov

optional user specified factor covariance matrix with named columns; defaults to the sample covariance matrix.

p

tail probability for calculation. Default is 0.05.

type

one of "np" (non-parametric) or "normal" for calculating VaR. Default is "np".

invert

a logical variable to choose if change VaR to positive number, default is False

use

an optional character string giving a method for computing factor covariances in the presence of missing values. This must be (an abbreviation of) one of the strings "everything", "all.obs", "complete.obs", "na.or.complete", or "pairwise.complete.obs". Default is "pairwise.complete.obs".

Details

The factor model for a portfolio's return at time t has the form

R(t) = beta'f(t) + e(t) = beta.star'f.star(t)

where, beta.star=(beta,sig.e) and f.star(t)=[f(t)',z(t)]'. By Euler's theorem, the VaR of the asset's return is given by:

VaR.fm = sum(cVaR_k) = sum(beta.star_k*mVaR_k)

where, summation is across the K factors and the residual, cVaR and mVaR are the component and marginal contributions to VaR respectively. The marginal contribution to VaR is defined as the expectation of F.star, conditional on the loss being equal to portVaR. This is approximated as described in Epperlein & Smillie (2006); a triangular smoothing kernel is used here.

Value

A list containing

portVaR

factor model VaR of portfolio return.

n.exceed

number of observations beyond VaR.

idx.exceed

a numeric vector of index values of exceedances.

mVaR

length-(K + 1) vector of marginal contributions to VaR.

cVaR

length-(K + 1) vector of component contributions to VaR.

pcVaR

length-(K + 1) vector of percentage component contributions to VaR.

Where, K is the number of factors.

Author(s)

Douglas Martin, Lingjie Yi

See Also

fitTsfm, fitFfm for the different factor model fitting functions.

portSdDecomp for factor model Sd decomposition. portEsDecomp for factor model ES decomposition.

Examples

# Time Series Factor Model

 # load data
data(managers, package = 'PerformanceAnalytics')
colnames(managers)
 # Make syntactically valid column names
colnames(managers) <- make.names( colnames(managers))
colnames(managers)

fit.macro <- FactorAnalytics::fitTsfm(asset.names=colnames(managers[,(1:6)]),
                     factor.names=colnames(managers[,(7:9)]),
                     rf.name=colnames(managers[,10]), 
                     data=managers)
                     
decomp <- portVaRDecomp(fit.macro,invert = TRUE)

# get the factor contributions of risk
decomp$cVaR

# random weights 
wts = runif(6)
wts = wts/sum(wts)
names(wts) <- colnames(managers)[1:6]
portVaRDecomp(fit.macro, wts)


# Fundamental Factor Model
data("stocks145scores6")
dat = stocks145scores6
dat$DATE = zoo::as.yearmon(dat$DATE)
dat = dat[dat$DATE >=zoo::as.yearmon("2008-01-01") & dat$DATE <= zoo::as.yearmon("2012-12-31"),]

# Load long-only GMV weights for the return data
data("wtsStocks145GmvLo")
wtsStocks145GmvLo = round(wtsStocks145GmvLo,5)  
                                                      
# fit a fundamental factor model
fit.cross <- fitFfm(data = dat, 
              exposure.vars = c("SECTOR","ROE","BP","PM12M1M","SIZE","ANNVOL1M",
              "EP"),date.var = "DATE", ret.var = "RETURN", asset.var = "TICKER", 
              fit.method="WLS", z.score = "crossSection")
              
decomp = portVaRDecomp(fit.cross) 
# get the factor contributions of risk 
decomp$cVaR
portVaRDecomp(fit.cross, weights = wtsStocks145GmvLo)               
 

braverock/factorAnalytics documentation built on Dec. 16, 2024, 1:05 p.m.