Type: | Package |
Title: | Functions Ported from 'MMR2' Toolbox Offered in Kevin Dowd's Book Measuring Market Risk |
Version: | 0.12 |
Date: | 2015-08-20 |
Author: | Dinesh Acharya <dines.acharya@gmail.com> |
Maintainer: | Dinesh Acharya <dines.acharya@gmail.com> |
Description: | 'Kevin Dowd's' book Measuring Market Risk is a widely read book in the area of risk measurement by students and practitioners alike. As he claims, 'MATLAB' indeed might have been the most suitable language when he originally wrote the functions, but, with growing popularity of R it is not entirely valid. As 'Dowd's' code was not intended to be error free and were mainly for reference, some functions in this package have inherited those errors. An attempt will be made in future releases to identify and correct them. 'Dowd's' original code can be downloaded from www.kevindowd.org/measuring-market-risk/. It should be noted that 'Dowd' offers both 'MMR2' and 'MMR1' toolboxes. Only 'MMR2' was ported to R. 'MMR2' is more recent version of 'MMR1' toolbox and they both have mostly similar function. The toolbox mainly contains different parametric and non parametric methods for measurement of market risk as well as backtesting risk measurement methods. |
Depends: | R (≥ 3.0.0), bootstrap, MASS, forecast |
Suggests: | PerformanceAnalytics, testthat |
License: | GPL-2 | GPL-3 [expanded from: GPL] |
NeedsCompilation: | no |
Packaged: | 2016-03-10 10:14:28 UTC; dinesh |
Repository: | CRAN |
Date/Publication: | 2016-03-11 00:45:03 |
R-version of Kevin Dowd's MATLAB Toolbox from book "Measuring Market Risk".
Description
Dowd Kevin Dowd's book "Measuring Market Risk" gives overview of risk measurement procedures with focus on Value at Risk (VaR) and Expected Shortfall (ES).
Acknowledgments
Without Kevin Dowd's book Measuring Market Risk and accompanying MATLAB toolbox, this project would not have been possible.
Peter Carl and Brian G. Peterson deserve special acknowledgement for mentoring me on this project.
Author(s)
Dinesh Acharya
Maintainer: Dinesh Acharya dines.acharya@gmail.com
References
Dowd, K. Measuring Market Risk. Wiley. 2005.
Plots cumulative density for AD test and computes confidence interval for AD test stat.
Description
Anderson-Darling(AD) test can be used to carry out distribution equality test and is similar to Kolmogorov-Smirnov test. AD test statistic is defined as:
A^2=n\int_{-\infty}^{\infty}\frac{[\hat{F}(x)-F(x)]^2}{F(x)[1-F(x)]}dF(x)
which is equivalent to
=-n-\frac{1}{n}\sum_{i=1}^n(2i-1)[\ln F(X_i)+\ln(1-F(X_{n+1-i}))]
Usage
ADTestStat(number.trials, sample.size, confidence.interval)
Arguments
number.trials |
Number of trials |
sample.size |
Sample size |
confidence.interval |
Confidence Interval |
Value
Confidence Interval for AD test statistic
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Anderson, T.W. and Darling, D.A. Asymptotic Theory of Certain Goodness of Fit Criteria Based on Stochastic Processes, The Annals of Mathematical Statistics, 23(2), 1952, p. 193-212.
Kvam, P.H. and Vidakovic, B. Nonparametric Statistics with Applications to Science and Engineering, Wiley, 2007.
Examples
# Probability that the VaR model is correct for 3 failures, 100 number
# observations and 95% confidence level
ADTestStat(1000, 100, 0.95)
Hotspots for ES adjusted by Cornish-Fisher correction
Description
Estimates the ES hotspots (or vector of incremental ESs) for a portfolio with portfolio return adjusted for non-normality by Cornish-Fisher corerction, for specified confidence level and holding period.
Usage
AdjustedNormalESHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
Arguments
vc.matrix |
Variance covariance matrix for returns |
mu |
Vector of expected position returns |
skew |
Return skew |
kurtosis |
Return kurtosis |
positions |
Vector of positions |
cl |
Confidence level and is scalar |
hp |
Holding period and is scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Hotspots for ES for randomly generated portfolio
vc.matrix <- matrix(rnorm(16),4,4)
mu <- rnorm(4)
skew <- .5
kurtosis <- 1.2
positions <- c(5,2,6,10)
cl <- .95
hp <- 280
AdjustedNormalESHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
Hotspots for VaR adjusted by Cornish-Fisher correction
Description
Estimates the VaR hotspots (or vector of incremental VaRs) for a portfolio with portfolio return adjusted for non-normality by Cornish-Fisher corerction, for specified confidence level and holding period.
Usage
AdjustedNormalVaRHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
Arguments
vc.matrix |
Variance covariance matrix for returns |
mu |
Vector of expected position returns |
skew |
Return skew |
kurtosis |
Return kurtosis |
positions |
Vector of positions |
cl |
Confidence level and is scalar |
hp |
Holding period and is scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Hotspots for ES for randomly generated portfolio
vc.matrix <- matrix(rnorm(16),4,4)
mu <- rnorm(4)
skew <- .5
kurtosis <- 1.2
positions <- c(5,2,6,10)
cl <- .95
hp <- 280
AdjustedNormalVaRHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
Cornish-Fisher adjusted Variance-Covariance ES
Description
Function estimates the Variance-Covariance ES of a multi-asset portfolio using the Cornish - Fisher adjustment for portfolio return non-normality, for specified confidence level and holding period.
Usage
AdjustedVarianceCovarianceES(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
Arguments
vc.matrix |
Variance covariance matrix for returns |
mu |
Vector of expected position returns |
skew |
Return skew |
kurtosis |
Return kurtosis |
positions |
Vector of positions |
cl |
Confidence level and is scalar |
hp |
Holding period and is scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Variance-covariance ES for randomly generated portfolio
vc.matrix <- matrix(rnorm(16), 4, 4)
mu <- rnorm(4)
skew <- .5
kurtosis <- 1.2
positions <- c(5, 2, 6, 10)
cl <- .95
hp <- 280
AdjustedVarianceCovarianceES(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
Cornish-Fisher adjusted variance-covariance VaR
Description
Estimates the variance-covariance VaR of a multi-asset portfolio using the Cornish-Fisher adjustment for portfolio-return non-normality, for specified confidence level and holding period.
Usage
AdjustedVarianceCovarianceVaR(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
Arguments
vc.matrix |
Assumed variance covariance matrix for returns |
mu |
Vector of expected position returns |
skew |
Portfolio return skewness |
kurtosis |
Portfolio return kurtosis |
positions |
Vector of positions |
cl |
Confidence level and is scalar or vector |
hp |
Holding period and is scalar or vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Variance-covariance for randomly generated portfolio
vc.matrix <- matrix(rnorm(16),4,4)
mu <- rnorm(4)
skew <- .5
kurtosis <- 1.2
positions <- c(5,2,6,10)
cl <- .95
hp <- 280
AdjustedVarianceCovarianceVaR(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
Estimates ES of American vanilla put using binomial tree.
Description
Estimates ES of American Put Option using binomial tree to price the option and historical method to compute the VaR.
Usage
AmericanPutESBinomial(amountInvested, stockPrice, strike, r, volatility,
maturity, numberSteps, cl, hp)
Arguments
amountInvested |
Total amount paid for the Put Option. |
stockPrice |
Stock price of underlying stock. |
strike |
Strike price of the option. |
r |
Risk-free rate. |
volatility |
Volatility of the underlying stock. |
maturity |
Time to maturity of the option in days. |
numberSteps |
The number of time-steps considered for the binomial model. |
cl |
Confidence level for which VaR is computed. |
hp |
Holding period of the option in days. |
Value
ES of the American Put Option
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
Examples
# Market Risk of American Put with given parameters.
AmericanPutESBinomial(0.20, 27.2, 25, .16, .05, 60, 20, .95, 30)
Estimates ES of American vanilla put using binomial option valuation tree and Monte Carlo Simulation
Description
Estimates ES of American Put Option using binomial tree to price the option valuation tree and Monte Carlo simulation with a binomial option valuation tree nested within the MCS. Historical method to compute the VaR.
Usage
AmericanPutESSim(amountInvested, stockPrice, strike, r, mu, sigma, maturity,
numberTrials, numberSteps, cl, hp)
Arguments
amountInvested |
Total amount paid for the Put Option and is positive (negative) if the option position is long (short) |
stockPrice |
Stock price of underlying stock |
strike |
Strike price of the option |
r |
Risk-free rate |
mu |
Expected rate of return on the underlying asset and is in annualised term |
sigma |
Volatility of the underlying stock and is in annualised term |
maturity |
The term to maturity of the option in days |
numberTrials |
The number of interations in the Monte Carlo simulation exercise |
numberSteps |
The number of steps over the holding period at each of which early exercise is checked and is at least 2 |
cl |
Confidence level for which VaR is computed and is scalar |
hp |
Holding period of the option in days and is scalar |
Value
Monte Carlo Simulation VaR estimate and the bounds of the 95 confidence interval for the VaR, based on an order-statistics analysis of the P/L distribution
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
Examples
# Market Risk of American Put with given parameters.
AmericanPutESSim(0.20, 27.2, 25, .16, .2, .05, 60, 30, 20, .95, 30)
Binomial Put Price
Description
Estimates the price of an American Put, using the binomial approach.
Usage
AmericanPutPriceBinomial(stockPrice, strike, r, sigma, maturity, numberSteps)
Arguments
stockPrice |
Stock price of underlying stock |
strike |
Strike price of the option |
r |
Risk-free rate |
sigma |
Volatility of the underlying stock and is in annualised term |
maturity |
The term to maturity of the option in days |
numberSteps |
The number of time-steps in the binomial tree |
Value
Binomial American put price
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
Examples
# Estimates the price of an American Put
AmericanPutPriceBinomial(27.2, 25, .03, .2, 60, 30)
Estimates VaR of American vanilla put using binomial tree.
Description
Estimates VaR of American Put Option using binomial tree to price the option and historical method to compute the VaR.
Usage
AmericanPutVaRBinomial(amountInvested, stockPrice, strike, r, volatility,
maturity, numberSteps, cl, hp)
Arguments
amountInvested |
Total amount paid for the Put Option. |
stockPrice |
Stock price of underlying stock. |
strike |
Strike price of the option. |
r |
Risk-free rate. |
volatility |
Volatility of the underlying stock. |
maturity |
Time to maturity of the option in days. |
numberSteps |
The number of time-steps considered for the binomial model. |
cl |
Confidence level for which VaR is computed. |
hp |
Holding period of the option in days. |
Value
VaR of the American Put Option
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
Examples
# Market Risk of American Put with given parameters.
AmericanPutVaRBinomial(0.20, 27.2, 25, .16, .05, 60, 20, .95, 30)
Carries out the binomial backtest for a VaR risk measurement model.
Description
The basic idea behind binomial backtest (also called basic frequency test) is to test whether the observed frequency of losses that exceed VaR is consistent with the frequency of tail losses predicted by the mode. Binomial Backtest carries out the binomial backtest for a VaR risk measurement model for specified VaR confidence level and for a one-sided alternative hypothesis (H1).
Usage
BinomialBacktest(x, n, cl)
Arguments
x |
Number of failures |
n |
Number of observations |
cl |
Confidence level for VaR |
Value
Probability that the VaR model is correct
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Kupiec, Paul. Techniques for verifying the accuracy of risk measurement models, Journal of Derivatives, Winter 1995, p. 79.
Examples
# Probability that the VaR model is correct for 3 failures, 100 number
# observations and 95% confidence level
BinomialBacktest(55, 1000, 0.95)
ES of Black-Scholes call using Monte Carlo Simulation
Description
Estimates ES of Black-Scholes call Option using Monte Carlo simulation
Usage
BlackScholesCallESSim(amountInvested, stockPrice, strike, r, mu, sigma,
maturity, numberTrials, cl, hp)
Arguments
amountInvested |
Total amount paid for the Call Option and is positive (negative) if the option position is long (short) |
stockPrice |
Stock price of underlying stock |
strike |
Strike price of the option |
r |
Risk-free rate |
mu |
Expected rate of return on the underlying asset and is in annualised term |
sigma |
Volatility of the underlying stock and is in annualised term |
maturity |
The term to maturity of the option in days |
numberTrials |
The number of interations in the Monte Carlo simulation exercise |
cl |
Confidence level for which ES is computed and is scalar |
hp |
Holding period of the option in days and is scalar |
Value
ES
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
Examples
# Market Risk of American call with given parameters.
BlackScholesCallESSim(0.20, 27.2, 25, .16, .2, .05, 60, 30, .95, 30)
Price of European Call Option
Description
Derives the price of European call option using the Black-Scholes approach
Usage
BlackScholesCallPrice(stockPrice, strike, rf, sigma, t)
Arguments
stockPrice |
Stock price of underlying stock |
strike |
Strike price of the option |
rf |
Risk-free rate and is annualised |
sigma |
Volatility of the underlying stock |
t |
The term to maturity of the option in years |
Value
Price of European Call Option
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Hull, John C.. Options, Futures, and Other Derivatives. 5th ed., p. 246.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
Examples
# Estimates the price of an American Put
BlackScholesCallPrice(27.2, 25, .03, .2, 60)
ES of Black-Scholes put using Monte Carlo Simulation
Description
Estimates ES of Black-Scholes Put Option using Monte Carlo simulation
Usage
BlackScholesPutESSim(amountInvested, stockPrice, strike, r, mu, sigma, maturity,
numberTrials, cl, hp)
Arguments
amountInvested |
Total amount paid for the Put Option and is positive (negative) if the option position is long (short) |
stockPrice |
Stock price of underlying stock |
strike |
Strike price of the option |
r |
Risk-free rate |
mu |
Expected rate of return on the underlying asset and is in annualised term |
sigma |
Volatility of the underlying stock and is in annualised term |
maturity |
The term to maturity of the option in days |
numberTrials |
The number of interations in the Monte Carlo simulation exercise |
cl |
Confidence level for which ES is computed and is scalar |
hp |
Holding period of the option in days and is scalar |
Value
ES
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
Examples
# Market Risk of American Put with given parameters.
BlackScholesPutESSim(0.20, 27.2, 25, .03, .12, .05, 60, 1000, .95, 30)
Price of European Put Option
Description
Derives the price of European call option using the Black-Scholes approach
Usage
BlackScholesPutPrice(stockPrice, strike, rf, sigma, t)
Arguments
stockPrice |
Stock price of underlying stock |
strike |
Strike price of the option |
rf |
Risk-free rate and is annualised |
sigma |
Volatility of the underlying stock |
t |
The term to maturity of the option in years |
Value
Price of European Call Option
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Hull, John C.. Options, Futures, and Other Derivatives. 5th ed., p. 246.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
Examples
# Estimates the price of an American Put
BlackScholesPutPrice(27.2, 25, .03, .2, 60)
Blanco-Ihle forecast evaluation backtest measure
Description
Derives the Blanco-Ihle forecast evaluation loss measure for a VaR risk measurement model.
Usage
BlancoIhleBacktest(Ra, Rb, Rc, cl)
Arguments
Ra |
Vector of a portfolio profit and loss |
Rb |
Vector of corresponding VaR forecasts |
Rc |
Vector of corresponding Expected Tailed Loss forecasts |
cl |
VaR confidence interval |
Value
First Blanco-Ihle score measure.
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Blanco, C. and Ihle, G. How Good is Your Var? Using Backtesting to Assess System Performance. Financial Engineering News, 1999.
Examples
# Blanco-Ihle Backtest For Independence for given confidence level.
# The VaR and ES are randomly generated.
a <- rnorm(1*100)
b <- abs(rnorm(1*100))+2
c <- abs(rnorm(1*100))+2
BlancoIhleBacktest(a, b, c, 0.95)
Bootstrapped ES for specified confidence level
Description
Estimates the bootstrapped ES for confidence level and holding period implied by data frequency.
Usage
BootstrapES(Ra, number.resamples, cl)
Arguments
Ra |
Vector corresponding to profit and loss distribution |
number.resamples |
Number of samples to be taken in bootstrap procedure |
cl |
Number corresponding to Expected Shortfall confidence level |
Value
Bootstrapped Expected Shortfall
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates bootstrapped ES for given parameters
a <- rnorm(100) # generate a random profit/loss vector
BootstrapVaR(a, 50, 0.95)
Bootstrapped ES Confidence Interval
Description
Estimates the 90 level and holding period implied by data frequency.
Usage
BootstrapESConfInterval(Ra, number.resamples, cl)
Arguments
Ra |
Vector corresponding to profit and loss distribution |
number.resamples |
Number of samples to be taken in bootstrap procedure |
cl |
Number corresponding to Expected Shortfall confidence level |
Value
90
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# To be modified with appropriate data.
# Estimates 90% confidence interval for bootstrapped ES for 95%
# confidence interval
Ra <- rnorm(1000)
BootstrapESConfInterval(Ra, 50, 0.95)
Plots figure of bootstrapped ES
Description
Plots figure for the bootstrapped ES, for confidence level and holding period implied by data frequency.
Usage
BootstrapESFigure(Ra, number.resamples, cl)
Arguments
Ra |
Vector corresponding to profit and loss distribution |
number.resamples |
Number of samples to be taken in bootstrap procedure |
cl |
Number corresponding to Expected Shortfall confidence level |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# To be modified with appropriate data.
# Estimates 90% confidence interval for bootstrapped ES for 95%
# confidence interval
Ra <- rnorm(1000)
BootstrapESFigure(Ra, 500, 0.95)
Bootstrapped VaR for specified confidence level
Description
Estimates the bootstrapped VaR for confidence level and holding period implied by data frequency.
Usage
BootstrapVaR(Ra, number.resamples, cl)
Arguments
Ra |
Vector corresponding to profit and loss distribution |
number.resamples |
Number of samples to be taken in bootstrap procedure |
cl |
Number corresponding to Value at Risk confidence level |
Value
Bootstrapped VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates bootstrapped VaR for given parameters
a <- rnorm(100) # generate a random profit/loss vector
BootstrapES(a, 50, 0.95)
Bootstrapped VaR Confidence Interval
Description
Estimates the 90 level and holding period implied by data frequency.
Usage
BootstrapVaRConfInterval(Ra, number.resamples, cl)
Arguments
Ra |
Vector corresponding to profit and loss distribution |
number.resamples |
Number of samples to be taken in bootstrap procedure |
cl |
Number corresponding to Value at Risk confidence level |
Value
90
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# To be modified with appropriate data.
# Estimates 90% confidence interval for bootstrapped Var for 95%
# confidence interval
Ra <- rnorm(1000)
BootstrapVaRConfInterval(Ra, 500, 0.95)
Plots figure of bootstrapped VaR
Description
Plots figure for the bootstrapped VaR, for confidence level and holding period implied by data frequency.
Usage
BootstrapVaRFigure(Ra, number.resamples, cl)
Arguments
Ra |
Vector corresponding to profit and loss distribution |
number.resamples |
Number of samples to be taken in bootstrap procedure |
cl |
Number corresponding to Value at Risk confidence level |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# To be modified with appropriate data.
# Estimates 90% confidence interval for bootstrapped VaR for 95%
# confidence interval
Ra <- rnorm(1000)
BootstrapESFigure(Ra, 500, 0.95)
Estimates ES with Box-Cox transformation
Description
Function estimates the ES of a portfolio assuming P and L data set transformed using the BoxCox transformation to make it as near normal as possible, for specified confidence level and holding period implied by data frequency.
Usage
BoxCoxES(loss.data, cl)
Arguments
loss.data |
Daily Profit/Loss data |
cl |
Confidence Level. It can be a scalar or a vector. |
Value
Estimated Box-Cox ES. Its dimension is same as that of cl
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Hamilton, S. A. and Taylor, M. G. A Comparision of the Box-Cox transformation method and nonparametric methods for estimating quantiles in clinical data with repeated measures. J. Statist. Comput. Simul., vol. 45, 1993, pp. 185 - 201.
Examples
# Estimates Box-Cox VaR
a<-rnorm(200)
BoxCoxES(a,.95)
Estimates VaR with Box-Cox transformation
Description
Function estimates the VaR of a portfolio assuming P and L data set transformed using the BoxCox transformation to make it as near normal as possible, for specified confidence level and holding period implied by data frequency.
Usage
BoxCoxVaR(PandLdata, cl)
Arguments
PandLdata |
Daily Profit/Loss data |
cl |
Confidence Level. It can be a scalar or a vector. |
Value
Estimated Box-Cox VaR. Its dimension is same as that of cl
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Hamilton, S. A. and Taylor, M. G. A Comparision of the Box-Cox transformation method and nonparametric methods for estimating quantiles in clinical data with repeated measures. J. Statist. Comput. Simul., vol. 45, 1993, pp. 185 - 201.
Examples
# Estimates Box-Cox VaR
a<-rnorm(100)
BoxCoxVaR(a,.95)
Derives prob ( X + Y < quantile) using Gaussian copula
Description
If X and Y are position P/Ls, then the VaR is equal to minus quantile. In such cases, we insert the negative of the VaR as the quantile, and the function gives us the value of 1 minus VaR confidence level. In other words, if X and Y are position P/Ls, the quantile is the negative of the VaR, and the output is 1 minus the VaR confidence level.
Usage
CdfOfSumUsingGaussianCopula(quantile, mu1, mu2, sigma1, sigma2, rho,
number.steps.in.copula)
Arguments
quantile |
Portfolio quantile (or negative of Var, if X, Y are position P/Ls) |
mu1 |
Mean of Profit/Loss on first position |
mu2 |
Mean of Profit/Loss on second position |
sigma1 |
Standard Deviation of Profit/Loss on first position |
sigma2 |
Standard Deviation of Profit/Loss on second position |
rho |
Correlation between P/Ls on two positions |
number.steps.in.copula |
The number of steps used in the copula approximation |
Value
Probability of X + Y being less than quantile
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Dowd, K. and Fackler, P. Estimating VaR with copulas. Financial Engineering News, 2004.
Examples
# Prob ( X + Y < q ) using Gaussian Copula for X with mean 2.3 and std. .2
# and Y with mean 4.5 and std. 1.5 with beta 1.2 at 0.9 quantile
CdfOfSumUsingGaussianCopula(0.9, 2.3, 4.5, 1.2, 1.5, 0.6, 15)
Derives prob ( X + Y < quantile) using Gumbel copula
Description
If X and Y are position P/Ls, then the VaR is equal to minus quantile. In such cases, we insert the negative of the VaR as the quantile, and the function gives us the value of 1 minus VaR confidence level. In other words, if X and Y are position P/Ls, the quantile is the negative of the VaR, and the output is 1 minus the VaR confidence level.
Usage
CdfOfSumUsingGumbelCopula(quantile, mu1, mu2, sigma1, sigma2, beta)
Arguments
quantile |
Portfolio quantile (or negative of Var, if X, Y are position P/Ls) |
mu1 |
Mean of Profit/Loss on first position |
mu2 |
Mean of Profit/Loss on second position |
sigma1 |
Standard Deviation of Profit/Loss on first position |
sigma2 |
Standard Deviation of Profit/Loss on second position |
beta |
Gumber copula parameter (greater than 1) |
Value
Probability of X + Y being less than quantile
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Dowd, K. and Fackler, P. Estimating VaR with copulas. Financial Engineering News, 2004.
Examples
# Prob ( X + Y < q ) using Gumbel Copula for X with mean 2.3 and std. .2
# and Y with mean 4.5 and std. 1.5 with beta 1.2 at 0.9 quantile
CdfOfSumUsingGumbelCopula(0.9, 2.3, 4.5, 1.2, 1.5, 1.2)
Derives prob ( X + Y < quantile) using Product copula
Description
If X and Y are position P/Ls, then the VaR is equal to minus quantile. In such cases, we insert the negative of the VaR as the quantile, and the function gives us the value of 1 minus VaR confidence level. In other words, if X and Y are position P/Ls, the quantile is the negative of the VaR, and the output is 1 minus the VaR confidence level.
Usage
CdfOfSumUsingProductCopula(quantile, mu1, mu2, sigma1, sigma2)
Arguments
quantile |
Portfolio quantile (or negative of Var, if X, Y are position P/Ls) |
mu1 |
Mean of Profit/Loss on first position |
mu2 |
Mean of Profit/Loss on second position |
sigma1 |
Standard Deviation of Profit/Loss on first position |
sigma2 |
Standard Deviation of Profit/Loss on second position |
Value
Probability of X + Y being less than quantile
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Dowd, K. and Fackler, P. Estimating VaR with copulas. Financial Engineering News, 2004.
Examples
# Prob ( X + Y < q ) using Product Copula for X with mean 2.3 and std. .2
# and Y with mean 4.5 and std. 1.5 with beta 1.2 at 0.9 quantile
CdfOfSumUsingProductCopula(0.9, 2.3, 4.5, 1.2, 1.5)
Christoffersen Backtest for Independence
Description
Carries out the Christoffersen backtest of independence for a VaR risk measurement model, for specified VaR confidence level.
Usage
ChristoffersenBacktestForIndependence(Ra, Rb, cl)
Arguments
Ra |
Vector of portfolio profit and loss observations |
Rb |
Vector of corresponding VaR forecasts |
cl |
Confidence interval for |
Value
Probability that given the data set, the null hypothesis (i.e. independence) is correct.
Author(s)
Dinesh Acharya
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Christoffersen, P. Evaluating Interval Forecasts. International Economic Review, 39(4), 1992, 841-862.
Examples
# Has to be modified with appropriate data:
# Christoffersen Backtest For Independence for given parameters
a <- rnorm(1*100)
b <- abs(rnorm(1*100))+2
ChristoffersenBacktestForIndependence(a, b, 0.95)
Christoffersen Backtest for Unconditional Coverage
Description
Carries out the Christiffersen backtest for unconditional coverage for a VaR risk measurement model, for specified VaR confidence level.
Usage
ChristoffersenBacktestForUnconditionalCoverage(Ra, Rb, cl)
Arguments
Ra |
Vector of portfolio profit and loss observations |
Rb |
Vector of VaR forecasts corresponding to PandL observations |
cl |
Confidence level for VaR |
Value
Probability, given the data set, that the null hypothesis (i.e. a correct model) is correct.
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Christoffersen, P. Evaluating interval forecasts. International Economic Review, 39(4), 1998, 841-862.
Examples
# Has to be modified with appropriate data:
# Christoffersen Backtest For Unconditional Coverage for given parameters
a <- rnorm(1*100)
b <- abs(rnorm(1*100))+2
ChristoffersenBacktestForUnconditionalCoverage(a, b, 0.95)
Corn-Fisher ES
Description
Function estimates the ES for near-normal P/L using the Cornish-Fisher adjustment for non-normality, for specified confidence level.
Usage
CornishFisherES(mu, sigma, skew, kurtosis, cl)
Arguments
mu |
Mean of P/L distribution |
sigma |
Variance of of P/L distribution |
skew |
Skew of P/L distribution |
kurtosis |
Kurtosis of P/L distribution |
cl |
ES confidence level |
Value
Expected Shortfall
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Zangri, P. A VaR methodology for portfolios that include options. RiskMetrics Monitor, First quarter, 1996, p. 4-12.
Examples
# Estimates Cornish-Fisher ES for given parameters
CornishFisherES(3.2, 5.6, 2, 3, .9)
Corn-Fisher VaR
Description
Function estimates the VaR for near-normal P/L using the Cornish-Fisher adjustment for non-normality, for specified confidence level.
Usage
CornishFisherVaR(mu, sigma, skew, kurtosis, cl)
Arguments
mu |
Mean of P/L distribution |
sigma |
Variance of of P/L distribution |
skew |
Skew of P/L distribution |
kurtosis |
Kurtosis of P/L distribution |
cl |
VaR confidence level |
Value
Value at Risk
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Zangri, P. A VaR methodology for portfolios that include options. RiskMetrics Monitor, First quarter, 1996, p. 4-12.
Examples
# Estimates Cornish-Fisher VaR for given parameters
CornishFisherVaR(3.2, 5.6, 2, 3, .9)
Monte Carlo VaR for DB pension
Description
Generates Monte Carlo VaR for DB pension in Chapter 6.7.
Usage
DBPensionVaR(mu, sigma, p, life.expectancy, number.trials, cl)
Arguments
mu |
Expected rate of return on pension-fund assets |
sigma |
Volatility of rate of return of pension-fund assets |
p |
Probability of unemployment in any period |
life.expectancy |
Life expectancy |
number.trials |
Number of trials |
cl |
VaR confidence level |
Value
VaR for DB pension
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates the price of an American Put
DBPensionVaR(.06, .2, .05, 80, 100, .95)
Monte Carlo VaR for DC pension
Description
Generates Monte Carlo VaR for DC pension in Chapter 6.7.
Usage
DCPensionVaR(mu, sigma, p, life.expectancy, number.trials, cl)
Arguments
mu |
Expected rate of return on pension-fund assets |
sigma |
Volatility of rate of return of pension-fund assets |
p |
Probability of unemployment in any period |
life.expectancy |
Life expectancy |
number.trials |
Number of trials |
cl |
VaR confidence level |
Value
VaR for DC pension
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates the price of an American Put
DCPensionVaR(.06, .2, .05, 80, 100, .95)
VaR for default risky bond portfolio
Description
Generates Monte Carlo VaR for default risky bond portfolio in Chapter 6.4
Usage
DefaultRiskyBondVaR(r, rf, coupon, sigma, amount.invested, recovery.rate, p,
number.trials, hp, cl)
Arguments
r |
Spot (interest) rate, assumed to be flat |
rf |
Risk-free rate |
coupon |
Coupon rate |
sigma |
Variance |
amount.invested |
Amount Invested |
recovery.rate |
Recovery rate |
p |
Probability of default |
number.trials |
Number of trials |
hp |
Holding period |
cl |
Confidence level |
Value
Monte Carlo VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# VaR for default risky bond portfolio for given parameters
DefaultRiskyBondVaR(.01, .01, .1, .01, 1, .1, .2, 100, 100, .95)
Log Normal VaR with filter strategy
Description
Generates Monte Carlo lognormal VaR with filter portfolio strategy
Usage
FilterStrategyLogNormalVaR(mu, sigma, number.trials, alpha, cl, hp)
Arguments
mu |
Mean arithmetic return |
sigma |
Standard deviation of arithmetic return |
number.trials |
Number of trials used in the simulations |
alpha |
Participation parameter |
cl |
Confidence Level |
hp |
Holding Period |
Value
Lognormal VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates standard error of normal quantile estimate
FilterStrategyLogNormalVaR(0, .2, 100, 1.2, .95, 10)
Frechet Expected Shortfall
Description
Estimates the ES of a portfolio assuming extreme losses are Frechet distributed, for specified confidence level and a given holding period.
Usage
FrechetES(mu, sigma, tail.index, n, cl, hp)
Arguments
mu |
Location parameter for daily L/P |
sigma |
Scale parameter for daily L/P |
tail.index |
Tail index |
n |
Block size from which maxima are drawn |
cl |
Confidence level |
hp |
Holding period |
Details
Note that the long-right-hand tail is fitted to losses, not profits.
Value
Estimated ES. If cl and hp are scalars, it returns scalar VaR. If cl is vector and hp is a scalar, or viceversa, returns vector of VaRs. If both cl and hp are vectors, returns a matrix of VaRs.
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Embrechts, P., Kluppelberg, C. and Mikosch, T., Modelling Extremal Events for Insurance and Finance. Springer, Berlin, 1997, p. 324.
Reiss, R. D. and Thomas, M. Statistical Analysis of Extreme Values from Insurance, Finance, Hydrology and Other Fields, Birkhaueser, Basel, 1997, 15-18.
Examples
# Computes ES assuming Frechet Distribution for given parameters
FrechetES(3.5, 2.3, 1.6, 10, .95, 30)
Plots Frechet Expected Shortfall against confidence level
Description
Plots the ES of a portfolio against confidence level assuming extreme losses are Frechet distributed, for specified confidence level and a given holding period.
Usage
FrechetESPlot2DCl(mu, sigma, tail.index, n, cl, hp)
Arguments
mu |
Location parameter for daily L/P |
sigma |
Scale parameter for daily L/P |
tail.index |
Tail index |
n |
Block size from which maxima are drawn |
cl |
Confidence level and should be a vector |
hp |
Holding period |
Details
Note that the long-right-hand tail is fitted to losses, not profits.
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Embrechts, P., Kluppelberg, C. and Mikosch, T., Modelling Extremal Events for Insurance and Finance. Springer, Berlin, 1997, p. 324.
Reiss, R. D. and Thomas, M. Statistical Analysis of Extreme Values from Insurance, Finance, Hydrology and Other Fields, Birkhaueser, Basel, 1997, 15-18.
Examples
# Plots ES against vector of cl assuming Frechet Distribution for given parameters
cl <- seq(0.9,0.99,0.01)
FrechetESPlot2DCl(3.5, 2.3, 1.6, 10, cl, 30)
Frechet Value at Risk
Description
Estimates the VaR of a portfolio assuming extreme losses are Frechet distributed, for specified range of confidence level and a given holding period.
Usage
FrechetVaR(mu, sigma, tail.index, n, cl, hp)
Arguments
mu |
Location parameter for daily L/P |
sigma |
Scale parameter for daily L/P |
tail.index |
Tail index |
n |
Block size from which maxima are drawn |
cl |
Confidence level |
hp |
Holding period |
Details
Note that the long-right-hand tail is fitted to losses, not profits.
Value
Value at Risk. If cl and hp are scalars, it returns scalar VaR. If cl is vector and hp is a scalar, or viceversa, returns vector of VaRs. If both cl and hp are vectors, returns a matrix of VaRs.
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Embrechts, P., Kluppelberg, C. and Mikosch, T., Modelling Extremal Events for Insurance and Finance. Springer, Berlin, 1997, p. 324.
Reiss, R. D. and Thomas, M. Statistical Analysis of Extreme Values from Insurance, Finance, Hydrology and Other Fields, Birkhaueser, Basel, 1997, 15-18.
Examples
# Computes VaR assuming Frechet Distribution for given parameters
FrechetVaR(3.5, 2.3, 1.6, 10, .95, 30)
Plots Frechet Value at Risk against Cl
Description
Plots the VaR of a portfolio against confidence level assuming extreme losses are Frechet distributed, for specified range of confidence level and a given holding period.
Usage
FrechetVaRPlot2DCl(mu, sigma, tail.index, n, cl, hp)
Arguments
mu |
Location parameter for daily L/P |
sigma |
Scale parameter for daily L/P |
tail.index |
Tail index |
n |
Block size from which maxima are drawn |
cl |
Confidence level and should be a vector |
hp |
Holding period and should be a scalar |
Details
Note that the long-right-hand tail is fitted to losses, not profits.
Author(s)
Dinesh Acharya
References
Dowd, K. Measurh ing Market Risk, Wiley, 2007.
Embrechts, P., Kluppelberg, C. and Mikosch, T., Modelling Extremal Events for Insurance and Finance. Springer, Berlin, 1997, p. 324.
Reiss, R. D. and Thomas, M. Statistical Analysis of Extreme Values from Insurance, Finance, Hydrology and Other Fields, Birkhaueser, Basel, 1997, 15-18.
Examples
# Plots VaR against vector of cl assuming Frechet Distribution for given parameters
cl <- seq(0.9, .99, .01)
FrechetVaRPlot2DCl(3.5, 2.3, 1.6, 10, cl, 30)
Expected Shortfall for Generalized Pareto
Description
Estimates the ES of a portfolio assuming losses are distributed as a generalised Pareto.
Usage
GParetoES(Ra, beta, zeta, threshold.prob, cl)
Arguments
Ra |
Vector of daily Profit/Loss data |
beta |
Assumed scale parameter |
zeta |
Assumed tail index |
threshold.prob |
Threshold probability |
cl |
VaR confidence level |
Value
Expected Shortfall
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
McNeil, A., Extreme value theory for risk managers. Mimeo, ETHZ, 1999.
Examples
# Computes ES assuming generalised Pareto for following parameters
Ra <- 5 * rnorm(100)
beta <- 1.2
zeta <- 1.6
threshold.prob <- .85
cl <- .99
GParetoES(Ra, beta, zeta, threshold.prob, cl)
Plot of Emperical and Generalised Pareto mean excess functions
Description
Plots of emperical mean excess function and Generalized mean excess function.
Usage
GParetoMEFPlot(Ra, mu, beta, zeta)
Arguments
Ra |
Vector of daily Profit/Loss data |
mu |
Location parameter |
beta |
Scale parameter |
zeta |
Assumed tail index |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes ES assuming generalised Pareto for following parameters
Ra <- 5 * rnorm(100)
mu <- 0
beta <- 1.2
zeta <- 1.6
GParetoMEFPlot(Ra, mu, beta, zeta)
Plot of Emperical and 2 Generalised Pareto mean excess functions
Description
Plots of emperical mean excess function and two generalized pareto mean excess functions which differ in their tail-index value.
Usage
GParetoMultipleMEFPlot(Ra, mu, beta, zeta1, zeta2)
Arguments
Ra |
Vector of daily Profit/Loss data |
mu |
Location parameter |
beta |
Scale parameter |
zeta1 |
Assumed tail index for first mean excess function |
zeta2 |
Assumed tail index for second mean excess function |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes ES assuming generalised Pareto for following parameters
Ra <- 5 * rnorm(100)
mu <- 1
beta <- 1.2
zeta1 <- 1.6
zeta2 <- 2.2
GParetoMultipleMEFPlot(Ra, mu, beta, zeta1, zeta2)
VaR for Generalized Pareto
Description
Estimates the Value at Risk of a portfolio assuming losses are distributed as a generalised Pareto.
Usage
GParetoVaR(Ra, beta, zeta, threshold.prob, cl)
Arguments
Ra |
Vector of daily Profit/Loss data |
beta |
Assumed scale parameter |
zeta |
Assumed tail index |
threshold.prob |
Threshold probability corresponding to threshold u and x |
cl |
VaR confidence level |
Value
Expected Shortfall
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
McNeil, A., Extreme value theory for risk managers. Mimeo, ETHZ, 1999.
Examples
# Computes ES assuming generalised Pareto for following parameters
Ra <- 5 * rnorm(100)
beta <- 1.2
zeta <- 1.6
threshold.prob <- .85
cl <- .99
GParetoVaR(Ra, beta, zeta, threshold.prob, cl)
Bivariate Gaussian Copule VaR
Description
Derives VaR using bivariate Gaussian copula with specified inputs for normal marginals.
Usage
GaussianCopulaVaR(mu1, mu2, sigma1, sigma2, rho, number.steps.in.copula, cl)
Arguments
mu1 |
Mean of Profit/Loss on first position |
mu2 |
Mean of Profit/Loss on second position |
sigma1 |
Standard Deviation of Profit/Loss on first position |
sigma2 |
Standard Deviation of Profit/Loss on second position |
rho |
Correlation between Profit/Loss on two positions |
number.steps.in.copula |
Number of steps used in the copula approximation ( approximation being needed because Gaussian copula lacks a closed form solution) |
cl |
VaR confidece level |
Value
Copula based VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Dowd, K. and Fackler, P. Estimating VaR with copulas. Financial Engineering News, 2004.
Examples
# VaR using bivariate Gaussian for X and Y with given parameters:
GaussianCopulaVaR(2.3, 4.1, 1.2, 1.5, .6, 10, .95)
Bivariate Gumbel Copule VaR
Description
Derives VaR using bivariate Gumbel or logistic copula with specified inputs for normal marginals.
Usage
GumbelCopulaVaR(mu1, mu2, sigma1, sigma2, beta, cl)
Arguments
mu1 |
Mean of Profit/Loss on first position |
mu2 |
Mean of Profit/Loss on second position |
sigma1 |
Standard Deviation of Profit/Loss on first position |
sigma2 |
Standard Deviation of Profit/Loss on second position |
beta |
Gumber copula parameter (greater than 1) |
cl |
VaR onfidece level |
Value
Copula based VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Dowd, K. and Fackler, P. Estimating VaR with copulas. Financial Engineering News, 2004.
Examples
# VaR using bivariate Gumbel for X and Y with given parameters:
GumbelCopulaVaR(1.1, 3.1, 1.2, 1.5, 1.1, .95)
Gumbel ES
Description
Estimates the ES of a portfolio assuming extreme losses are Gumbel distributed, for specified confidence level and holding period. Note that the long-right-hand tail is fitted to losses, not profits.
Usage
GumbelES(mu, sigma, n, cl, hp)
Arguments
mu |
Location parameter for daily L/P |
sigma |
Assumed scale parameter for daily L/P |
n |
Assumed block size from which the maxima are drawn |
cl |
VaR confidence level |
hp |
VaR holding period |
Value
Estimated ES. If cl and hp are scalars, it returns scalar VaR. If cl is vector and hp is a scalar, or viceversa, returns vector of VaRs. If both cl and hp are vectors, returns a matrix of VaRs.
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
National Institute of Standards and Technology, Dataplot Reference Manual. Volume 1: Commands. NIST: Washington, DC, 1997, p. 8-67.
Examples
# Gumber ES Plot
GumbelES(0, 1.2, 100, c(.9,.88, .85, .8), 280)
Gumbel VaR
Description
Estimates the EV VaR of a portfolio assuming extreme losses are Gumbel distributed, for specified confidence level and holding period.
Usage
GumbelESPlot2DCl(mu, sigma, n, cl, hp)
Arguments
mu |
Location parameter for daily L/P |
sigma |
Assumed scale parameter for daily L/P |
n |
size from which the maxima are drawn |
cl |
VaR confidence level |
hp |
VaR holding period |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots ES against Cl
GumbelESPlot2DCl(0, 1.2, 100, seq(0.8,0.99,0.02), 280)
Gumbel VaR
Description
Estimates the EV VaR of a portfolio assuming extreme losses are Gumbel distributed, for specified confidence level and holding period.
Usage
GumbelVaR(mu, sigma, n, cl, hp)
Arguments
mu |
Location parameter for daily L/P |
sigma |
Assumed scale parameter for daily L/P |
n |
Size from which the maxima are drawn |
cl |
VaR confidence level |
hp |
VaR holding period |
Value
Estimated VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Gumbel VaR
GumbelVaR(0, 1.2, 100, c(.9,.88, .85, .8), 280)
Gumbel VaR
Description
Estimates the EV VaR of a portfolio assuming extreme losses are Gumbel distributed, for specified confidence level and holding period.
Usage
GumbelVaRPlot2DCl(mu, sigma, n, cl, hp)
Arguments
mu |
Location parameter for daily L/P |
sigma |
Assumed scale parameter for daily L/P |
n |
size from which the maxima are drawn |
cl |
VaR confidence level |
hp |
VaR holding period |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots VaR against Cl
GumbelVaRPlot2DCl(0, 1.2, 100, c(.9,.88, .85, .8), 280)
Expected Shortfall of a portfolio using Historical Estimator
Description
Estimates the Expected Shortfall (aka. Average Value at Risk or Conditional Value at Risk) using historical estimator approach for the specified confidence level and the holding period implies by data frequency.
Usage
HSES(Ra, cl)
Arguments
Ra |
Vector corresponding to profit and loss distribution |
cl |
Number between 0 and 1 corresponding to confidence level |
Value
Expected Shortfall of the portfolio
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Cont, R., Deguest, R. and Scandolo, G. Robustness and sensitivity analysis of risk measurement procedures. Quantitative Finance, 10(6), 2010, 593-606.
Acerbi, C. and Tasche, D. On the coherence of Expected Shortfall. Journal of Banking and Finance, 26(7), 2002, 1487-1503
Artzner, P., Delbaen, F., Eber, J.M. and Heath, D. Coherent Risk Measures of Risk. Mathematical Finance 9(3), 1999, 203.
Foellmer, H. and Scheid, A. Stochastic Finance: An Introduction in Discrete Time. De Gryuter, 2011.
Examples
# Computes Historical Expected Shortfall for a given profit/loss
# distribution and confidence level
a <- rnorm(100) # generate a random profit/loss vector
HSES(a, 0.95)
Percentile of historical simulation ES distribution function
Description
Estimates percentiles of historical simulation ES distribution function, using theory of order statistics, for specified confidence level.
Usage
HSESDFPerc(Ra, perc, cl)
Arguments
Ra |
Vector of daily P/L data |
perc |
Desired percentile and is scalar |
cl |
VaR confidence level and is scalar |
Value
Value of percentile of VaR distribution function
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates Percentiles for random standard normal returns and given perc
# and cl
Ra <- rnorm(100)
HSESDFPerc(Ra, .75, .95)
Figure of Historical SImulation VaR and ES and histogram of L/P
Description
Plots figure showing the historical simulation VaR and ES and histogram of L/P for specified confidence level and holding period implied by data frequency.
Usage
HSESFigure(Ra, cl)
Arguments
Ra |
Vector of profit loss data |
cl |
VaR confidence level |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots figure showing VaR and histogram of P/L data
Ra <- rnorm(100)
HSESFigure(Ra, .95)
Plots historical simulation ES against confidence level
Description
Function plots the historical simulation ES of a portfolio against confidence level, for specified range of confidence level and holding period implied by data frequency.
Usage
HSESPlot2DCl(Ra, cl)
Arguments
Ra |
Vector of daily P/L data |
cl |
Vector of ES confidence levels |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots historical simulation ES against confidence level
Ra <- rnorm(100)
cl <- seq(.90, .99, .01)
HSESPlot2DCl(Ra, cl)
Value at Risk of a portfolio using Historical Estimator
Description
Estimates the Value at Risk (VaR) using historical estimator approach for the specified range of confidence levels and the holding period implies by data frequency.
Usage
HSVaR(Ra, Rb)
Arguments
Ra |
Vector corresponding to profit and loss distribution |
Rb |
Scalar corresponding to VaR confidence levels. |
Value
Value at Risk of the portfolio
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Jorion, P. Value at Risk: The New Benchmark for Managing Financial Risk. McGraw-Hill, 2006
Cont, R., Deguest, R. and Scandolo, G. Robustness and sensitivity analysis of risk measurement procedures. Quantitative Finance, 10(6), 2010, 593-606.
Artzner, P., Delbaen, F., Eber, J.M. and Heath, D. Coherent Risk Measures of Risk. Mathematical Finance 9(3), 1999, 203.
Foellmer, H. and Scheid, A. Stochastic Finance: An Introduction in Discrete Time. De Gryuter, 2011.
Examples
# To be added
a <- rnorm(1000) # Payoffs of random portfolio
HSVaR(a, .95)
Percentile of historical simulation VaR distribution function
Description
Estimates percentiles of historical simulation VaR distribution function, using theory of order statistics, for specified confidence level.
Usage
HSVaRDFPerc(Ra, perc, cl)
Arguments
Ra |
Vector of daily P/L data |
perc |
Desired percentile and is scalar |
cl |
VaR confidence level and is scalar |
Value
Value of percentile of VaR distribution function
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates Percentiles for random standard normal returns and given perc
# and cl
Ra <- rnorm(100)
HSVaRDFPerc(Ra, .75, .95)
Plots historical simulation VaR and ES against confidence level
Description
Function plots the historical simulation VaR and ES of a portfolio against confidence level, for specified range of confidence level and holding period implied by data frequency.
Usage
HSVaRESPlot2DCl(Ra, cl)
Arguments
Ra |
Vector of daily P/L data |
cl |
Vectof of VaR confidence levels |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots historical simulation VaR and ES against confidence level
Ra <- rnorm(100)
cl <- seq(.90, .99, .01)
HSVaRESPlot2DCl(Ra, cl)
Figure of Historical SImulation VaR and histogram of L/P
Description
Plots figure showing the historical simulation VaR and histogram of L/P for specified confidence level and holding period implied by data frequency.
Usage
HSVaRFigure(Ra, cl)
Arguments
Ra |
Vector of profit loss data |
cl |
ES confidence level |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots figure showing VaR and histogram of P/L data
Ra <- rnorm(100)
HSVaRFigure(Ra, .95)
Plots historical simulation VaR against confidence level
Description
Function plots the historical simulation VaR of a portfolio against confidence level, for specified range of confidence level and holding period implied by data frequency.
Usage
HSVaRPlot2DCl(Ra, cl)
Arguments
Ra |
Vector of daily P/L data |
cl |
Vector of VaR confidence levels |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots historical simulation VaR against confidence level
Ra <- rnorm(100)
cl <- seq(.90, .99, .01)
HSVaRPlot2DCl(Ra, cl)
Hill Estimator
Description
Estimates the value of the Hill Estimator for a given specified data set and chosen tail size. Notes: 1) We estimate Hill Estimator by looking at the upper tail. 2) If the specified tail size is such that any included observations are negative, the tail is truncated at the point before observations become negative. 3) The tail size must be a scalar.
Usage
HillEstimator(Ra, tail.size)
Arguments
Ra |
Data set |
tail.size |
Number of observations to be used to estimate the Hill estimator. |
Value
Estimated value of Hill Estimator
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates Hill Estimator of
Ra <- rnorm(15)
HillEstimator(Ra, 10)
Hill Plot
Description
Displays a plot of the Hill Estimator against tail sample size.
Usage
HillPlot(Ra, maximum.tail.size)
Arguments
Ra |
The data set |
maximum.tail.size |
maximum tail size and should be greater than a quarter of the sample size. |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Hill Estimator - Tail Sample Size Plot for random normal dataset
Ra <- rnorm(1000)
HillPlot(Ra, 180)
Hill Quantile Estimator
Description
Estimates value of Hill Quantile Estimator for a specified data set, tail index, in-sample probability and confidence level.
Usage
HillQuantileEstimator(Ra, tail.index, in.sample.prob, cl)
Arguments
Ra |
A data set |
tail.index |
Assumed tail index |
in.sample.prob |
In-sample probability (used as basis for projection) |
cl |
Confidence level |
Value
Value of Hill Quantile Estimator
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Next reference
Examples
# Computes estimates value of hill estimator for a specified data set
Ra <- rnorm(1000)
HillQuantileEstimator(Ra, 40, .5, .9)
VaR of Insurance Portfolio
Description
Generates Monte Carlo VaR for insurance portfolio in Chapter 6.5
Usage
InsuranceVaR(mu, sigma, n, p, theta, deductible, number.trials, cl)
Arguments
mu |
Mean of returns |
sigma |
Volatility of returns |
n |
Number of contracts |
p |
Probability of any loss event |
theta |
Expected profit per contract |
deductible |
Deductible |
number.trials |
Number of simulation trials |
cl |
VaR confidence level |
Value
VaR of the specified portfolio
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates VaR of Insurance portfolio with given parameters
InsuranceVaR(.8, 1.3, 100, .6, 21, 12, 50, .95)
VaR and ES of Insurance Portfolio
Description
Generates Monte Carlo VaR and ES for insurance portfolio.
Usage
InsuranceVaRES(mu, sigma, n, p, theta, deductible, number.trials, cl)
Arguments
mu |
Mean of returns |
sigma |
Volatility of returns |
n |
Number of contracts |
p |
Probability of any loss event |
theta |
Expected profit per contract |
deductible |
Deductible |
number.trials |
Number of simulation trials |
cl |
VaR confidence level |
Value
A list with "VaR" and "ES" of the specified portfolio
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates VaR and ES of Insurance portfolio with given parameters
y<-InsuranceVaRES(.8, 1.3, 100, .6, 21, 12, 50, .95)
Jarque-Bera backtest for normality.
Description
Jarque-Bera (JB) is a backtest to test whether the skewness and kurtosis of a given sample matches that of normal distribution. JB test statistic is defined as
JB=\frac{n}{6}\left(s^2+\frac{(k-3)^2}{4}\right)
where
n
is sample size, s
and k
are coefficients of sample
skewness and kurtosis.
Usage
JarqueBeraBacktest(sample.skewness, sample.kurtosis, n)
Arguments
sample.skewness |
Coefficient of Skewness of the sample |
sample.kurtosis |
Coefficient of Kurtosis of the sample |
n |
Number of observations |
Value
Probability of null hypothesis H0
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Jarque, C. M. and Bera, A. K. A test for normality of observations and regression residuals, International Statistical Review, 55(2): 163-172.
Examples
# JB test statistic for sample with 500 observations with sample
# skewness and kurtosis of -0.075 and 2.888
JarqueBeraBacktest(-0.075,2.888,500)
Plots cumulative density for KS test and computes confidence interval for KS test stat.
Description
Kolmogorov-Smirnov (KS) test statistic is a non parametric test for distribution equality and measures the maximum distance between two cdfs. Formally, the KS test statistic is :
D=\max_i|F(X_i)-\hat{F}(X_i)|
Usage
KSTestStat(number.trials, sample.size, confidence.interval)
Arguments
number.trials |
Number of trials |
sample.size |
Sizes of the trial samples |
confidence.interval |
Confidence interval expressed as a fraction of 1 |
Value
Confidence Interval for KS test stat
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Chakravarti, I. M., Laha, R. G. and Roy, J. Handbook of Methods of #' Applied Statistics, Volume 1, Wiley, 1967.
Examples
# Plots the cdf for KS Test statistic and returns KS confidence interval
# for 100 trials with 1000 sample size and 0.95 confidence interval
KSTestStat(100, 1000, 0.95)
Calculates ES using box kernel approach
Description
The output consists of a scalar ES for specified confidence level.
Usage
KernelESBoxKernel(Ra, cl)
Arguments
Ra |
Profit and Loss data set |
cl |
VaR confidence level |
Value
Scalar VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# VaR for specified confidence level using box kernel approach
Ra <- rnorm(30)
KernelESBoxKernel(Ra, .95)
Calculates ES using Epanechinikov kernel approach
Description
The output consists of a scalar ES for specified confidence level.
Usage
KernelESEpanechinikovKernel(Ra, cl, plot = TRUE)
Arguments
Ra |
Profit and Loss data set |
cl |
ES confidence level |
plot |
Bool, plots cdf if true |
Value
Scalar ES
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# ES for specified confidence level using Epanechinikov kernel approach
Ra <- rnorm(30)
KernelESEpanechinikovKernel(Ra, .95)
Calculates ES using normal kernel approach
Description
The output consists of a scalar ES for specified confidence level.
Usage
KernelESNormalKernel(Ra, cl)
Arguments
Ra |
Profit and Loss data set |
cl |
VaR confidence level |
Value
Scalar VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# ES for specified confidence level using normal kernel approach
Ra <- rnorm(30)
KernelESNormalKernel(Ra, .95)
Calculates ES using triangle kernel approach
Description
The output consists of a scalar ES for specified confidence level.
Usage
KernelESTriangleKernel(Ra, cl)
Arguments
Ra |
Profit and Loss data set |
cl |
VaR confidence level |
Value
Scalar VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# VaR for specified confidence level using triangle kernel approach
Ra <- rnorm(30)
KernelESTriangleKernel(Ra, .95)
Calculates VaR using box kernel approach
Description
The output consists of a scalar VaR for specified confidence level.
Usage
KernelVaRBoxKernel(Ra, cl, plot = TRUE)
Arguments
Ra |
Profit and Loss data set |
cl |
VaR confidence level |
plot |
Bool which indicates whether the graph is plotted or not |
Value
Scalar VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# VaR for specified confidence level using box kernel approach
Ra <- rnorm(30)
KernelVaRBoxKernel(Ra, .95)
Calculates VaR using epanechinikov kernel approach
Description
The output consists of a scalar VaR for specified confidence level.
Usage
KernelVaREpanechinikovKernel(Ra, cl, plot = TRUE)
Arguments
Ra |
Profit and Loss data set |
cl |
VaR confidence level |
plot |
Bool, plots the cdf if true. |
Value
Scalar VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# VaR for specified confidence level using epanechinikov kernel approach
Ra <- rnorm(30)
KernelVaREpanechinikovKernel(Ra, .95)
Calculates VaR using normal kernel approach
Description
The output consists of a scalar VaR for specified confidence level.
Usage
KernelVaRNormalKernel(Ra, cl, plot = TRUE)
Arguments
Ra |
Profit and Loss data set |
cl |
VaR confidence level |
plot |
Bool, plots cdf if true |
Value
Scalar VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# VaR for specified confidence level using normal kernel approach
Ra <- rnorm(30)
KernelVaRNormalKernel(Ra, .95)
Calculates VaR using triangle kernel approach
Description
The output consists of a scalar VaR for specified confidence level.
Usage
KernelVaRTriangleKernel(Ra, cl, plot = TRUE)
Arguments
Ra |
Profit and Loss data set |
cl |
VaR confidence level |
plot |
Bool, plots cdf if true. |
Value
Scalar VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# VaR for specified confidence level using triangle kernel approach
Ra <- rnorm(30)
KernelVaRTriangleKernel(Ra, .95)
Plots cummulative density for Kuiper test and computes confidence interval for Kuiper test stat.
Description
Kuiper test statistic is a non parametric test for distribution equality and is closely related to KS test. Formally, the Kuiper test statistic is :
D*=\max_i\{F(X_i)-\hat{F(x_i)}+\max_i\{\hat{F}(X_i)-F(X_i)\}
Usage
KuiperTestStat(number.trials, sample.size, confidence.interval)
Arguments
number.trials |
Number of trials |
sample.size |
Sizes of the trial samples |
confidence.interval |
Confidence interval expressed as a fraction of 1 |
Value
Confidence Interval for KS test stat
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots the cdf for Kuiper Test statistic and returns Kuiper confidence
# interval for 100 trials with 1000 sample size and 0.95 confidence
# interval.
KuiperTestStat(100, 1000, 0.95)
ES for normally distributed geometric returns
Description
Estimates the ES of a portfolio assuming that geometric returns are normally distributed, for specified confidence level and holding period.
Usage
LogNormalES(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment cl VaR confidence level hp VaR holding period in days |
Value
Matrix of ES whose dimension depends on dimension of hp and cl. If cl and hp are both scalars, the matrix is 1 by 1. If cl is a vector and hp is a scalar, the matrix is row matrix, if cl is a scalar and hp is a vector, the matrix is column matrix and if both cl and hp are vectors, the matrix has dimension length of cl * length of hp.
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes ES given geometric return data
data <- runif(5, min = 0, max = .2)
LogNormalES(returns = data, investment = 5, cl = .95, hp = 90)
# Computes ES given mean and standard deviation of return data
LogNormalES(mu = .012, sigma = .03, investment = 5, cl = .95, hp = 90)
Percentiles of ES distribution function for normally distributed geometric returns
Description
Estimates the percentiles of ES distribution for normally distributed geometric returns, for specified confidence level and holding period using the theory of order statistics.
Usage
LogNormalESDFPerc(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 5 or 7. In case there 5 input arguments, the mean, standard deviation and number of samples is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data n Sample size investment Size of investment perc Desired percentile cl ES confidence level and must be a scalar hp ES holding period and must be a a scalar |
Value
Percentiles of ES distribution function
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates Percentiles of ES distribution
data <- runif(5, min = 0, max = .2)
LogNormalESDFPerc(returns = data, investment = 5, perc = .7, cl = .95, hp = 60)
# Estimates Percentiles given mean, standard deviation and number of sambles of return data
LogNormalESDFPerc(mu = .012, sigma = .03, n= 10, investment = 5, perc = .8, cl = .99, hp = 40)
Figure of lognormal VaR and ES and pdf against L/P
Description
Gives figure showing the VaR and ES and probability distribution function against L/P of a portfolio assuming geometric returns are normally distributed, for specified confidence level and holding period.
Usage
LogNormalESFigure(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment cl VaR confidence level and should be scalar hp VaR holding period in days and should be scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots lognormal VaR, ES and pdf against L/P data for given returns data
data <- runif(5, min = 0, max = .2)
LogNormalESFigure(returns = data, investment = 5, cl = .95, hp = 90)
# Plots lognormal VaR, ES and pdf against L/P data with given parameters
LogNormalESFigure(mu = .012, sigma = .03, investment = 5, cl = .95, hp = 90)
Plots log normal ES against confidence level
Description
Plots the ES of a portfolio against confidence level assuming that geometric returns are normally distributed, for specified confidence level and holding period.
Usage
LogNormalESPlot2DCL(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment cl ES confidence level and must be a vector hp ES holding period and must be a scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots ES against confidence level
data <- runif(5, min = 0, max = .2)
LogNormalESPlot2DCL(returns = data, investment = 5,
cl = seq(.9,.99,.01), hp = 60)
# Plots ES against confidence level
LogNormalESPlot2DCL(mu = .012, sigma = .03, investment = 5,
cl = seq(.9,.99,.01), hp = 40)
Plots log normal ES against holding period
Description
Plots the ES of a portfolio against holding period assuming that geometric returns are normal distributed, for specified confidence level and holding period.
Usage
LogNormalESPlot2DHP(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment cl ES confidence level and must be a scalar hp ES holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes ES given geometric return data
data <- runif(5, min = 0, max = .2)
LogNormalESPlot2DHP(returns = data, investment = 5, cl = .95, hp = 60:90)
# Computes v given mean and standard deviation of return data
LogNormalESPlot2DHP(mu = .012, sigma = .03, investment = 5, cl = .99, hp = 40:80)
Plots log normal ES against confidence level and holding period
Description
Plots the ES of a portfolio against confidence level and holding period assuming that geometric returns are normally distributed, for specified confidence level and holding period.
Usage
LogNormalESPlot3D(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data cl VaR confidence level and must be a vector hp VaR holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots VaR against confidene level given geometric return data
data <- runif(5, min = 0, max = .2)
LogNormalESPlot3D(returns = data, investment = 5, cl = seq(.9,.99,.01), hp = 1:100)
# Computes VaR against confidence level given mean and standard deviation of return data
LogNormalESPlot3D(mu = .012, sigma = .03, investment = 5, cl = seq(.9,.99,.01), hp = 1:100)
VaR for normally distributed geometric returns
Description
Estimates the VaR of a portfolio assuming that geometric returns are normally distributed, for specified confidence level and holding period.
Usage
LogNormalVaR(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment cl VaR confidence level hp VaR holding period in days |
Value
Matrix of VaR whose dimension depends on dimension of hp and cl. If cl and hp are both scalars, the matrix is 1 by 1. If cl is a vector and hp is a scalar, the matrix is row matrix, if cl is a scalar and hp is a vector, the matrix is column matrix and if both cl and hp are vectors, the matrix has dimension length of cl * length of hp.
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes VaR given geometric return data
data <- runif(5, min = 0, max = .2)
LogNormalVaR(returns = data, investment = 5, cl = .95, hp = 90)
# Computes VaR given mean and standard deviation of return data
LogNormalVaR(mu = .012, sigma = .03, investment = 5, cl = .95, hp = 90)
Percentiles of VaR distribution function for normally distributed geometric returns
Description
Estimates the percentile of VaR distribution function for normally distributed geometric returns, using the theory of order statistics.
Usage
LogNormalVaRDFPerc(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 5 or 7. In case there 5 input arguments, the mean, standard deviation and number of observations of data are computed from returns data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data n Sample size investment Size of investment perc Desired percentile cl VaR confidence level and must be a scalar hp VaR holding period and must be a a scalar Percentiles of VaR distribution function and is scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates Percentiles of VaR distribution
data <- runif(5, min = 0, max = .2)
LogNormalVaRDFPerc(returns = data, investment = 5, perc = .7, cl = .95, hp = 60)
# Computes v given mean and standard deviation of return data
LogNormalVaRDFPerc(mu = .012, sigma = .03, n= 10, investment = 5, perc = .8, cl = .99, hp = 40)
Plots log normal VaR and ETL against confidence level
Description
Plots the VaR and ETL of a portfolio against confidence level assuming that geometric returns are normally distributed, for specified confidence level and holding period.
Usage
LogNormalVaRETLPlot2DCL(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there are 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment cl VaR confidence level and must be a vector hp VaR holding period and must be a scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots VaR and ETL against confidene level given geometric return data
data <- runif(5, min = 0, max = .2)
LogNormalVaRETLPlot2DCL(returns = data, investment = 5, cl = seq(.85,.99,.01), hp = 60)
# Computes VaR against confidence level given mean and standard deviation of return data
LogNormalVaRETLPlot2DCL(mu = .012, sigma = .03, investment = 5, cl = seq(.85,.99,.01), hp = 40)
Figure of lognormal VaR and pdf against L/P
Description
Gives figure showing the VaR and probability distribution function against L/P of a portfolio assuming geometric returns are normally distributed, for specified confidence level and holding period.
Usage
LogNormalVaRFigure(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment cl VaR confidence level and should be scalar hp VaR holding period in days and should be scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots lognormal VaR and pdf against L/P data for given returns data
data <- runif(5, min = 0, max = .2)
LogNormalVaRFigure(returns = data, investment = 5, cl = .95, hp = 90)
# Plots lognormal VaR and pdf against L/P data with given parameters
LogNormalVaRFigure(mu = .012, sigma = .03, investment = 5, cl = .95, hp = 90)
Plots log normal VaR against confidence level
Description
Plots the VaR of a portfolio against confidence level assuming that geometric returns are normally distributed, for specified confidence level and holding period.
Usage
LogNormalVaRPlot2DCL(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there are 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment cl VaR confidence level and must be a vector hp VaR holding period and must be a scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots VaR against confidene level given geometric return data
data <- runif(5, min = 0, max = .2)
LogNormalVaRPlot2DCL(returns = data, investment = 5, cl = seq(.85,.99,.01), hp = 60)
# Computes VaR against confidence level given mean and standard deviation of return data
LogNormalVaRPlot2DCL(mu = .012, sigma = .03, investment = 5, cl = seq(.85,.99,.01), hp = 40)
Plots log normal VaR against holding period
Description
Plots the VaR of a portfolio against holding period assuming that geometric returns are normal distributed, for specified confidence level and holding period.
Usage
LogNormalVaRPlot2DHP(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment cl VaR confidence level and must be a scalar hp VaR holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes VaR given geometric return data
data <- runif(5, min = 0, max = .2)
LogNormalVaRPlot2DHP(returns = data, investment = 5, cl = .95, hp = 60:90)
# Computes VaR given mean and standard deviation of return data
LogNormalVaRPlot2DHP(mu = .012, sigma = .03, investment = 5, cl = .99, hp = 40:80)
Plots log normal VaR against confidence level and holding period
Description
Plots the VaR of a portfolio against confidence level and holding period assuming that geometric returns are normal distributed, for specified confidence level and holding period.
Usage
LogNormalVaRPlot3D(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment cl VaR confidence level and must be a vector hp VaR holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots VaR against confidene level given geometric return data
data <- rnorm(5, .09, .03)
LogNormalVaRPlot3D(returns = data, investment = 5, cl = seq(.9,.99,.01), hp = 1:100)
# Computes VaR against confidence level given mean and standard deviation of return data
LogNormalVaRPlot3D(mu = .012, sigma = .03, investment = 5, cl = seq(.9,.99,.01), hp = 1:100)
ES for t distributed geometric returns
Description
Estimates the ES of a portfolio assuming that geometric returns are Student-t distributed, for specified confidence level and holding period.
Usage
LogtES(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 5 or 6. In case there 5 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment df Number of degrees of freedom in the t distribution cl VaR confidence level hp VaR holding period |
Value
Matrix of ES whose dimension depends on dimension of hp and cl. If cl and hp are both scalars, the matrix is 1 by 1. If cl is a vector and hp is a scalar, the matrix is row matrix, if cl is a scalar and hp is a vector, the matrix is column matrix and if both cl and hp are vectors, the matrix has dimension length of cl * length of hp.
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes ES given geometric return data
data <- runif(5, min = 0, max = .2)
LogtES(returns = data, investment = 5, df = 6, cl = .95, hp = 90)
# Computes ES given mean and standard deviation of return data
LogtES(mu = .012, sigma = .03, investment = 5, df = 6, cl = .95, hp = 90)
Percentiles of ES distribution function for Student-t
Description
Plots the ES of a portfolio against confidence level assuming that geometric returns are Student t distributed, for specified confidence level and holding period.
Usage
LogtESDFPerc(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 6 or 8. In case there 6 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data n Sample size investment Size of investment perc Desired percentile df Number of degrees of freedom in the t distribution cl ES confidence level and must be a scalar hp ES holding period and must be a a scalar |
Value
Percentiles of ES distribution function
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates Percentiles of ES distribution
data <- runif(5, min = 0, max = .2)
LogtESDFPerc(returns = data, investment = 5, perc = .7, df = 6, cl = .95, hp = 60)
# Computes v given mean and standard deviation of return data
LogtESDFPerc(mu = .012, sigma = .03, n= 10, investment = 5, perc = .8, df = 6, cl = .99, hp = 40)
Plots log-t ES against confidence level
Description
Plots the ES of a portfolio against confidence level assuming that geometric returns are Student t distributed, for specified confidence level and holding period.
Usage
LogtESPlot2DCL(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 5 or 6. In case there 5 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment df Number of degrees of freedom in the t distribution cl ES confidence level and must be a vector hp ES holding period and must be a scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes ES given geometric return data
data <- runif(5, min = 0, max = .2)
LogtESPlot2DCL(returns = data, investment = 5, df = 6, cl = seq(.9,.99,.01), hp = 60)
# Computes v given mean and standard deviation of return data
LogtESPlot2DCL(mu = .012, sigma = .03, investment = 5, df = 6, cl = seq(.9,.99,.01), hp = 40)
Plots log-t ES against holding period
Description
Plots the ES of a portfolio against holding period assuming that geometric returns are Student t distributed, for specified confidence level and holding period.
Usage
LogtESPlot2DHP(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 5 or 6. In case there 5 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment df Number of degrees of freedom in the t distribution cl ES confidence level and must be a scalar hp ES holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes ES given geometric return data
data <- runif(5, min = 0, max = .2)
LogtESPlot2DHP(returns = data, investment = 5, df = 6, cl = .95, hp = 60:90)
# Computes v given mean and standard deviation of return data
LogtESPlot2DHP(mu = .012, sigma = .03, investment = 5, df = 6, cl = .99, hp = 40:80)
Plots log-t ES against confidence level and holding period
Description
Plots the ES of a portfolio against confidence level and holding period assuming that geometric returns are Student-t distributed, for specified confidence level and holding period.
Usage
LogtESPlot3D(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 5 or 6. In case there 5 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment df Number of degrees of freedom in the t distribution cl VaR confidence level and must be a vector hp VaR holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots ES against confidene level given geometric return data
data <- rnorm(5, .09, .03)
LogtESPlot3D(returns = data, investment = 5, df = 6, cl = seq(.9,.99,.01), hp = 1:100)
# Computes ES against confidence level given mean and standard deviation of return data
LogtESPlot3D(mu = .012, sigma = .03, investment = 5, df = 6, cl = seq(.9,.99,.01), hp = 1:100)
VaR for t distributed geometric returns
Description
Estimates the VaR of a portfolio assuming that geometric returns are Student t distributed, for specified confidence level and holding period.
Usage
LogtVaR(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 5 or 6. In case there 5 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment df Number of degrees of freedom in the t distribution cl VaR confidence level hp VaR holding period |
Value
Matrix of VaRs whose dimension depends on dimension of hp and cl. If cl and hp are both scalars, the matrix is 1 by 1. If cl is a vector and hp is a scalar, the matrix is row matrix, if cl is a scalar and hp is a vector, the matrix is column matrix and if both cl and hp are vectors, the matrix has dimension length of cl * length of hp.
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes VaR given geometric return data
data <- runif(5, min = 0, max = .2)
LogtVaR(returns = data, investment = 5, df = 6, cl = .95, hp = 90)
# Computes VaR given mean and standard deviation of return data
LogtVaR(mu = .012, sigma = .03, investment = 5, df = 6, cl = .95, hp = 90)
Percentiles of VaR distribution function for Student-t
Description
Plots the VaR of a portfolio against confidence level assuming that geometric returns are Student t distributed, for specified confidence level and holding period.
Usage
LogtVaRDFPerc(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 6 or 8. In case there 6 input arguments, the mean, standard deviation and number of observations of the data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data n Sample size investment Size of investment perc Desired percentile df Number of degrees of freedom in the t distribution cl VaR confidence level and must be a scalar hp VaR holding period and must be a a scalar Percentiles of VaR distribution function |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates Percentiles of VaR distribution
data <- runif(5, min = 0, max = .2)
LogtVaRDFPerc(returns = data, investment = 5, perc = .7,
df = 6, cl = .95, hp = 60)
# Computes v given mean and standard deviation of return data
LogtVaRDFPerc(mu = .012, sigma = .03, n= 10, investment = 5,
perc = .8, df = 6, cl = .99, hp = 40)
Plots log-t VaR against confidence level
Description
Plots the VaR of a portfolio against confidence level assuming that geometric returns are Student-t distributed, for specified confidence level and holding period.
Usage
LogtVaRPlot2DCL(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 5 or 6. In case there 5 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment df Number of degrees of freedom in the t distribution cl VaR confidence level and must be a vector hp VaR holding period and must be a scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots VaR against confidene level given geometric return data
data <- runif(5, min = 0, max = .2)
LogtVaRPlot2DCL(returns = data, investment = 5, df = 6, cl = seq(.85,.99,.01), hp = 60)
# Computes VaR against confidence level given mean and standard deviation of return data
LogtVaRPlot2DCL(mu = .012, sigma = .03, investment = 5, df = 6, cl = seq(.85,.99,.01), hp = 40)
Plots log-t VaR against holding period
Description
Plots the VaR of a portfolio against holding period assuming that geometric returns are Student t distributed, for specified confidence level and holding period.
Usage
LogtVaRPlot2DHP(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 5 or 6. In case there 5 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment df Number of degrees of freedom in the t distribution cl VaR confidence level and must be a scalar hp VaR holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes VaR given geometric return data
data <- runif(5, min = 0, max = .2)
LogtVaRPlot2DHP(returns = data, investment = 5, df = 6, cl = .95, hp = 60:90)
# Computes VaR given mean and standard deviation of return data
LogtVaRPlot2DHP(mu = .012, sigma = .03, investment = 5, df = 6, cl = .99, hp = 40:80)
Plots log-t VaR against confidence level and holding period
Description
Plots the VaR of a portfolio against confidence level and holding period assuming that geometric returns are Student-t distributed, for specified confidence level and holding period.
Usage
LogtVaRPlot3D(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 5 or 6. In case there 5 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data investment Size of investment df Number of degrees of freedom in the t distribution cl VaR confidence level and must be a vector hp VaR holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots VaR against confidene level given geometric return data
data <- runif(5, min = 0, max = .2)
LogtVaRPlot3D(returns = data, investment = 5, df = 6, cl = seq(.9,.99,.01), hp = 1:100)
# Computes VaR against confidence level given mean and standard deviation of return data
LogtVaRPlot3D(mu = .012, sigma = .03, investment = 5, df = 6, cl = seq(.9,.99,.01), hp = 1:100)
Derives VaR of a long Black Scholes call option
Description
Function derives the VaR of a long Black Scholes call for specified confidence level and holding period, using analytical solution.
Usage
LongBlackScholesCallVaR(stockPrice, strike, r, mu, sigma, maturity, cl, hp)
Arguments
stockPrice |
Stock price of underlying stock |
strike |
Strike price of the option |
r |
Risk-free rate and is annualised |
mu |
Mean return |
sigma |
Volatility of the underlying stock |
maturity |
Term to maturity and is expressed in days |
cl |
Confidence level and is scalar |
hp |
Holding period and is scalar and is expressed in days |
Value
Price of European Call Option
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Hull, John C.. Options, Futures, and Other Derivatives. 4th ed., Upper Saddle River, NJ: Prentice Hall, 200, ch. 11.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
Examples
# Estimates the price of an American Put
LongBlackScholesCallVaR(27.2, 25, .03, .12, .2, 60, .95, 40)
Derives VaR of a long Black Scholes put option
Description
Function derives the VaR of a long Black Scholes put for specified confidence level and holding period, using analytical solution.
Usage
LongBlackScholesPutVaR(stockPrice, strike, r, mu, sigma, maturity, cl, hp)
Arguments
stockPrice |
Stock price of underlying stock |
strike |
Strike price of the option |
r |
Risk-free rate and is annualised |
mu |
Mean return |
sigma |
Volatility of the underlying stock |
maturity |
Term to maturity and is expressed in days |
cl |
Confidence level and is scalar |
hp |
Holding period and is scalar and is expressed in days |
Value
Price of European put Option
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Hull, John C.. Options, Futures, and Other Derivatives. 4th ed., Upper Saddle River, NJ: Prentice Hall, 200, ch. 11.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
Examples
# Estimates the price of an American Put
LongBlackScholesPutVaR(27.2, 25, .03, .12, .2, 60, .95, 40)
First (binomial) Lopez forecast evaluation backtest score measure
Description
Derives the first Lopez (i.e. binomial) forecast evaluation score for a VaR risk measurement model.
Usage
LopezBacktest(Ra, Rb, cl)
Arguments
Ra |
Vector of portfolio of profit loss distribution |
Rb |
Vector of corresponding VaR forecasts |
cl |
VaR confidence level |
Value
Something
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Lopez, J. A. Methods for Evaluating Value-at-Risk Estimates. Federal Reserve Bank of New York Economic Policy Review, 1998, p. 121.
Lopez, J. A. Regulatory Evaluations of Value-at-Risk Models. Journal of Risk 1999, 37-64.
Examples
# Has to be modified with appropriate data:
# LopezBacktest for given parameters
a <- rnorm(1*100)
b <- abs(rnorm(1*100))+2
LopezBacktest(a, b, 0.95)
Mean Excess Function Plot
Description
Plots mean-excess function values of the data set.
Usage
MEFPlot(Ra)
Arguments
Ra |
Vector data |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots mean-excess function values
Ra <- rnorm(1000)
MEFPlot(Ra)
ES for normally distributed P/L
Description
Estimates the ES of a portfolio assuming that P/L is normally distributed, for specified confidence level and holding period.
Usage
NormalES(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data along with the remaining arguments. Accordingly, number of input arguments is either 3 or 4. In case there 3 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data cl VaR confidence level hp VaR holding period in days |
Value
Matrix of ES whose dimension depends on dimension of hp and cl. If cl and hp are both scalars, the matrix is 1 by 1. If cl is a vector and hp is a scalar, the matrix is row matrix, if cl is a scalar and hp is a vector, the matrix is column matrix and if both cl and hp are vectors, the matrix has dimension length of cl * length of hp.
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes VaR given P/L
data <- runif(5, min = 0, max = .2)
NormalES(returns = data, cl = .95, hp = 90)
# Computes VaR given mean and standard deviation of P/L data
NormalES(mu = .012, sigma = .03, cl = .95, hp = 90)
Generates Monte Carlo 95% Confidence Intervals for normal ES
Description
Generates 95% confidence intervals for normal ES using Monte Carlo simulation
Usage
NormalESConfidenceInterval(mu, sigma, number.trials, sample.size, cl, hp)
Arguments
mu |
Mean of the P/L process |
sigma |
Standard deviation of the P/L process |
number.trials |
Number of trials used in the simulations |
sample.size |
Sample drawn in each trial |
cl |
Confidence Level |
hp |
Holding Period |
Value
95% confidence intervals for normal ES
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Generates 95\% confidence intervals for normal ES for given parameters
NormalESConfidenceInterval(0, .5, 20, 20, .95, 90)
Percentiles of ES distribution function for normally distributed P/L data
Description
Estimates the percentiles of ES distribution for normally distributed P/L data, for specified confidence level and holding period using the theory of order statistics.
Usage
NormalESDFPerc(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 6. In case there 4 input arguments, the mean, standard deviation and number of samples is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data n Sample size perc Desired percentile cl ES confidence level and must be a scalar hp ES holding period and must be a a scalar |
Value
Percentiles of ES distribution function
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates Percentiles of ES distribution
data <- runif(5, min = 0, max = .2)
NormalESDFPerc(returns = data, perc = .7, cl = .95, hp = 60)
# Estimates Percentiles given mean, standard deviation and number of sambles of return data
NormalESDFPerc(mu = .012, sigma = .03, n= 10, perc = .8, cl = .99, hp = 40)
Figure of normal VaR and ES and pdf against L/P
Description
Gives figure showing the VaR and ES and probability distribution function against L/P of a portfolio assuming geometric returns are normally distributed, for specified confidence level and holding period.
Usage
NormalESFigure(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 3 or 4. In case there 3 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data cl VaR confidence level and should be scalar hp VaR holding period in days and should be scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots lognormal VaR, ES and pdf against L/P data for given returns data
data <- runif(5, min = 0, max = .2)
NormalESFigure(returns = data, cl = .95, hp = 90)
# Plots lognormal VaR, ES and pdf against L/P data with given parameters
NormalESFigure(mu = .012, sigma = .03, cl = .95, hp = 90)
Hotspots for normal ES
Description
Estimates the ES hotspots (or vector of incremental ESs) for a portfolio assuming individual asset returns are normally distributed, for specified confidence level and holding period.
Usage
NormalESHotspots(vc.matrix, mu, positions, cl, hp)
Arguments
vc.matrix |
Variance covariance matrix for returns |
mu |
Vector of expected position returns |
positions |
Vector of positions |
cl |
Confidence level and is scalar |
hp |
Holding period and is scalar |
Value
Hotspots for normal ES
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Hotspots for ES for randomly generated portfolio
vc.matrix <- matrix(rnorm(16),4,4)
mu <- rnorm(4,.08,.04)
positions <- c(5,2,6,10)
cl <- .95
hp <- 280
NormalESHotspots(vc.matrix, mu, positions, cl, hp)
Plots normal ES against confidence level
Description
Plots the ES of a portfolio against confidence level assuming that P/L are normally distributed, for specified confidence level and holding period.
Usage
NormalESPlot2DCL(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 3 or 4. In case there 3 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data cl ES confidence level and must be a vector hp ES holding period and must be a scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots ES against confidence level
data <- runif(5, min = 0, max = .2)
NormalESPlot2DCL(returns = data, cl = seq(.9,.99,.01), hp = 60)
# Plots ES against confidence level
NormalESPlot2DCL(mu = .012, sigma = .03, cl = seq(.9,.99,.01), hp = 40)
Plots normal ES against holding period
Description
Plots the ES of a portfolio against holding period assuming that P/L distribution is normally distributed, for specified confidence level and holding period.
Usage
NormalESPlot2DHP(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 3 or 4. In case there 3 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data cl ES confidence level and must be a scalar hp ES holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes ES given geometric return data
data <- runif(5, min = 0, max = .2)
NormalESPlot2DHP(returns = data, cl = .95, hp = 60:90)
# Computes v given mean and standard deviation of return data
NormalESPlot2DHP(mu = .012, sigma = .03, cl = .99, hp = 40:80)
Plots normal ES against confidence level and holding period
Description
Plots the ES of a portfolio against confidence level and holding period assuming that P/L is normally distributed, for specified ranges of confidence level and holding period.
Usage
NormalESPlot3D(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 3 or 4. In case there 3 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data cl VaR confidence level and must be a vector hp VaR holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots VaR against confidene level given geometric return data
data <- runif(5, min = 0, max = .2)
NormalESPlot3D(returns = data, cl = seq(.9,.99,.01), hp = 1:100)
# Computes VaR against confidence level given mean and standard deviation of return data
NormalESPlot3D(mu = .012, sigma = .03, cl = seq(.9,.99,.01), hp = 1:100)
Normal Quantile Quantile Plot
Description
Produces an emperical QQ-Plot of the quantiles of the data set 'Ra' versus the quantiles of a normal distribution. The purpose of the quantile-quantile plot is to determine whether the sample in 'Ra' is drawn from a normal (i.e., Gaussian) distribution.
Usage
NormalQQPlot(Ra)
Arguments
Ra |
Vector data set |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Normal QQ Plot for randomly generated standard normal data
Ra <- rnorm(100)
NormalQQPlot(Ra)
Standard error of normal quantile estimate
Description
Estimates standard error of normal quantile estimate
Usage
NormalQuantileStandardError(prob, n, mu, sigma, bin.size)
Arguments
prob |
Tail probability. Can be a vector or scalar |
n |
Sample size |
mu |
Mean of the normal distribution |
sigma |
Standard deviation of the distribution |
bin.size |
Bin size. It is optional parameter with default value 1 |
Value
Vector or scalar depending on whether the probability is a vector or scalar
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates standard error of normal quantile estimate
NormalQuantileStandardError(.8, 100, 0, .5, 3)
Estimates the spectral risk measure of a portfolio
Description
Function estimates the spectral risk measure of a portfolio assuming losses are normally distributed, assuming exponential weighting function with specified gamma.
Usage
NormalSpectralRiskMeasure(mu, sigma, gamma, number.of.slices)
Arguments
mu |
Mean losses |
sigma |
Standard deviation of losses |
gamma |
Gamma parameter in exponential risk aversion |
number.of.slices |
Number of slices into which density function is divided |
Value
Estimated spectral risk measure
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Generates 95% confidence intervals for normal VaR for given parameters
NormalSpectralRiskMeasure(0, .5, .8, 20)
VaR for normally distributed P/L
Description
Estimates the VaR of a portfolio assuming that P/L is normally distributed, for specified confidence level and holding period.
Usage
NormalVaR(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data along with the remaining arguments. Accordingly, number of input arguments is either 3 or 4. In case there 3 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data cl VaR confidence level hp VaR holding period in days |
Value
Matrix of VaR whose dimension depends on dimension of hp and cl. If cl and hp are both scalars, the matrix is 1 by 1. If cl is a vector and hp is a scalar, the matrix is row matrix, if cl is a scalar and hp is a vector, the matrix is column matrix and if both cl and hp are vectors, the matrix has dimension length of cl * length of hp.
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes VaR given geometric return data
data <- runif(5, min = 0, max = .2)
NormalVaR(returns = data, cl = .95, hp = 90)
# Computes VaR given mean and standard deviation of return data
NormalVaR(mu = .012, sigma = .03, cl = .95, hp = 90)
Generates Monte Carlo 95% Confidence Intervals for normal VaR
Description
Generates 95% confidence intervals for normal VaR using Monte Carlo simulation
Usage
NormalVaRConfidenceInterval(mu, sigma, number.trials, sample.size, cl, hp)
Arguments
mu |
Mean of the P/L process |
sigma |
Standard deviation of the P/L process |
number.trials |
Number of trials used in the simulations |
sample.size |
Sample drawn in each trial |
cl |
Confidence Level |
hp |
Holding Period |
Value
95% confidence intervals for normal VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Generates 95\% confidence intervals for normal VaR for given parameters
NormalVaRConfidenceInterval(0, .5, 20, 15, .95, 90)
Percentiles of VaR distribution function for normally distributed P/L
Description
Estimates the percentile of VaR distribution function for normally distributed P/L, using the theory of order statistics.
Usage
NormalVaRDFPerc(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 6. In case there 4 input arguments, the mean, standard deviation and number of observations of data are computed from returns data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data n Sample size perc Desired percentile cl VaR confidence level and must be a scalar hp VaR holding period and must be a a scalar |
Value
Percentiles of VaR distribution function and is scalar
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates Percentiles of VaR distribution
data <- runif(5, min = 0, max = .2)
NormalVaRDFPerc(returns = data, perc = .7, cl = .95, hp = 60)
# Estimates Percentiles of VaR distribution
NormalVaRDFPerc(mu = .012, sigma = .03, n= 10, perc = .8, cl = .99, hp = 40)
Figure of normal VaR and pdf against L/P
Description
Gives figure showing the VaR and probability distribution function against L/P of a portfolio assuming P/L are normally distributed, for specified confidence level and holding period.
Usage
NormalVaRFigure(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 3 or 4. In case there 3 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data cl VaR confidence level and should be scalar hp VaR holding period in days and should be scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots normal VaR and pdf against L/P data for given returns data
data <- runif(5, min = 0, max = .2)
NormalVaRFigure(returns = data, cl = .95, hp = 90)
# Plots normal VaR and pdf against L/P data with given parameters
NormalVaRFigure(mu = .012, sigma = .03, cl = .95, hp = 90)
Hotspots for normal VaR
Description
Estimates the VaR hotspots (or vector of incremental VaRs) for a portfolio assuming individual asset returns are normally distributed, for specified confidence level and holding period.
Usage
NormalVaRHotspots(vc.matrix, mu, positions, cl, hp)
Arguments
vc.matrix |
Variance covariance matrix for returns |
mu |
Vector of expected position returns |
positions |
Vector of positions |
cl |
Confidence level and is scalar |
hp |
Holding period and is scalar |
Value
Hotspots for normal VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Hotspots for ES for randomly generated portfolio
vc.matrix <- matrix(rnorm(16),4,4)
mu <- rnorm(4,.08,.04)
positions <- c(5,2,6,10)
cl <- .95
hp <- 280
NormalVaRHotspots(vc.matrix, mu, positions, cl, hp)
Plots normal VaR against confidence level
Description
Plots the VaR of a portfolio against confidence level assuming that P/L are normally distributed, for specified confidence level and holding period.
Usage
NormalVaRPlot2DCL(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 3 or 4. In case there are 3 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data cl VaR confidence level and must be a vector hp VaR holding period and must be a scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots VaR against confidene level given P/L data
data <- runif(5, min = 0, max = .2)
NormalVaRPlot2DCL(returns = data, cl = seq(.85,.99,.01), hp = 60)
# Computes VaR against confidence level given mean and standard deviation of return data
NormalVaRPlot2DCL(mu = .012, sigma = .03, cl = seq(.85,.99,.01), hp = 40)
Plots normal VaR against holding period
Description
Plots the VaR of a portfolio against holding period assuming that P/L are normally distributed, for specified confidence level and holding period.
Usage
NormalVaRPlot2DHP(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 3 or 4. In case there 3 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data cl VaR confidence level and must be a scalar hp VaR holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes VaR given P/L data
data <- runif(5, min = 0, max = .2)
NormalVaRPlot2DHP(returns = data, cl = .95, hp = 60:90)
# Computes VaR given mean and standard deviation of P/L data
NormalVaRPlot2DHP(mu = .012, sigma = .03, cl = .99, hp = 40:80)
Plots normal VaR in 3D against confidence level and holding period
Description
Plots the VaR of a portfolio against confidence level and holding period assuming that P/L are normally distributed, for specified confidence level and holding period.
Usage
NormalVaRPlot3D(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 3 or 4. In case there 3 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data cl VaR confidence level and must be a vector hp VaR holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots VaR against confidene level given geometric return data
data <- rnorm(5, .07, .03)
NormalVaRPlot3D(returns = data, cl = seq(.9,.99,.01), hp = 1:100)
# Computes VaR against confidence level given mean and standard deviation of return data
NormalVaRPlot3D(mu = .012, sigma = .03, cl = seq(.9,.99,.01), hp = 1:100)
Estimates ES by principal components analysis
Description
Estimates the ES of a multi position portfolio by principal components analysis, using chosen number of principal components and a specified confidence level or range of confidence levels.
Usage
PCAES(Ra, position.data, number.of.principal.components, cl)
Arguments
Ra |
Matrix return data set where each row is interpreted as a set of daily observations, and each column as the returns to each position in a portfolio |
position.data |
Position-size vector, giving amount invested in each position |
number.of.principal.components |
Chosen number of principal components |
cl |
Chosen confidence level |
Value
ES
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes PCA ES
Ra <- matrix(rnorm(4*6),4,6)
position.data <- rnorm(6)
PCAES(Ra, position.data, 2, .95)
ES plot
Description
Estimates ES plot using principal components analysis
Usage
PCAESPlot(Ra, position.data)
Arguments
Ra |
Matrix return data set where each row is interpreted as a set of daily observations, and each column as the returns to each position in a portfolio |
position.data |
Position-size vector, giving amount invested in each position |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes PCA ES
Ra <- matrix(rnorm(15*20),15,20)
position.data <- rnorm(20)
PCAESPlot(Ra, position.data)
Estimates VaR plot using principal components analysis
Description
Estimates VaR plot using principal components analysis
Usage
PCAPrelim(Ra)
Arguments
Ra |
Matrix return data set where each row is interpreted as a set of daily observations, and each column as the returns to each position in a portfolio position |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes PCA Prelim
# This code was based on Dowd's code and similar to Dowd's code,
# it is inconsistent for non-scalar data (Ra).
library(MASS)
Ra <- .15
PCAPrelim(Ra)
Estimates VaR by principal components analysis
Description
Estimates the VaR of a multi position portfolio by principal components analysis, using chosen number of principal components and a specified confidence level or range of confidence levels.
Usage
PCAVaR(Ra, position.data, number.of.principal.components, cl)
Arguments
Ra |
Matrix return data set where each row is interpreted as a set of daily observations, and each column as the returns to each position in a portfolio |
position.data |
Position-size vector, giving amount invested in each position |
number.of.principal.components |
Chosen number of principal components |
cl |
Chosen confidence level |
Value
VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes PCA VaR
Ra <- matrix(rnorm(4*6),4,6)
position.data <- rnorm(6)
PCAVaR(Ra, position.data, 2, .95)
VaR plot
Description
Estimates VaR plot using principal components analysis
Usage
PCAVaRPlot(Ra, position.data)
Arguments
Ra |
Matrix return data set where each row is interpreted as a set of daily observations, and each column as the returns to each position in a portfolio |
position.data |
Position-size vector, giving amount invested in each position |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes PCA VaR
Ra <- matrix(rnorm(15*20),15,20)
position.data <- rnorm(20)
PCAVaRPlot(Ra, position.data)
Pickands Estimator
Description
Estimates the Value of Pickands Estimator for a specified data set and chosen tail size. Notes: (1) We estimate the Pickands Estimator by looking at the upper tail. (2) The tail size must be less than one quarter of the total sample size. (3) The tail size must be a scalar.
Usage
PickandsEstimator(Ra, tail.size)
Arguments
Ra |
A data set |
tail.size |
Number of observations to be used to estimate the Pickands estimator |
Value
Value of Pickands estimator
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes estimated Pickands estimator for randomly generated data.
Ra <- rnorm(1000)
PickandsEstimator(Ra, 40)
Pickand Estimator - Tail Sample Size Plot
Description
Displays a plot of the Pickands Estimator against Tail Sample Size.
Usage
PickandsPlot(Ra, maximum.tail.size)
Arguments
Ra |
The data set |
maximum.tail.size |
maximum tail size and should be greater than a quarter of the sample size. |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Pickand - Sample Tail Size Plot for random standard normal data
Ra <- rnorm(1000)
PickandsPlot(Ra, 40)
Bivariate Product Copule VaR
Description
Derives VaR using bivariate Product or logistic copula with specified inputs for normal marginals.
Usage
ProductCopulaVaR(mu1, mu2, sigma1, sigma2, cl)
Arguments
mu1 |
Mean of Profit/Loss on first position |
mu2 |
Mean of Profit/Loss on second position |
sigma1 |
Standard Deviation of Profit/Loss on first position |
sigma2 |
Standard Deviation of Profit/Loss on second position |
cl |
VaR onfidece level |
Value
Copula based VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Dowd, K. and Fackler, P. Estimating VaR with copulas. Financial Engineering News, 2004.
Examples
# VaR using bivariate Product for X and Y with given parameters:
ProductCopulaVaR(.9, 2.1, 1.2, 1.5, .95)
Derives VaR of a short Black Scholes call option
Description
Function derives the VaR of a short Black Scholes call for specified confidence level and holding period, using analytical solution.
Usage
ShortBlackScholesCallVaR(stockPrice, strike, r, mu, sigma, maturity, cl, hp)
Arguments
stockPrice |
Stock price of underlying stock |
strike |
Strike price of the option |
r |
Risk-free rate and is annualised |
mu |
Mean return |
sigma |
Volatility of the underlying stock |
maturity |
Term to maturity and is expressed in days |
cl |
Confidence level and is scalar |
hp |
Holding period and is scalar and is expressed in days |
Value
Price of European Call Option
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Hull, John C.. Options, Futures, and Other Derivatives. 4th ed., Upper Saddle River, NJ: Prentice Hall, 200, ch. 11.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
Examples
# Estimates the price of an American Put
ShortBlackScholesCallVaR(27.2, 25, .03, .12, .2, 60, .95, 40)
Derives VaR of a short Black Scholes put option
Description
Function derives the VaR of a Short Black Scholes put for specified confidence level and holding period, using analytical solution.
Usage
ShortBlackScholesPutVaR(stockPrice, strike, r, mu, sigma, maturity, cl, hp)
Arguments
stockPrice |
Stock price of underlying stock |
strike |
Strike price of the option |
r |
Risk-free rate and is annualised |
mu |
Mean return |
sigma |
Volatility of the underlying stock |
maturity |
Term to maturity and is expressed in days |
cl |
Confidence level and is scalar |
hp |
Holding period and is scalar and is expressed in days |
Value
Price of European put Option
Author(s)
Dinesh Acharya
References
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Hull, John C.. Options, Futures, and Other Derivatives. 4th ed., Upper Saddle River, NJ: Prentice Hall, 200, ch. 11.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
Examples
# Derives VaR of a short Black Scholes put option
ShortBlackScholesPutVaR(27.2, 25, .03, .12, .2, 60, .95, 40)
Log Normal VaR with stop loss limit
Description
Generates Monte Carlo lognormal VaR with stop-loss limit
Usage
StopLossLogNormalVaR(mu, sigma, number.trials, loss.limit, cl, hp)
Arguments
mu |
Mean arithmetic return |
sigma |
Standard deviation of arithmetic return |
number.trials |
Number of trials used in the simulations |
loss.limit |
Stop Loss limit |
cl |
Confidence Level |
hp |
Holding Period |
Value
Lognormal VaR
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates standard error of normal quantile estimate
StopLossLogNormalVaR(0, .2, 100, 1.2, .95, 10)
Student's T Quantile - Quantile Plot
Description
Creates emperical QQ-plot of the quantiles of the data set x versus of a t distribution. The QQ-plot can be used to determine whether the sample in x is drawn from a t distribution with specified number of degrees of freedom.
Usage
TQQPlot(Ra, df)
Arguments
Ra |
Sample data set |
df |
Number of degrees of freedom of the t distribution |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# t-QQ Plot for randomly generated standard normal data
Ra <- rnorm(100)
TQQPlot(Ra, 20)
Variance-covariance ES for normally distributed returns
Description
Estimates the variance-covariance VaR of a portfolio assuming individual asset returns are normally distributed, for specified confidence level and holding period.
Usage
VarianceCovarianceES(vc.matrix, mu, positions, cl, hp)
Arguments
vc.matrix |
Variance covariance matrix for returns |
mu |
Vector of expected position returns |
positions |
Vector of positions |
cl |
Confidence level and is scalar |
hp |
Holding period and is scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Variance-covariance ES for randomly generated portfolio
vc.matrix <- matrix(rnorm(16), 4, 4)
mu <- rnorm(4)
positions <- c(5, 2, 6, 10)
cl <- .95
hp <- 280
VarianceCovarianceES(vc.matrix, mu, positions, cl, hp)
Variance-covariance VaR for normally distributed returns
Description
Estimates the variance-covariance VaR of a portfolio assuming individual asset returns are normally distributed, for specified confidence level and holding period.
Usage
VarianceCovarianceVaR(vc.matrix, mu, positions, cl, hp)
Arguments
vc.matrix |
Assumed variance covariance matrix for returns |
mu |
Vector of expected position returns |
positions |
Vector of positions |
cl |
Confidence level and is scalar or vector |
hp |
Holding period and is scalar or vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
See Also
AdjustedVarianceCovarianceVaR
Examples
# Variance-covariance VaR for randomly generated portfolio
vc.matrix <- matrix(rnorm(16),4,4)
mu <- rnorm(4)
positions <- c(5,2,6,10)
cl <- .95
hp <- 280
VarianceCovarianceVaR(vc.matrix, mu, positions, cl, hp)
ES for t distributed P/L
Description
Estimates the ES of a portfolio assuming that P/L are t-distributed, for specified confidence level and holding period.
Usage
tES(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily P/L data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data df Number of degrees of freedom in the t-distribution cl ES confidence level hp ES holding period in days |
Value
Matrix of ES whose dimension depends on dimension of hp and cl. If cl and hp are both scalars, the matrix is 1 by 1. If cl is a vector and hp is a scalar, the matrix is row matrix, if cl is a scalar and hp is a vector, the matrix is column matrix and if both cl and hp are vectors, the matrix has dimension length of cl * length of hp.
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Evans, M., Hastings, M. and Peacock, B. Statistical Distributions, 3rd edition, New York: John Wiley, ch. 38,39.
Examples
# Computes ES given P/L data
data <- runif(5, min = 0, max = .2)
tES(returns = data, df = 6, cl = .95, hp = 90)
# Computes ES given mean and standard deviation of P/L data
tES(mu = .012, sigma = .03, df = 6, cl = .95, hp = 90)
Percentiles of ES distribution function for t-distributed P/L
Description
Estimates percentiles of ES distribution function for t-distributed P/L, using the theory of order statistics
Usage
tESDFPerc(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 5 or 7. In case there 5 input arguments, the mean, standard deviation and assumed sampel size of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data n Sample size df Degrees of freedom perc Desired percentile df Number of degrees of freedom in the t distribution cl ES confidence level and must be a scalar hp ES holding period and must be a a scalar |
Value
Percentiles of ES distribution function
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates Percentiles of ES distribution given P/L data
data <- runif(5, min = 0, max = .2)
tESDFPerc(returns = data, perc = .7, df = 6, cl = .95, hp = 60)
# Estimates Percentiles of ES distribution given mean, std. deviation and sample size
tESDFPerc(mu = .012, sigma = .03, n= 10, perc = .8, df = 6, cl = .99, hp = 40)
Figure of t - VaR and ES and pdf against L/P
Description
Gives figure showing the VaR and ES and probability distribution function assuming P/L is t- distributed, for specified confidence level and holding period.
Usage
tESFigure(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data df Number of degrees of freedom cl VaR confidence level and should be scalar hp VaR holding period in days and should be scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Evans, M., Hastings, M. and Peacock, B. Statistical Distributions, 3rd edition, New York: John Wiley, ch. 38,39.
Examples
# Plots lognormal VaR, ES and pdf against L/P data for given returns data
data <- runif(5, min = 0, max = .2)
tESFigure(returns = data, df = 10, cl = .95, hp = 90)
# Plots lognormal VaR, ES and pdf against L/P data with given parameters
tESFigure(mu = .012, sigma = .03, df = 10, cl = .95, hp = 90)
Plots t- ES against confidence level
Description
Plots the ES of a portfolio against confidence level, assuming that L/P is t distributed, for specified confidence level and holding period.
Usage
tESPlot2DCL(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data df Number of degrees of freedom in the t distribution cl ES confidence level and must be a vector hp ES holding period and must be a scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Evans, M., Hastings, M. and Peacock, B. Statistical Distributions, 3rd edition, New York: John Wiley, ch. 38,39.
Examples
# Computes ES given geometric return data
data <- runif(5, min = 0, max = .2)
tESPlot2DCL(returns = data, df = 6, cl = seq(.9,.99,.01), hp = 60)
# Computes v given mean and standard deviation of return data
tESPlot2DCL(mu = .012, sigma = .03, df = 6, cl = seq(.9,.99,.01), hp = 40)
Plots t ES against holding period
Description
Plots the ES of a portfolio against holding period assuming that L/P is t distributed, for specified confidence level and holding periods.
Usage
tESPlot2DHP(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily P/L data mu Mean of daily P/L data sigma Standard deviation of daily P/L data df Number of degrees of freedom in the t distribution cl ES confidence level and must be a scalar hp ES holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Evans, M., Hastings, M. and Peacock, B. Statistical Distributions, 3rd edition, New York: John Wiley, ch. 38,39.
Examples
# Computes ES given geometric return data
data <- runif(5, min = 0, max = .2)
tESPlot2DHP(returns = data, df = 6, cl = .95, hp = 60:90)
# Computes v given mean and standard deviation of return data
tESPlot2DHP(mu = .012, sigma = .03, df = 6, cl = .99, hp = 40:80)
Plots t ES against confidence level and holding period
Description
Plots the ES of a portfolio against confidence level and holding period assuming that P/L are Student-t distributed, for specified confidence level and holding period.
Usage
tESPlot3D(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily P/L data mu Mean of daily P/L data sigma Standard deviation of daily P/L data df Number of degrees of freedom in the t distribution cl VaR confidence level and must be a vector hp VaR holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots ES against confidene level given P/L data
data <- runif(5, min = 0, max = .2)
tESPlot3D(returns = data, df = 6, cl = seq(.85,.99,.01), hp = 60:90)
# Computes ES against confidence level given mean and standard deviation of return data
tESPlot3D(mu = .012, sigma = .03, df = 6, cl = seq(.85,.99,.02), hp = 40:80)
Standard error of t quantile estimate
Description
Estimates standard error of t quantile estimate
Usage
tQuantileStandardError(prob, n, mu, sigma, df, bin.size)
Arguments
prob |
Tail probability. Can be a vector or scalar |
n |
Sample size |
mu |
Mean of the normal distribution |
sigma |
Standard deviation of the distribution |
df |
Number of degrees of freedom |
bin.size |
Bin size. It is optional parameter with default value 1 |
Value
Vector or scalar depending on whether the probability is a vector or scalar
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates standard error of normal quantile estimate
tQuantileStandardError(.8, 100, 0, .5, 5, 3)
VaR for t distributed P/L
Description
Estimates the VaR of a portfolio assuming that P/L are t distributed, for specified confidence level and holding period.
Usage
tVaR(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data df Number of degrees of freedom in the t distribution cl VaR confidence level hp VaR holding period |
Value
Matrix of VaRs whose dimension depends on dimension of hp and cl. If cl and hp are both scalars, the matrix is 1 by 1. If cl is a vector and hp is a scalar, the matrix is row matrix, if cl is a scalar and hp is a vector, the matrix is column matrix and if both cl and hp are vectors, the matrix has dimension length of cl * length of hp.
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Evans, M., Hastings, M. and Peacock, B. Statistical Distributions, 3rd edition, New York: John Wiley, ch. 38,39.
Examples
# Computes VaR given P/L data
data <- runif(5, min = 0, max = .2)
tVaR(returns = data, df = 6, cl = .95, hp = 90)
# Computes VaR given mean and standard deviation of P/L data
tVaR(mu = .012, sigma = .03, df = 6, cl = .95, hp = 90)
Percentiles of VaR distribution function
Description
Plots the VaR of a portfolio against confidence level assuming that P/L are t- distributed, for specified confidence level and holding period.
Usage
tVaRDFPerc(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 5 or 7. In case there 6 input arguments, the mean, standard deviation and number of observations of the data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data n Sample size perc Desired percentile df Number of degrees of freedom in the t distribution cl VaR confidence level and must be a scalar hp VaR holding period and must be a a scalar Percentiles of VaR distribution function |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Estimates Percentiles of VaR distribution
data <- runif(5, min = 0, max = .2)
tVaRDFPerc(returns = data, perc = .7,
df = 6, cl = .95, hp = 60)
# Computes v given mean and standard deviation of return data
tVaRDFPerc(mu = .012, sigma = .03, n= 10,
perc = .8, df = 6, cl = .99, hp = 40)
Plots t VaR and ES against confidence level
Description
Plots the VaR and ES of a portfolio against confidence level assuming that P/L data are t distributed, for specified confidence level and holding period.
Usage
tVaRESPlot2DCL(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there are 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data cl VaR confidence level and must be a vector hp VaR holding period and must be a scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots VaR and ETL against confidene level given P/L data
data <- runif(5, min = 0, max = .2)
tVaRESPlot2DCL(returns = data, df = 7, cl = seq(.85,.99,.01), hp = 60)
# Computes VaR against confidence level given mean and standard deviation of P/L data
tVaRESPlot2DCL(mu = .012, sigma = .03, df = 7, cl = seq(.85,.99,.01), hp = 40)
Figure of t- VaR and pdf against L/P
Description
Gives figure showing the VaR and probability distribution function against L/P of a portfolio assuming P/L are normally distributed, for specified confidence level and holding period.
Usage
tVaRFigure(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data df Number of degrees of freedom cl VaR confidence level and should be scalar hp VaR holding period in days and should be scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots normal VaR and pdf against L/P data for given returns data
data <- runif(5, min = 0, max = .2)
tVaRFigure(returns = data, df = 7, cl = .95, hp = 90)
# Plots normal VaR and pdf against L/P data with given parameters
tVaRFigure(mu = .012, sigma = .03, df=7, cl = .95, hp = 90)
Plots t VaR against confidence level
Description
Plots the VaR of a portfolio against confidence level assuming that P/L data is t distributed, for specified confidence level and holding period.
Usage
tVaRPlot2DCL(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily P/L data data mu Mean of daily P/L data data sigma Standard deviation of daily P/L data data df Number of degrees of freedom in the t distribution cl VaR confidence level and must be a vector hp VaR holding period and must be a scalar |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots VaR against confidene level given P/L data data
data <- runif(5, min = 0, max = .2)
tVaRPlot2DCL(returns = data, df = 6, cl = seq(.85,.99,.01), hp = 60)
# Computes VaR against confidence level given mean and standard deviation of P/L data
tVaRPlot2DCL(mu = .012, sigma = .03, df = 6, cl = seq(.85,.99,.01), hp = 40)
Plots t VaR against holding period
Description
Plots the VaR of a portfolio against holding period assuming that P/L are t- distributed, for specified confidence level and holding period.
Usage
tVaRPlot2DHP(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily P/L data data mu Mean of daily P/L data data sigma Standard deviation of daily P/L data data df Number of degrees of freedom in the t distribution cl VaR confidence level and must be a scalar hp VaR holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Computes VaR given P/L data data
data <- runif(5, min = 0, max = .2)
tVaRPlot2DHP(returns = data, df = 6, cl = .95, hp = 60:90)
# Computes VaR given mean and standard deviation of return data
tVaRPlot2DHP(mu = .012, sigma = .03, df = 6, cl = .99, hp = 40:80)
Plots t VaR against confidence level and holding period
Description
Plots the VaR of a portfolio against confidence level and holding period assuming that P/L are t distributed, for specified confidence level and holding period.
Usage
tVaRPlot3D(...)
Arguments
... |
The input arguments contain either return data or else mean and standard deviation data. Accordingly, number of input arguments is either 4 or 5. In case there 4 input arguments, the mean and standard deviation of data is computed from return data. See examples for details. returns Vector of daily geometric return data mu Mean of daily geometric return data sigma Standard deviation of daily geometric return data df Number of degrees of freedom in the t distribution cl VaR confidence level and must be a vector hp VaR holding period and must be a vector |
Author(s)
Dinesh Acharya
References
Dowd, K. Measuring Market Risk, Wiley, 2007.
Examples
# Plots VaR against confidene level given geometric return data
data <- runif(5, min = 0, max = .2)
tVaRPlot3D(returns = data, df = 6, cl = seq(.85,.99,.01), hp = 60:90)
# Computes VaR against confidence level given mean and standard deviation of return data
tVaRPlot3D(mu = .012, sigma = .03, df = 6, cl = seq(.85,.99,.02), hp = 40:80)