portVolDecomp: Decompose portfolio variance risk into factor/residual risk

View source: R/portVolDecomp.R

portVolDecompR Documentation

Decompose portfolio variance risk into factor/residual risk

Description

Decompose portfolio variance risk into factor/residual risk

Usage

portVolDecomp(object, ...)

## S3 method for class 'tsfm'
portVolDecomp(
  object,
  weights = NULL,
  factor.cov,
  use = "pairwise.complete.obs",
  ...
)

## S3 method for class 'ffm'
portVolDecomp(object, weights = NULL, factor.cov, ...)

Arguments

object

fit object of class tsfm, or ffm.

...

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.

use

an optional character string giving a method for computing 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".

Value

A vector containing: percent factor contribution to risk portfolio volatility risk, factor volatility risk and residual/specific volatility risk

Author(s)

Douglas Martin, Lingjie Yi

See Also

fitTsfm, fitFfm for the different factor model fitting functions.

portSdDecomp for portfolio factor model VaR decomposition. portVaRDecomp for portfolio factor model VaR decomposition. portEsDecomp for portfolio factor model ES decomposition.

Examples

# Time Series Factor Model example

## Not run: 
 # load data
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)

decomp <- portVolDecomp(fit.macro)

decomp

# Fundamental Factor Model example

## First load CRSP and SPGMI data sets
data(stocksCRSP)
data(factorsSPGMI)
## merge by intersection variables
intersecting_vars <- intersect(names(stocksCRSP), names(factorsSPGMI))
   stocks_factors <- merge(stocksCRSP, factorsSPGMI, by = intersecting_vars)
## Remove observations with missing Sector/GICS
      NA_index <- is.na(stocks_factors$GICS) & is.na(stocks_factors$Sector)
stocks_factors <- stocks_factors[!NA_index]
## Setindex for faster processing
data.table::setindexv(stocks_factors, c("Date","TickerLast"))


# fit a fundamental factor model

exposure_vars = c("Sector", "AnnVol12M", "BP", "EP", "LogMktCap", "PM12M1M")

fit.cross <- fitFfm(data = stocks_factors,
                    asset.var = "TickerLast",
                    ret.var = "Return",
                    date.var = "Date",
                    exposure.vars = exposure_vars,
                    fit.method = "W-Rob",
                    z.score = "crossSection")

decomp <- portVolDecomp(fit.cross)

# get the factor contributions of risk
decomp
 
## End(Not run)


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