repRisk: Decompose portfolio risk into individual factor contributions...

View source: R/repRisk.R

repRiskR Documentation

Decompose portfolio risk into individual factor contributions and provide tabular report

Description

Compute the factor contributions to standard deviation (SD), Value-at-Risk (VaR), Expected Tail Loss or Expected Shortfall (ES) of the return of individual asset within a portfolio return of a portfolio based on Euler's theorem, given the fitted factor model.

Usage

repRisk(object, ...)

## S3 method for class 'tsfm'
repRisk(
  object,
  weights = NULL,
  risk = c("Sd", "VaR", "ES"),
  decomp = c("FPCR", "FCR", "FMCR"),
  digits = NULL,
  invert = FALSE,
  nrowPrint = 20,
  p = 0.05,
  type = c("np", "normal"),
  use = "pairwise.complete.obs",
  sliceby = c("factor", "asset"),
  isPrint = TRUE,
  isPlot = FALSE,
  layout = NULL,
  stripText.cex = 1,
  axis.cex = 1,
  portfolio.only = FALSE,
  ...
)

## S3 method for class 'ffm'
repRisk(
  object,
  weights = NULL,
  risk = c("Sd", "VaR", "ES"),
  decomp = c("FMCR", "FCR", "FPCR"),
  digits = NULL,
  invert = FALSE,
  nrowPrint = 20,
  p = 0.05,
  type = c("np", "normal"),
  sliceby = c("factor", "asset", "riskType"),
  isPrint = TRUE,
  isPlot = FALSE,
  layout = NULL,
  stripText.cex = 1,
  axis.cex = 1,
  portfolio.only = 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, names of the vector should match with asset names. Default is NULL, in which case an equal weights will be used.

risk

one of 'Sd' (standard deviation), 'VaR' (Value-at-Risk) or 'ES' (Expected Tail Loss or Expected Shortfall for calculating risk decompositon. Default is 'Sd'

decomp

one of 'FMCR' (factor marginal contribution to risk), 'FCR' 'factor contribution to risk' or 'FPCR' (factor percent contribution to risk).

digits

digits of number in the resulting table. Default is NULL, in which case digtis = 3 will be used for decomp = ( 'FMCR', 'FCR'), digits = 1 will be used for decomp = 'FPCR'. Used only when isPrint = 'TRUE'

invert

a logical variable to change VaR/ES to positive number, default is False and will return positive values.

nrowPrint

a numerical value deciding number of assets/portfolio in result vector/table to print or plot

p

tail probability for calculation. Default is 0.05.

type

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

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

sliceby

one of 'factor' (slice/condition by factor) or 'asset' (slice/condition by asset) or 'riskType' Used only when isPlot = 'TRUE'

isPrint

logical variable to print numeric output or not.

isPlot

logical variable to generate plot or not.

layout

layout is a numeric vector of length 2 or 3 giving the number of columns, rows, and pages (optional) in a multipanel display.

stripText.cex

a number indicating the amount by which strip text in the plot(s) should be scaled relative to the default. 1=default, 1.5 is 50% larger, 0.5 is 50% smaller, etc.

axis.cex

a number indicating the amount by which axis in the plot(s) should be scaled relative to the default. 1=default, 1.5 is 50% larger, 0.5 is 50% smaller, etc.

portfolio.only

logical variable to choose if to calculate portfolio only decomposition, in which case multiple risk measures are allowed.

Value

A table containing

decomp = 'FMCR'

(N + 1) * (K + 1) matrix of marginal contributions to risk of portfolio return as well assets return, with first row of values for the portfolio and the remaining rows for the assets in the portfolio, with (K + 1) columns containing values for the K risk factors and the residual respectively

decomp = 'FCR'

(N + 1) * (K + 2) matrix of component contributions to risk of portfolio return as well assets return, with first row of values for the portfolio and the remaining rows for the assets in the portfolio, with first column containing portfolio and asset risk values and remaining (K + 1) columns containing values for the K risk factors and the residual respectively

decomp = 'FPCR'

(N + 1) * (K + 1) matrix of percentage component contributions to risk of portfolio return as well assets return, with first row of values for the portfolio and the remaining rows for the assets in the portfolio, with (K + 1) columns containing values for the K risk factors and the residual respectively

Where, K is the number of factors, N is the number of assets.

Author(s)

Douglas Martin, Lingjie Yi

See Also

fitTsfm, fitFfm for the different factor model fitting functions.

Examples

# Time Series Factor Model

data(managers, package = 'PerformanceAnalytics')

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

report <- repRisk(fit.macro, risk = "ES", decomp = 'FPCR',
                  nrowPrint = 10)
report

# plot
repRisk(fit.macro, risk = "ES", decomp = 'FPCR', isPrint = FALSE,
        isPlot = TRUE)

# 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
exposure.vars = c("SECTOR","ROE","BP","PM12M1M","SIZE","ANNVOL1M", "EP")
fit.cross <- fitFfm(data = dat,
                    exposure.vars = exposure.vars,
                    date.var = "DATE",
                    ret.var = "RETURN",
                    asset.var = "TICKER",
                    fit.method="WLS",
                    z.score = "crossSection")

repRisk(fit.cross, risk = "Sd", decomp = 'FCR', nrowPrint = 10,
        digits = 4)

# get the factor contributions of risk
repRisk(fit.cross, wtsStocks145GmvLo, risk = "Sd", decomp = 'FPCR',
        nrowPrint = 10)

# portfolio only decomposition
repRisk(fit.cross, wtsStocks145GmvLo, risk = c("VaR", "ES"), decomp = 'FPCR',
        portfolio.only = TRUE)

# plot
repRisk(fit.cross, wtsStocks145GmvLo, risk = "Sd", decomp = 'FPCR',
        isPrint = FALSE, nrowPrint = 15, isPlot = TRUE, layout = c(4,2))

braverock/factorAnalytics documentation built on March 2, 2024, 11:17 p.m.