Learn R Programming

fPortfolio (version 260.72)

VaRModelling: Value-at-Risk Measures for Portfolios

Description

A collection and description of functions to compute Value-at-Risk and related risk measures for a portfolio of assets. In addition utility functions are available to compute the maximum loss, to calculate the total return, and to plot a histogram of the total return. The functions are:

ll{ pfolioVaR computes Value-at-Risk for a portfolio of assets, pfolioCVaRplus computes Value-at-Risk+ for a portfolio of assets, pfolioCVaR computes Conditional Value-at-Risk for a PF of assets, lambdaCVaR computes CVaR's atomic split value lambda, pfolioMaxLoss computes Maximum Loss for a portfolio of assets, pfolioReturn computes return values of a portfolio, pfolioTargetReturn computes the target return of a portfolio, pfolioTargetRisk computes the target risk of a portfolio, pfolioHist plots a histogram of the returns of a portfolio. }

Usage

pfolioVaR(x, weights = NULL, alpha = 0.05) 
pfolioCVaRplus(x, weights = NULL, alpha = 0.05) 
pfolioCVaR(x, weights = NULL, alpha = 0.05) 
lambdaCVaR(n, alpha = 0.05) 

pfolioMaxLoss(x, weights = NULL) pfolioReturn(x, weights = NULL) pfolioTargetReturn(x, weights = NULL) pfolioTargetRisk(x, weights = NULL) pfolioHist(x, weights = NULL, alpha = 0.05, range = NULL, details = TRUE, ...)

Arguments

alpha
a numeric value, the confidence interval, by default 0.05.
details
a logical value, should details be printed?
n
the number of observation from which the CVaR's atomic split value lambda=1-floor(alpha*n)/(alpha*n) will be evaluated.
weights
usually a numeric vector which has the length of the number of assets. The weights measures the normalized weights of the individual assets. By default NULL, then an equally weighted set of assets is assumed.
range
a numeric vector of two elements limiting the plot range of the histogram. This is quite useful if one likes to compare several plots on the same scale. If range=NULL, the default value, then the range will be selected
x
a 'timeSeries' object, data frame or any other rectangular object which can be expressed as a matrix. The first dimension is the number of observations, we call it n, and the second is the number of assets in the data
...
optional arguments to be passet to the function hist.

Value

  • pfolioVaR returns the value of risk, VaR, for a portfolio of assets, a numeric value. pfolioCVaRplus returns the conditional value of risk plus, CVaRplus, for a portfolio of assets, a numeric value. pfolioCVaR returns the conditional value of risk, CVaR, for a portfolio of assets, a numeric value. lambdaCVaR returns CVaR's atomic split value lambda, a numeric value. pfolioMaxLoss returns the maximum loss value of the portfolio, a numeric value. pfolioReturn returns the total portfolio return computed from the set of assets x, a numeric vector. pfolioTargetReturn returns the total return or target return computed from the set of assets x and weights weights, a numeric value. pfolioTargetRisk returns the total risk (Sigma) or target risk computed from the set of assets x and weights via the formual sqrt(weights %*% cov(x) %*% weights), a numeric value. pfolioHist plots a histogram of portfolio returns and adds the values for the VaR (blue), for the CVaRplus (red), and for the maximum loss (green) to the histogram plot. The function invisibly returns a list with the following elements: VaR, VaRplus, maxLoss, mean, and sd. If details is TRUE, then the result is printed.

Details

The percentile measures of loss (or reward) are defined in the following way: Let $f(x ,y)$ be a loss functions depending upon a decision vector $x = (x_1, ..., x_n )$ and a random vector $y = (y_1, ..., y_m)$, then pfolioVaR is the alpha-percentile of the loss distribution, a smallest value such that the probability that losses exceed or are equal to this value is greater or equal to alpha. pfolioCVaRplus or "CVaR+" or the "upper CVaR" are the expected losses strictly exceeding VaR. This is also also called "Mean Excess Loss" and "Expected Shortfall".

pfolioCVaR is a weighted average of VaR and CVaRplus defined as $CVaR = lambda*VaR + (1-lambda)$ CVaRplus, for $0

References

Uryasev S. (2000); Conditional Value-at-Risk (CVaR): Algorithms and Applications, Risk Management and Financial Engineering Lab, University of Florida

Examples

Run this code
## assetsSim -
   myAssets = 100/12 * assetsSim(n = 120, dim = 4)
   # Plot Cumulated Returns of the Assets:
   prices = apply(myAssets, 2, FUN = cumsum)
   par(mfrow = c(2, 1), cex = 0.7)
   ts.plot(prices, col = 1:4, ylim = c(-300, 300))
   legend(0, 300, legend = colnames(myAssets), pch = "----", col = 1:4)
   title(main = "Cumulated Returns", ylab = "Cumulated Returns")
   abline(h = 0, lty = 3)
    
## pfolioCVaR -
   equalWeights = rep(1/4, 4)
   alpha = 0.10
   # Value at Risk:
   pfolioVaR(myAssets, equalWeights, alpha)
   # Conditional Value at Risk Plus:
   pfolioCVaRplus(myAssets, equalWeights, alpha)
   # Conditional Value at Risk Plus:
   pfolioCVaR(myAssets, equalWeights, alpha)
   # Lambda - Atomic Split Value:
   lambdaCVaR(120, alpha) 

## pfolioHist - 
   # Maximum Loss Value of the Portfolio
   pfolioMaxLoss(myAssets, equalWeights)
   # Compute Portfolio Returns:
   r = pfolioReturn(myAssets, equalWeights) 
   head(r)
   # Target Return and Target Risk:
   pfolioTargetReturn(myAssets, equalWeights)
   pfolioTargetRisk(myAssets, equalWeights)
   # Plot:
   pfolioHist(myAssets, equalWeights, alpha, n = 20)

Run the code above in your browser using DataLab