Title: | Functions Ported from 'MMR2' Toolbox Offered in Kevin Dowd's Book Measuring Market Risk |
---|---|
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. |
Authors: | Dinesh Acharya <[email protected]> |
Maintainer: | Dinesh Acharya <[email protected]> |
License: | GPL |
Version: | 0.12 |
Built: | 2025-03-05 04:02:22 UTC |
Source: | https://github.com/d-acharya/dowd |
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).
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.
Dinesh Acharya
Maintainer: Dinesh Acharya [email protected]
Dowd, K. Measuring Market Risk. Wiley. 2005.
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.
AdjustedNormalESHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
AdjustedNormalESHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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 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)
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.
AdjustedNormalVaRHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
AdjustedNormalVaRHotspots(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
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.
AdjustedVarianceCovarianceES(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
AdjustedVarianceCovarianceES(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
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.
AdjustedVarianceCovarianceVaR(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
AdjustedVarianceCovarianceVaR(vc.matrix, mu, skew, kurtosis, positions, cl, hp)
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
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:
which is equivalent to
ADTestStat(number.trials, sample.size, confidence.interval)
ADTestStat(number.trials, sample.size, confidence.interval)
number.trials |
Number of trials |
sample.size |
Sample size |
confidence.interval |
Confidence Interval |
Confidence Interval for AD test statistic
Dinesh Acharya
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.
# Probability that the VaR model is correct for 3 failures, 100 number # observations and 95% confidence level ADTestStat(1000, 100, 0.95)
# Probability that the VaR model is correct for 3 failures, 100 number # observations and 95% confidence level ADTestStat(1000, 100, 0.95)
Estimates ES of American Put Option using binomial tree to price the option and historical method to compute the VaR.
AmericanPutESBinomial(amountInvested, stockPrice, strike, r, volatility, maturity, numberSteps, cl, hp)
AmericanPutESBinomial(amountInvested, stockPrice, strike, r, volatility, maturity, numberSteps, cl, hp)
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. |
ES of the American Put Option
Dinesh Acharya
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
# Market Risk of American Put with given parameters. AmericanPutESBinomial(0.20, 27.2, 25, .16, .05, 60, 20, .95, 30)
# Market Risk of American Put with given parameters. AmericanPutESBinomial(0.20, 27.2, 25, .16, .05, 60, 20, .95, 30)
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.
AmericanPutESSim(amountInvested, stockPrice, strike, r, mu, sigma, maturity, numberTrials, numberSteps, cl, hp)
AmericanPutESSim(amountInvested, stockPrice, strike, r, mu, sigma, maturity, numberTrials, numberSteps, cl, hp)
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 |
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
Dinesh Acharya
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
# Market Risk of American Put with given parameters. AmericanPutESSim(0.20, 27.2, 25, .16, .2, .05, 60, 30, 20, .95, 30)
# Market Risk of American Put with given parameters. AmericanPutESSim(0.20, 27.2, 25, .16, .2, .05, 60, 30, 20, .95, 30)
Estimates the price of an American Put, using the binomial approach.
AmericanPutPriceBinomial(stockPrice, strike, r, sigma, maturity, numberSteps)
AmericanPutPriceBinomial(stockPrice, strike, r, sigma, maturity, numberSteps)
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 |
Binomial American put price
Dinesh Acharya
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
# Estimates the price of an American Put AmericanPutPriceBinomial(27.2, 25, .03, .2, 60, 30)
# Estimates the price of an American Put AmericanPutPriceBinomial(27.2, 25, .03, .2, 60, 30)
Estimates VaR of American Put Option using binomial tree to price the option and historical method to compute the VaR.
AmericanPutVaRBinomial(amountInvested, stockPrice, strike, r, volatility, maturity, numberSteps, cl, hp)
AmericanPutVaRBinomial(amountInvested, stockPrice, strike, r, volatility, maturity, numberSteps, cl, hp)
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. |
VaR of the American Put Option
Dinesh Acharya
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
# Market Risk of American Put with given parameters. AmericanPutVaRBinomial(0.20, 27.2, 25, .16, .05, 60, 20, .95, 30)
# Market Risk of American Put with given parameters. AmericanPutVaRBinomial(0.20, 27.2, 25, .16, .05, 60, 20, .95, 30)
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).
BinomialBacktest(x, n, cl)
BinomialBacktest(x, n, cl)
x |
Number of failures |
n |
Number of observations |
cl |
Confidence level for VaR |
Probability that the VaR model is correct
Dinesh Acharya
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.
# Probability that the VaR model is correct for 3 failures, 100 number # observations and 95% confidence level BinomialBacktest(55, 1000, 0.95)
# Probability that the VaR model is correct for 3 failures, 100 number # observations and 95% confidence level BinomialBacktest(55, 1000, 0.95)
Estimates ES of Black-Scholes call Option using Monte Carlo simulation
BlackScholesCallESSim(amountInvested, stockPrice, strike, r, mu, sigma, maturity, numberTrials, cl, hp)
BlackScholesCallESSim(amountInvested, stockPrice, strike, r, mu, sigma, maturity, numberTrials, cl, hp)
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 |
ES
Dinesh Acharya
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
# Market Risk of American call with given parameters. BlackScholesCallESSim(0.20, 27.2, 25, .16, .2, .05, 60, 30, .95, 30)
# Market Risk of American call with given parameters. BlackScholesCallESSim(0.20, 27.2, 25, .16, .2, .05, 60, 30, .95, 30)
Derives the price of European call option using the Black-Scholes approach
BlackScholesCallPrice(stockPrice, strike, rf, sigma, t)
BlackScholesCallPrice(stockPrice, strike, rf, sigma, t)
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 |
Price of European Call Option
Dinesh Acharya
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.
# Estimates the price of an American Put BlackScholesCallPrice(27.2, 25, .03, .2, 60)
# Estimates the price of an American Put BlackScholesCallPrice(27.2, 25, .03, .2, 60)
Estimates ES of Black-Scholes Put Option using Monte Carlo simulation
BlackScholesPutESSim(amountInvested, stockPrice, strike, r, mu, sigma, maturity, numberTrials, cl, hp)
BlackScholesPutESSim(amountInvested, stockPrice, strike, r, mu, sigma, maturity, numberTrials, cl, hp)
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 |
ES
Dinesh Acharya
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
Lyuu, Yuh-Dauh. Financial Engineering & Computation: Principles, Mathematics, Algorithms, Cambridge University Press, 2002.
# Market Risk of American Put with given parameters. BlackScholesPutESSim(0.20, 27.2, 25, .03, .12, .05, 60, 1000, .95, 30)
# Market Risk of American Put with given parameters. BlackScholesPutESSim(0.20, 27.2, 25, .03, .12, .05, 60, 1000, .95, 30)
Derives the price of European call option using the Black-Scholes approach
BlackScholesPutPrice(stockPrice, strike, rf, sigma, t)
BlackScholesPutPrice(stockPrice, strike, rf, sigma, t)
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 |
Price of European Call Option
Dinesh Acharya
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.
# Estimates the price of an American Put BlackScholesPutPrice(27.2, 25, .03, .2, 60)
# Estimates the price of an American Put BlackScholesPutPrice(27.2, 25, .03, .2, 60)
Derives the Blanco-Ihle forecast evaluation loss measure for a VaR risk measurement model.
BlancoIhleBacktest(Ra, Rb, Rc, cl)
BlancoIhleBacktest(Ra, Rb, Rc, cl)
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 |
First Blanco-Ihle score measure.
Dinesh Acharya
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.
# 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)
# 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)
Estimates the bootstrapped ES for confidence level and holding period implied by data frequency.
BootstrapES(Ra, number.resamples, cl)
BootstrapES(Ra, number.resamples, cl)
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 |
Bootstrapped Expected Shortfall
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Estimates bootstrapped ES for given parameters a <- rnorm(100) # generate a random profit/loss vector BootstrapVaR(a, 50, 0.95)
# Estimates bootstrapped ES for given parameters a <- rnorm(100) # generate a random profit/loss vector BootstrapVaR(a, 50, 0.95)
Estimates the 90 level and holding period implied by data frequency.
BootstrapESConfInterval(Ra, number.resamples, cl)
BootstrapESConfInterval(Ra, number.resamples, cl)
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 |
90
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 for the bootstrapped ES, for confidence level and holding period implied by data frequency.
BootstrapESFigure(Ra, number.resamples, cl)
BootstrapESFigure(Ra, number.resamples, cl)
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
Estimates the bootstrapped VaR for confidence level and holding period implied by data frequency.
BootstrapVaR(Ra, number.resamples, cl)
BootstrapVaR(Ra, number.resamples, cl)
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 |
Bootstrapped VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Estimates bootstrapped VaR for given parameters a <- rnorm(100) # generate a random profit/loss vector BootstrapES(a, 50, 0.95)
# Estimates bootstrapped VaR for given parameters a <- rnorm(100) # generate a random profit/loss vector BootstrapES(a, 50, 0.95)
Estimates the 90 level and holding period implied by data frequency.
BootstrapVaRConfInterval(Ra, number.resamples, cl)
BootstrapVaRConfInterval(Ra, number.resamples, cl)
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 |
90
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 for the bootstrapped VaR, for confidence level and holding period implied by data frequency.
BootstrapVaRFigure(Ra, number.resamples, cl)
BootstrapVaRFigure(Ra, number.resamples, cl)
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
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.
BoxCoxES(loss.data, cl)
BoxCoxES(loss.data, cl)
loss.data |
Daily Profit/Loss data |
cl |
Confidence Level. It can be a scalar or a vector. |
Estimated Box-Cox ES. Its dimension is same as that of cl
Dinesh Acharya
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.
# Estimates Box-Cox VaR a<-rnorm(200) BoxCoxES(a,.95)
# Estimates Box-Cox VaR a<-rnorm(200) BoxCoxES(a,.95)
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.
BoxCoxVaR(PandLdata, cl)
BoxCoxVaR(PandLdata, cl)
PandLdata |
Daily Profit/Loss data |
cl |
Confidence Level. It can be a scalar or a vector. |
Estimated Box-Cox VaR. Its dimension is same as that of cl
Dinesh Acharya
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.
# Estimates Box-Cox VaR a<-rnorm(100) BoxCoxVaR(a,.95)
# Estimates Box-Cox VaR a<-rnorm(100) BoxCoxVaR(a,.95)
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.
CdfOfSumUsingGaussianCopula(quantile, mu1, mu2, sigma1, sigma2, rho, number.steps.in.copula)
CdfOfSumUsingGaussianCopula(quantile, mu1, mu2, sigma1, sigma2, rho, number.steps.in.copula)
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 |
Probability of X + Y being less than quantile
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
Dowd, K. and Fackler, P. Estimating VaR with copulas. Financial Engineering News, 2004.
# 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)
# 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)
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.
CdfOfSumUsingGumbelCopula(quantile, mu1, mu2, sigma1, sigma2, beta)
CdfOfSumUsingGumbelCopula(quantile, mu1, mu2, sigma1, sigma2, beta)
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) |
Probability of X + Y being less than quantile
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
Dowd, K. and Fackler, P. Estimating VaR with copulas. Financial Engineering News, 2004.
# 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)
# 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)
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.
CdfOfSumUsingProductCopula(quantile, mu1, mu2, sigma1, sigma2)
CdfOfSumUsingProductCopula(quantile, mu1, mu2, sigma1, sigma2)
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 |
Probability of X + Y being less than quantile
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
Dowd, K. and Fackler, P. Estimating VaR with copulas. Financial Engineering News, 2004.
# 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)
# 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)
Carries out the Christoffersen backtest of independence for a VaR risk measurement model, for specified VaR confidence level.
ChristoffersenBacktestForIndependence(Ra, Rb, cl)
ChristoffersenBacktestForIndependence(Ra, Rb, cl)
Ra |
Vector of portfolio profit and loss observations |
Rb |
Vector of corresponding VaR forecasts |
cl |
Confidence interval for |
Probability that given the data set, the null hypothesis (i.e. independence) is correct.
Dinesh Acharya
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
Christoffersen, P. Evaluating Interval Forecasts. International Economic Review, 39(4), 1992, 841-862.
# 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)
# 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)
Carries out the Christiffersen backtest for unconditional coverage for a VaR risk measurement model, for specified VaR confidence level.
ChristoffersenBacktestForUnconditionalCoverage(Ra, Rb, cl)
ChristoffersenBacktestForUnconditionalCoverage(Ra, Rb, cl)
Ra |
Vector of portfolio profit and loss observations |
Rb |
Vector of VaR forecasts corresponding to PandL observations |
cl |
Confidence level for VaR |
Probability, given the data set, that the null hypothesis (i.e. a correct model) is correct.
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
Christoffersen, P. Evaluating interval forecasts. International Economic Review, 39(4), 1998, 841-862.
# 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)
# 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)
Function estimates the ES for near-normal P/L using the Cornish-Fisher adjustment for non-normality, for specified confidence level.
CornishFisherES(mu, sigma, skew, kurtosis, cl)
CornishFisherES(mu, sigma, skew, kurtosis, cl)
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 |
Expected Shortfall
Dinesh Acharya
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.
# Estimates Cornish-Fisher ES for given parameters CornishFisherES(3.2, 5.6, 2, 3, .9)
# Estimates Cornish-Fisher ES for given parameters CornishFisherES(3.2, 5.6, 2, 3, .9)
Function estimates the VaR for near-normal P/L using the Cornish-Fisher adjustment for non-normality, for specified confidence level.
CornishFisherVaR(mu, sigma, skew, kurtosis, cl)
CornishFisherVaR(mu, sigma, skew, kurtosis, cl)
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 at Risk
Dinesh Acharya
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.
# Estimates Cornish-Fisher VaR for given parameters CornishFisherVaR(3.2, 5.6, 2, 3, .9)
# Estimates Cornish-Fisher VaR for given parameters CornishFisherVaR(3.2, 5.6, 2, 3, .9)
Generates Monte Carlo VaR for DB pension in Chapter 6.7.
DBPensionVaR(mu, sigma, p, life.expectancy, number.trials, cl)
DBPensionVaR(mu, sigma, p, life.expectancy, number.trials, cl)
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 |
VaR for DB pension
Dinesh Acharya
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
# Estimates the price of an American Put DBPensionVaR(.06, .2, .05, 80, 100, .95)
# Estimates the price of an American Put DBPensionVaR(.06, .2, .05, 80, 100, .95)
Generates Monte Carlo VaR for DC pension in Chapter 6.7.
DCPensionVaR(mu, sigma, p, life.expectancy, number.trials, cl)
DCPensionVaR(mu, sigma, p, life.expectancy, number.trials, cl)
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 |
VaR for DC pension
Dinesh Acharya
Dowd, Kevin. Measuring Market Risk, Wiley, 2007.
# Estimates the price of an American Put DCPensionVaR(.06, .2, .05, 80, 100, .95)
# Estimates the price of an American Put DCPensionVaR(.06, .2, .05, 80, 100, .95)
Generates Monte Carlo VaR for default risky bond portfolio in Chapter 6.4
DefaultRiskyBondVaR(r, rf, coupon, sigma, amount.invested, recovery.rate, p, number.trials, hp, cl)
DefaultRiskyBondVaR(r, rf, coupon, sigma, amount.invested, recovery.rate, p, number.trials, hp, cl)
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 |
Monte Carlo VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# VaR for default risky bond portfolio for given parameters DefaultRiskyBondVaR(.01, .01, .1, .01, 1, .1, .2, 100, 100, .95)
# VaR for default risky bond portfolio for given parameters DefaultRiskyBondVaR(.01, .01, .1, .01, 1, .1, .2, 100, 100, .95)
Generates Monte Carlo lognormal VaR with filter portfolio strategy
FilterStrategyLogNormalVaR(mu, sigma, number.trials, alpha, cl, hp)
FilterStrategyLogNormalVaR(mu, sigma, number.trials, alpha, cl, hp)
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 |
Lognormal VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Estimates standard error of normal quantile estimate FilterStrategyLogNormalVaR(0, .2, 100, 1.2, .95, 10)
# Estimates standard error of normal quantile estimate FilterStrategyLogNormalVaR(0, .2, 100, 1.2, .95, 10)
Estimates the ES of a portfolio assuming extreme losses are Frechet distributed, for specified confidence level and a given holding period.
FrechetES(mu, sigma, tail.index, n, cl, hp)
FrechetES(mu, sigma, tail.index, n, cl, hp)
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 |
Note that the long-right-hand tail is fitted to losses, not profits.
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.
Dinesh Acharya
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.
# Computes ES assuming Frechet Distribution for given parameters FrechetES(3.5, 2.3, 1.6, 10, .95, 30)
# Computes ES assuming Frechet Distribution for given parameters FrechetES(3.5, 2.3, 1.6, 10, .95, 30)
Plots the ES of a portfolio against confidence level assuming extreme losses are Frechet distributed, for specified confidence level and a given holding period.
FrechetESPlot2DCl(mu, sigma, tail.index, n, cl, hp)
FrechetESPlot2DCl(mu, sigma, tail.index, n, cl, hp)
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 |
Note that the long-right-hand tail is fitted to losses, not profits.
Dinesh Acharya
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.
# 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)
# 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)
Estimates the VaR of a portfolio assuming extreme losses are Frechet distributed, for specified range of confidence level and a given holding period.
FrechetVaR(mu, sigma, tail.index, n, cl, hp)
FrechetVaR(mu, sigma, tail.index, n, cl, hp)
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 |
Note that the long-right-hand tail is fitted to losses, not profits.
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.
Dinesh Acharya
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.
# Computes VaR assuming Frechet Distribution for given parameters FrechetVaR(3.5, 2.3, 1.6, 10, .95, 30)
# Computes VaR assuming Frechet Distribution for given parameters FrechetVaR(3.5, 2.3, 1.6, 10, .95, 30)
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.
FrechetVaRPlot2DCl(mu, sigma, tail.index, n, cl, hp)
FrechetVaRPlot2DCl(mu, sigma, tail.index, n, cl, hp)
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 |
Note that the long-right-hand tail is fitted to losses, not profits.
Dinesh Acharya
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.
# 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)
# 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)
Derives VaR using bivariate Gaussian copula with specified inputs for normal marginals.
GaussianCopulaVaR(mu1, mu2, sigma1, sigma2, rho, number.steps.in.copula, cl)
GaussianCopulaVaR(mu1, mu2, sigma1, sigma2, rho, number.steps.in.copula, cl)
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 |
Copula based VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
Dowd, K. and Fackler, P. Estimating VaR with copulas. Financial Engineering News, 2004.
# VaR using bivariate Gaussian for X and Y with given parameters: GaussianCopulaVaR(2.3, 4.1, 1.2, 1.5, .6, 10, .95)
# VaR using bivariate Gaussian for X and Y with given parameters: GaussianCopulaVaR(2.3, 4.1, 1.2, 1.5, .6, 10, .95)
Estimates the ES of a portfolio assuming losses are distributed as a generalised Pareto.
GParetoES(Ra, beta, zeta, threshold.prob, cl)
GParetoES(Ra, beta, zeta, threshold.prob, cl)
Ra |
Vector of daily Profit/Loss data |
beta |
Assumed scale parameter |
zeta |
Assumed tail index |
threshold.prob |
Threshold probability |
cl |
VaR confidence level |
Expected Shortfall
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
McNeil, A., Extreme value theory for risk managers. Mimeo, ETHZ, 1999.
# 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)
# 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)
Plots of emperical mean excess function and Generalized mean excess function.
GParetoMEFPlot(Ra, mu, beta, zeta)
GParetoMEFPlot(Ra, mu, beta, zeta)
Ra |
Vector of daily Profit/Loss data |
mu |
Location parameter |
beta |
Scale parameter |
zeta |
Assumed tail index |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
Plots of emperical mean excess function and two generalized pareto mean excess functions which differ in their tail-index value.
GParetoMultipleMEFPlot(Ra, mu, beta, zeta1, zeta2)
GParetoMultipleMEFPlot(Ra, mu, beta, zeta1, zeta2)
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
Estimates the Value at Risk of a portfolio assuming losses are distributed as a generalised Pareto.
GParetoVaR(Ra, beta, zeta, threshold.prob, cl)
GParetoVaR(Ra, beta, zeta, threshold.prob, cl)
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 |
Expected Shortfall
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
McNeil, A., Extreme value theory for risk managers. Mimeo, ETHZ, 1999.
# 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)
# 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)
Derives VaR using bivariate Gumbel or logistic copula with specified inputs for normal marginals.
GumbelCopulaVaR(mu1, mu2, sigma1, sigma2, beta, cl)
GumbelCopulaVaR(mu1, mu2, sigma1, sigma2, beta, cl)
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 |
Copula based VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
Dowd, K. and Fackler, P. Estimating VaR with copulas. Financial Engineering News, 2004.
# VaR using bivariate Gumbel for X and Y with given parameters: GumbelCopulaVaR(1.1, 3.1, 1.2, 1.5, 1.1, .95)
# VaR using bivariate Gumbel for X and Y with given parameters: GumbelCopulaVaR(1.1, 3.1, 1.2, 1.5, 1.1, .95)
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.
GumbelES(mu, sigma, n, cl, hp)
GumbelES(mu, sigma, n, cl, hp)
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 |
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.
Dinesh Acharya
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.
# Gumber ES Plot GumbelES(0, 1.2, 100, c(.9,.88, .85, .8), 280)
# Gumber ES Plot GumbelES(0, 1.2, 100, c(.9,.88, .85, .8), 280)
Estimates the EV VaR of a portfolio assuming extreme losses are Gumbel distributed, for specified confidence level and holding period.
GumbelESPlot2DCl(mu, sigma, n, cl, hp)
GumbelESPlot2DCl(mu, sigma, n, cl, hp)
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Plots ES against Cl GumbelESPlot2DCl(0, 1.2, 100, seq(0.8,0.99,0.02), 280)
# Plots ES against Cl GumbelESPlot2DCl(0, 1.2, 100, seq(0.8,0.99,0.02), 280)
Estimates the EV VaR of a portfolio assuming extreme losses are Gumbel distributed, for specified confidence level and holding period.
GumbelVaR(mu, sigma, n, cl, hp)
GumbelVaR(mu, sigma, n, cl, hp)
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 |
Estimated VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Gumbel VaR GumbelVaR(0, 1.2, 100, c(.9,.88, .85, .8), 280)
# Gumbel VaR GumbelVaR(0, 1.2, 100, c(.9,.88, .85, .8), 280)
Estimates the EV VaR of a portfolio assuming extreme losses are Gumbel distributed, for specified confidence level and holding period.
GumbelVaRPlot2DCl(mu, sigma, n, cl, hp)
GumbelVaRPlot2DCl(mu, sigma, n, cl, hp)
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Plots VaR against Cl GumbelVaRPlot2DCl(0, 1.2, 100, c(.9,.88, .85, .8), 280)
# Plots VaR against Cl GumbelVaRPlot2DCl(0, 1.2, 100, c(.9,.88, .85, .8), 280)
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.
HillEstimator(Ra, tail.size)
HillEstimator(Ra, tail.size)
Ra |
Data set |
tail.size |
Number of observations to be used to estimate the Hill estimator. |
Estimated value of Hill Estimator
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Estimates Hill Estimator of Ra <- rnorm(15) HillEstimator(Ra, 10)
# Estimates Hill Estimator of Ra <- rnorm(15) HillEstimator(Ra, 10)
Displays a plot of the Hill Estimator against tail sample size.
HillPlot(Ra, maximum.tail.size)
HillPlot(Ra, maximum.tail.size)
Ra |
The data set |
maximum.tail.size |
maximum tail size and should be greater than a quarter of the sample size. |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Hill Estimator - Tail Sample Size Plot for random normal dataset Ra <- rnorm(1000) HillPlot(Ra, 180)
# Hill Estimator - Tail Sample Size Plot for random normal dataset Ra <- rnorm(1000) HillPlot(Ra, 180)
Estimates value of Hill Quantile Estimator for a specified data set, tail index, in-sample probability and confidence level.
HillQuantileEstimator(Ra, tail.index, in.sample.prob, cl)
HillQuantileEstimator(Ra, tail.index, in.sample.prob, cl)
Ra |
A data set |
tail.index |
Assumed tail index |
in.sample.prob |
In-sample probability (used as basis for projection) |
cl |
Confidence level |
Value of Hill Quantile Estimator
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
Next reference
# Computes estimates value of hill estimator for a specified data set Ra <- rnorm(1000) HillQuantileEstimator(Ra, 40, .5, .9)
# Computes estimates value of hill estimator for a specified data set Ra <- rnorm(1000) HillQuantileEstimator(Ra, 40, .5, .9)
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.
HSES(Ra, cl)
HSES(Ra, cl)
Ra |
Vector corresponding to profit and loss distribution |
cl |
Number between 0 and 1 corresponding to confidence level |
Expected Shortfall of the portfolio
Dinesh Acharya
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.
# 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)
# 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)
Estimates percentiles of historical simulation ES distribution function, using theory of order statistics, for specified confidence level.
HSESDFPerc(Ra, perc, cl)
HSESDFPerc(Ra, perc, cl)
Ra |
Vector of daily P/L data |
perc |
Desired percentile and is scalar |
cl |
VaR confidence level and is scalar |
Value of percentile of VaR distribution function
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Estimates Percentiles for random standard normal returns and given perc # and cl Ra <- rnorm(100) HSESDFPerc(Ra, .75, .95)
# Estimates Percentiles for random standard normal returns and given perc # and cl Ra <- rnorm(100) HSESDFPerc(Ra, .75, .95)
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.
HSESFigure(Ra, cl)
HSESFigure(Ra, cl)
Ra |
Vector of profit loss data |
cl |
VaR confidence level |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Plots figure showing VaR and histogram of P/L data Ra <- rnorm(100) HSESFigure(Ra, .95)
# Plots figure showing VaR and histogram of P/L data Ra <- rnorm(100) HSESFigure(Ra, .95)
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.
HSESPlot2DCl(Ra, cl)
HSESPlot2DCl(Ra, cl)
Ra |
Vector of daily P/L data |
cl |
Vector of ES confidence levels |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Plots historical simulation ES against confidence level Ra <- rnorm(100) cl <- seq(.90, .99, .01) HSESPlot2DCl(Ra, cl)
# Plots historical simulation ES against confidence level Ra <- rnorm(100) cl <- seq(.90, .99, .01) HSESPlot2DCl(Ra, cl)
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.
HSVaR(Ra, Rb)
HSVaR(Ra, Rb)
Ra |
Vector corresponding to profit and loss distribution |
Rb |
Scalar corresponding to VaR confidence levels. |
Value at Risk of the portfolio
Dinesh Acharya
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.
# To be added a <- rnorm(1000) # Payoffs of random portfolio HSVaR(a, .95)
# To be added a <- rnorm(1000) # Payoffs of random portfolio HSVaR(a, .95)
Estimates percentiles of historical simulation VaR distribution function, using theory of order statistics, for specified confidence level.
HSVaRDFPerc(Ra, perc, cl)
HSVaRDFPerc(Ra, perc, cl)
Ra |
Vector of daily P/L data |
perc |
Desired percentile and is scalar |
cl |
VaR confidence level and is scalar |
Value of percentile of VaR distribution function
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Estimates Percentiles for random standard normal returns and given perc # and cl Ra <- rnorm(100) HSVaRDFPerc(Ra, .75, .95)
# Estimates Percentiles for random standard normal returns and given perc # and cl Ra <- rnorm(100) HSVaRDFPerc(Ra, .75, .95)
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.
HSVaRESPlot2DCl(Ra, cl)
HSVaRESPlot2DCl(Ra, cl)
Ra |
Vector of daily P/L data |
cl |
Vectof of VaR confidence levels |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Plots historical simulation VaR and ES against confidence level Ra <- rnorm(100) cl <- seq(.90, .99, .01) HSVaRESPlot2DCl(Ra, cl)
# Plots historical simulation VaR and ES against confidence level Ra <- rnorm(100) cl <- seq(.90, .99, .01) HSVaRESPlot2DCl(Ra, cl)
Plots figure showing the historical simulation VaR and histogram of L/P for specified confidence level and holding period implied by data frequency.
HSVaRFigure(Ra, cl)
HSVaRFigure(Ra, cl)
Ra |
Vector of profit loss data |
cl |
ES confidence level |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Plots figure showing VaR and histogram of P/L data Ra <- rnorm(100) HSVaRFigure(Ra, .95)
# Plots figure showing VaR and histogram of P/L data Ra <- rnorm(100) HSVaRFigure(Ra, .95)
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.
HSVaRPlot2DCl(Ra, cl)
HSVaRPlot2DCl(Ra, cl)
Ra |
Vector of daily P/L data |
cl |
Vector of VaR confidence levels |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Plots historical simulation VaR against confidence level Ra <- rnorm(100) cl <- seq(.90, .99, .01) HSVaRPlot2DCl(Ra, cl)
# Plots historical simulation VaR against confidence level Ra <- rnorm(100) cl <- seq(.90, .99, .01) HSVaRPlot2DCl(Ra, cl)
Generates Monte Carlo VaR for insurance portfolio in Chapter 6.5
InsuranceVaR(mu, sigma, n, p, theta, deductible, number.trials, cl)
InsuranceVaR(mu, sigma, n, p, theta, deductible, number.trials, cl)
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 |
VaR of the specified portfolio
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Estimates VaR of Insurance portfolio with given parameters InsuranceVaR(.8, 1.3, 100, .6, 21, 12, 50, .95)
# Estimates VaR of Insurance portfolio with given parameters InsuranceVaR(.8, 1.3, 100, .6, 21, 12, 50, .95)
Generates Monte Carlo VaR and ES for insurance portfolio.
InsuranceVaRES(mu, sigma, n, p, theta, deductible, number.trials, cl)
InsuranceVaRES(mu, sigma, n, p, theta, deductible, number.trials, cl)
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 |
A list with "VaR" and "ES" of the specified portfolio
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Estimates VaR and ES of Insurance portfolio with given parameters y<-InsuranceVaRES(.8, 1.3, 100, .6, 21, 12, 50, .95)
# Estimates VaR and ES of Insurance portfolio with given parameters y<-InsuranceVaRES(.8, 1.3, 100, .6, 21, 12, 50, .95)
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
where
is sample size,
and
are coefficients of sample
skewness and kurtosis.
JarqueBeraBacktest(sample.skewness, sample.kurtosis, n)
JarqueBeraBacktest(sample.skewness, sample.kurtosis, n)
sample.skewness |
Coefficient of Skewness of the sample |
sample.kurtosis |
Coefficient of Kurtosis of the sample |
n |
Number of observations |
Probability of null hypothesis H0
Dinesh Acharya
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.
# 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)
# 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)
The output consists of a scalar ES for specified confidence level.
KernelESBoxKernel(Ra, cl)
KernelESBoxKernel(Ra, cl)
Ra |
Profit and Loss data set |
cl |
VaR confidence level |
Scalar VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# VaR for specified confidence level using box kernel approach Ra <- rnorm(30) KernelESBoxKernel(Ra, .95)
# VaR for specified confidence level using box kernel approach Ra <- rnorm(30) KernelESBoxKernel(Ra, .95)
The output consists of a scalar ES for specified confidence level.
KernelESEpanechinikovKernel(Ra, cl, plot = TRUE)
KernelESEpanechinikovKernel(Ra, cl, plot = TRUE)
Ra |
Profit and Loss data set |
cl |
ES confidence level |
plot |
Bool, plots cdf if true |
Scalar ES
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# ES for specified confidence level using Epanechinikov kernel approach Ra <- rnorm(30) KernelESEpanechinikovKernel(Ra, .95)
# ES for specified confidence level using Epanechinikov kernel approach Ra <- rnorm(30) KernelESEpanechinikovKernel(Ra, .95)
The output consists of a scalar ES for specified confidence level.
KernelESNormalKernel(Ra, cl)
KernelESNormalKernel(Ra, cl)
Ra |
Profit and Loss data set |
cl |
VaR confidence level |
Scalar VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# ES for specified confidence level using normal kernel approach Ra <- rnorm(30) KernelESNormalKernel(Ra, .95)
# ES for specified confidence level using normal kernel approach Ra <- rnorm(30) KernelESNormalKernel(Ra, .95)
The output consists of a scalar ES for specified confidence level.
KernelESTriangleKernel(Ra, cl)
KernelESTriangleKernel(Ra, cl)
Ra |
Profit and Loss data set |
cl |
VaR confidence level |
Scalar VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# VaR for specified confidence level using triangle kernel approach Ra <- rnorm(30) KernelESTriangleKernel(Ra, .95)
# VaR for specified confidence level using triangle kernel approach Ra <- rnorm(30) KernelESTriangleKernel(Ra, .95)
The output consists of a scalar VaR for specified confidence level.
KernelVaRBoxKernel(Ra, cl, plot = TRUE)
KernelVaRBoxKernel(Ra, cl, plot = TRUE)
Ra |
Profit and Loss data set |
cl |
VaR confidence level |
plot |
Bool which indicates whether the graph is plotted or not |
Scalar VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# VaR for specified confidence level using box kernel approach Ra <- rnorm(30) KernelVaRBoxKernel(Ra, .95)
# VaR for specified confidence level using box kernel approach Ra <- rnorm(30) KernelVaRBoxKernel(Ra, .95)
The output consists of a scalar VaR for specified confidence level.
KernelVaREpanechinikovKernel(Ra, cl, plot = TRUE)
KernelVaREpanechinikovKernel(Ra, cl, plot = TRUE)
Ra |
Profit and Loss data set |
cl |
VaR confidence level |
plot |
Bool, plots the cdf if true. |
Scalar VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# VaR for specified confidence level using epanechinikov kernel approach Ra <- rnorm(30) KernelVaREpanechinikovKernel(Ra, .95)
# VaR for specified confidence level using epanechinikov kernel approach Ra <- rnorm(30) KernelVaREpanechinikovKernel(Ra, .95)
The output consists of a scalar VaR for specified confidence level.
KernelVaRNormalKernel(Ra, cl, plot = TRUE)
KernelVaRNormalKernel(Ra, cl, plot = TRUE)
Ra |
Profit and Loss data set |
cl |
VaR confidence level |
plot |
Bool, plots cdf if true |
Scalar VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# VaR for specified confidence level using normal kernel approach Ra <- rnorm(30) KernelVaRNormalKernel(Ra, .95)
# VaR for specified confidence level using normal kernel approach Ra <- rnorm(30) KernelVaRNormalKernel(Ra, .95)
The output consists of a scalar VaR for specified confidence level.
KernelVaRTriangleKernel(Ra, cl, plot = TRUE)
KernelVaRTriangleKernel(Ra, cl, plot = TRUE)
Ra |
Profit and Loss data set |
cl |
VaR confidence level |
plot |
Bool, plots cdf if true. |
Scalar VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# VaR for specified confidence level using triangle kernel approach Ra <- rnorm(30) KernelVaRTriangleKernel(Ra, .95)
# VaR for specified confidence level using triangle kernel approach Ra <- rnorm(30) KernelVaRTriangleKernel(Ra, .95)
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 :
KSTestStat(number.trials, sample.size, confidence.interval)
KSTestStat(number.trials, sample.size, confidence.interval)
number.trials |
Number of trials |
sample.size |
Sizes of the trial samples |
confidence.interval |
Confidence interval expressed as a fraction of 1 |
Confidence Interval for KS test stat
Dinesh Acharya
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.
# 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)
# 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)
Kuiper test statistic is a non parametric test for distribution equality and is closely related to KS test. Formally, the Kuiper test statistic is :
KuiperTestStat(number.trials, sample.size, confidence.interval)
KuiperTestStat(number.trials, sample.size, confidence.interval)
number.trials |
Number of trials |
sample.size |
Sizes of the trial samples |
confidence.interval |
Confidence interval expressed as a fraction of 1 |
Confidence Interval for KS test stat
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
Estimates the ES of a portfolio assuming that geometric returns are normally distributed, for specified confidence level and holding period.
LogNormalES(...)
LogNormalES(...)
... |
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 |
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.
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
Estimates the percentiles of ES distribution for normally distributed geometric returns, for specified confidence level and holding period using the theory of order statistics.
LogNormalESDFPerc(...)
LogNormalESDFPerc(...)
... |
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 |
Percentiles of ES distribution function
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
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.
LogNormalESFigure(...)
LogNormalESFigure(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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 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 the ES of a portfolio against confidence level assuming that geometric returns are normally distributed, for specified confidence level and holding period.
LogNormalESPlot2DCL(...)
LogNormalESPlot2DCL(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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 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 the ES of a portfolio against holding period assuming that geometric returns are normal distributed, for specified confidence level and holding period.
LogNormalESPlot2DHP(...)
LogNormalESPlot2DHP(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 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.
LogNormalESPlot3D(...)
LogNormalESPlot3D(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
Estimates the VaR of a portfolio assuming that geometric returns are normally distributed, for specified confidence level and holding period.
LogNormalVaR(...)
LogNormalVaR(...)
... |
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 |
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.
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
Estimates the percentile of VaR distribution function for normally distributed geometric returns, using the theory of order statistics.
LogNormalVaRDFPerc(...)
LogNormalVaRDFPerc(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 the VaR and ETL of a portfolio against confidence level assuming that geometric returns are normally distributed, for specified confidence level and holding period.
LogNormalVaRETLPlot2DCL(...)
LogNormalVaRETLPlot2DCL(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
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.
LogNormalVaRFigure(...)
LogNormalVaRFigure(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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 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 the VaR of a portfolio against confidence level assuming that geometric returns are normally distributed, for specified confidence level and holding period.
LogNormalVaRPlot2DCL(...)
LogNormalVaRPlot2DCL(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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 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 the VaR of a portfolio against holding period assuming that geometric returns are normal distributed, for specified confidence level and holding period.
LogNormalVaRPlot2DHP(...)
LogNormalVaRPlot2DHP(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 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.
LogNormalVaRPlot3D(...)
LogNormalVaRPlot3D(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
Estimates the ES of a portfolio assuming that geometric returns are Student-t distributed, for specified confidence level and holding period.
LogtES(...)
LogtES(...)
... |
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 |
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.
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
Plots the ES of a portfolio against confidence level assuming that geometric returns are Student t distributed, for specified confidence level and holding period.
LogtESDFPerc(...)
LogtESDFPerc(...)
... |
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 |
Percentiles of ES distribution function
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 the ES of a portfolio against confidence level assuming that geometric returns are Student t distributed, for specified confidence level and holding period.
LogtESPlot2DCL(...)
LogtESPlot2DCL(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 the ES of a portfolio against holding period assuming that geometric returns are Student t distributed, for specified confidence level and holding period.
LogtESPlot2DHP(...)
LogtESPlot2DHP(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 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.
LogtESPlot3D(...)
LogtESPlot3D(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
Estimates the VaR of a portfolio assuming that geometric returns are Student t distributed, for specified confidence level and holding period.
LogtVaR(...)
LogtVaR(...)
... |
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 |
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.
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
Plots the VaR of a portfolio against confidence level assuming that geometric returns are Student t distributed, for specified confidence level and holding period.
LogtVaRDFPerc(...)
LogtVaRDFPerc(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 the VaR of a portfolio against confidence level assuming that geometric returns are Student-t distributed, for specified confidence level and holding period.
LogtVaRPlot2DCL(...)
LogtVaRPlot2DCL(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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 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 the VaR of a portfolio against holding period assuming that geometric returns are Student t distributed, for specified confidence level and holding period.
LogtVaRPlot2DHP(...)
LogtVaRPlot2DHP(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 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.
LogtVaRPlot3D(...)
LogtVaRPlot3D(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
Function derives the VaR of a long Black Scholes call for specified confidence level and holding period, using analytical solution.
LongBlackScholesCallVaR(stockPrice, strike, r, mu, sigma, maturity, cl, hp)
LongBlackScholesCallVaR(stockPrice, strike, r, mu, sigma, maturity, cl, hp)
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 |
Price of European Call Option
Dinesh Acharya
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.
# Estimates the price of an American Put LongBlackScholesCallVaR(27.2, 25, .03, .12, .2, 60, .95, 40)
# Estimates the price of an American Put LongBlackScholesCallVaR(27.2, 25, .03, .12, .2, 60, .95, 40)
Function derives the VaR of a long Black Scholes put for specified confidence level and holding period, using analytical solution.
LongBlackScholesPutVaR(stockPrice, strike, r, mu, sigma, maturity, cl, hp)
LongBlackScholesPutVaR(stockPrice, strike, r, mu, sigma, maturity, cl, hp)
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 |
Price of European put Option
Dinesh Acharya
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.
# Estimates the price of an American Put LongBlackScholesPutVaR(27.2, 25, .03, .12, .2, 60, .95, 40)
# Estimates the price of an American Put LongBlackScholesPutVaR(27.2, 25, .03, .12, .2, 60, .95, 40)
Derives the first Lopez (i.e. binomial) forecast evaluation score for a VaR risk measurement model.
LopezBacktest(Ra, Rb, cl)
LopezBacktest(Ra, Rb, cl)
Ra |
Vector of portfolio of profit loss distribution |
Rb |
Vector of corresponding VaR forecasts |
cl |
VaR confidence level |
Something
Dinesh Acharya
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.
# 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)
# 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)
Plots mean-excess function values of the data set.
MEFPlot(Ra)
MEFPlot(Ra)
Ra |
Vector data |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Plots mean-excess function values Ra <- rnorm(1000) MEFPlot(Ra)
# Plots mean-excess function values Ra <- rnorm(1000) MEFPlot(Ra)
Estimates the ES of a portfolio assuming that P/L is normally distributed, for specified confidence level and holding period.
NormalES(...)
NormalES(...)
... |
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 |
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.
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 95% confidence intervals for normal ES using Monte Carlo simulation
NormalESConfidenceInterval(mu, sigma, number.trials, sample.size, cl, hp)
NormalESConfidenceInterval(mu, sigma, number.trials, sample.size, cl, hp)
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 |
95% confidence intervals for normal ES
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Generates 95\% confidence intervals for normal ES for given parameters NormalESConfidenceInterval(0, .5, 20, 20, .95, 90)
# Generates 95\% confidence intervals for normal ES for given parameters NormalESConfidenceInterval(0, .5, 20, 20, .95, 90)
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.
NormalESDFPerc(...)
NormalESDFPerc(...)
... |
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 |
Percentiles of ES distribution function
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
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.
NormalESFigure(...)
NormalESFigure(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
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.
NormalESHotspots(vc.matrix, mu, positions, cl, hp)
NormalESHotspots(vc.matrix, mu, positions, cl, hp)
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 |
Hotspots for normal ES
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 the ES of a portfolio against confidence level assuming that P/L are normally distributed, for specified confidence level and holding period.
NormalESPlot2DCL(...)
NormalESPlot2DCL(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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 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 the ES of a portfolio against holding period assuming that P/L distribution is normally distributed, for specified confidence level and holding period.
NormalESPlot2DHP(...)
NormalESPlot2DHP(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 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.
NormalESPlot3D(...)
NormalESPlot3D(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
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.
NormalQQPlot(Ra)
NormalQQPlot(Ra)
Ra |
Vector data set |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Normal QQ Plot for randomly generated standard normal data Ra <- rnorm(100) NormalQQPlot(Ra)
# Normal QQ Plot for randomly generated standard normal data Ra <- rnorm(100) NormalQQPlot(Ra)
Estimates standard error of normal quantile estimate
NormalQuantileStandardError(prob, n, mu, sigma, bin.size)
NormalQuantileStandardError(prob, n, mu, sigma, bin.size)
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 |
Vector or scalar depending on whether the probability is a vector or scalar
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Estimates standard error of normal quantile estimate NormalQuantileStandardError(.8, 100, 0, .5, 3)
# Estimates standard error of normal quantile estimate NormalQuantileStandardError(.8, 100, 0, .5, 3)
Function estimates the spectral risk measure of a portfolio assuming losses are normally distributed, assuming exponential weighting function with specified gamma.
NormalSpectralRiskMeasure(mu, sigma, gamma, number.of.slices)
NormalSpectralRiskMeasure(mu, sigma, gamma, number.of.slices)
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 |
Estimated spectral risk measure
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Generates 95% confidence intervals for normal VaR for given parameters NormalSpectralRiskMeasure(0, .5, .8, 20)
# Generates 95% confidence intervals for normal VaR for given parameters NormalSpectralRiskMeasure(0, .5, .8, 20)
Estimates the VaR of a portfolio assuming that P/L is normally distributed, for specified confidence level and holding period.
NormalVaR(...)
NormalVaR(...)
... |
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 |
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.
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 95% confidence intervals for normal VaR using Monte Carlo simulation
NormalVaRConfidenceInterval(mu, sigma, number.trials, sample.size, cl, hp)
NormalVaRConfidenceInterval(mu, sigma, number.trials, sample.size, cl, hp)
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 |
95% confidence intervals for normal VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Generates 95\% confidence intervals for normal VaR for given parameters NormalVaRConfidenceInterval(0, .5, 20, 15, .95, 90)
# Generates 95\% confidence intervals for normal VaR for given parameters NormalVaRConfidenceInterval(0, .5, 20, 15, .95, 90)
Estimates the percentile of VaR distribution function for normally distributed P/L, using the theory of order statistics.
NormalVaRDFPerc(...)
NormalVaRDFPerc(...)
... |
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 |
Percentiles of VaR distribution function and is scalar
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
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.
NormalVaRFigure(...)
NormalVaRFigure(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
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.
NormalVaRHotspots(vc.matrix, mu, positions, cl, hp)
NormalVaRHotspots(vc.matrix, mu, positions, cl, hp)
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 |
Hotspots for normal VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 the VaR of a portfolio against confidence level assuming that P/L are normally distributed, for specified confidence level and holding period.
NormalVaRPlot2DCL(...)
NormalVaRPlot2DCL(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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 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 the VaR of a portfolio against holding period assuming that P/L are normally distributed, for specified confidence level and holding period.
NormalVaRPlot2DHP(...)
NormalVaRPlot2DHP(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 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.
NormalVaRPlot3D(...)
NormalVaRPlot3D(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 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.
PCAES(Ra, position.data, number.of.principal.components, cl)
PCAES(Ra, position.data, number.of.principal.components, cl)
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 |
ES
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Computes PCA ES Ra <- matrix(rnorm(4*6),4,6) position.data <- rnorm(6) PCAES(Ra, position.data, 2, .95)
# Computes PCA ES Ra <- matrix(rnorm(4*6),4,6) position.data <- rnorm(6) PCAES(Ra, position.data, 2, .95)
Estimates ES plot using principal components analysis
PCAESPlot(Ra, position.data)
PCAESPlot(Ra, position.data)
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Computes PCA ES Ra <- matrix(rnorm(15*20),15,20) position.data <- rnorm(20) PCAESPlot(Ra, position.data)
# 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
PCAPrelim(Ra)
PCAPrelim(Ra)
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 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.
PCAVaR(Ra, position.data, number.of.principal.components, cl)
PCAVaR(Ra, position.data, number.of.principal.components, cl)
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 |
VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Computes PCA VaR Ra <- matrix(rnorm(4*6),4,6) position.data <- rnorm(6) PCAVaR(Ra, position.data, 2, .95)
# Computes PCA VaR Ra <- matrix(rnorm(4*6),4,6) position.data <- rnorm(6) PCAVaR(Ra, position.data, 2, .95)
Estimates VaR plot using principal components analysis
PCAVaRPlot(Ra, position.data)
PCAVaRPlot(Ra, position.data)
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Computes PCA VaR Ra <- matrix(rnorm(15*20),15,20) position.data <- rnorm(20) PCAVaRPlot(Ra, position.data)
# Computes PCA VaR Ra <- matrix(rnorm(15*20),15,20) position.data <- rnorm(20) PCAVaRPlot(Ra, position.data)
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.
PickandsEstimator(Ra, tail.size)
PickandsEstimator(Ra, tail.size)
Ra |
A data set |
tail.size |
Number of observations to be used to estimate the Pickands estimator |
Value of Pickands estimator
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Computes estimated Pickands estimator for randomly generated data. Ra <- rnorm(1000) PickandsEstimator(Ra, 40)
# Computes estimated Pickands estimator for randomly generated data. Ra <- rnorm(1000) PickandsEstimator(Ra, 40)
Displays a plot of the Pickands Estimator against Tail Sample Size.
PickandsPlot(Ra, maximum.tail.size)
PickandsPlot(Ra, maximum.tail.size)
Ra |
The data set |
maximum.tail.size |
maximum tail size and should be greater than a quarter of the sample size. |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Pickand - Sample Tail Size Plot for random standard normal data Ra <- rnorm(1000) PickandsPlot(Ra, 40)
# Pickand - Sample Tail Size Plot for random standard normal data Ra <- rnorm(1000) PickandsPlot(Ra, 40)
Derives VaR using bivariate Product or logistic copula with specified inputs for normal marginals.
ProductCopulaVaR(mu1, mu2, sigma1, sigma2, cl)
ProductCopulaVaR(mu1, mu2, sigma1, sigma2, cl)
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 |
Copula based VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
Dowd, K. and Fackler, P. Estimating VaR with copulas. Financial Engineering News, 2004.
# VaR using bivariate Product for X and Y with given parameters: ProductCopulaVaR(.9, 2.1, 1.2, 1.5, .95)
# VaR using bivariate Product for X and Y with given parameters: ProductCopulaVaR(.9, 2.1, 1.2, 1.5, .95)
Function derives the VaR of a short Black Scholes call for specified confidence level and holding period, using analytical solution.
ShortBlackScholesCallVaR(stockPrice, strike, r, mu, sigma, maturity, cl, hp)
ShortBlackScholesCallVaR(stockPrice, strike, r, mu, sigma, maturity, cl, hp)
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 |
Price of European Call Option
Dinesh Acharya
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.
# Estimates the price of an American Put ShortBlackScholesCallVaR(27.2, 25, .03, .12, .2, 60, .95, 40)
# Estimates the price of an American Put ShortBlackScholesCallVaR(27.2, 25, .03, .12, .2, 60, .95, 40)
Function derives the VaR of a Short Black Scholes put for specified confidence level and holding period, using analytical solution.
ShortBlackScholesPutVaR(stockPrice, strike, r, mu, sigma, maturity, cl, hp)
ShortBlackScholesPutVaR(stockPrice, strike, r, mu, sigma, maturity, cl, hp)
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 |
Price of European put Option
Dinesh Acharya
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.
# Derives VaR of a short Black Scholes put option ShortBlackScholesPutVaR(27.2, 25, .03, .12, .2, 60, .95, 40)
# Derives VaR of a short Black Scholes put option ShortBlackScholesPutVaR(27.2, 25, .03, .12, .2, 60, .95, 40)
Generates Monte Carlo lognormal VaR with stop-loss limit
StopLossLogNormalVaR(mu, sigma, number.trials, loss.limit, cl, hp)
StopLossLogNormalVaR(mu, sigma, number.trials, loss.limit, cl, hp)
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 |
Lognormal VaR
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Estimates standard error of normal quantile estimate StopLossLogNormalVaR(0, .2, 100, 1.2, .95, 10)
# Estimates standard error of normal quantile estimate StopLossLogNormalVaR(0, .2, 100, 1.2, .95, 10)
Estimates the ES of a portfolio assuming that P/L are t-distributed, for specified confidence level and holding period.
tES(...)
tES(...)
... |
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 |
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.
Dinesh Acharya
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.
# 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)
# 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)
Estimates percentiles of ES distribution function for t-distributed P/L, using the theory of order statistics
tESDFPerc(...)
tESDFPerc(...)
... |
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 |
Percentiles of ES distribution function
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
Gives figure showing the VaR and ES and probability distribution function assuming P/L is t- distributed, for specified confidence level and holding period.
tESFigure(...)
tESFigure(...)
... |
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 |
Dinesh Acharya
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.
# 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 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 the ES of a portfolio against confidence level, assuming that L/P is t distributed, for specified confidence level and holding period.
tESPlot2DCL(...)
tESPlot2DCL(...)
... |
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 |
Dinesh Acharya
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.
# 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)
# 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 the ES of a portfolio against holding period assuming that L/P is t distributed, for specified confidence level and holding periods.
tESPlot2DHP(...)
tESPlot2DHP(...)
... |
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 |
Dinesh Acharya
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.
# 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)
# 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 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.
tESPlot3D(...)
tESPlot3D(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
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.
TQQPlot(Ra, df)
TQQPlot(Ra, df)
Ra |
Sample data set |
df |
Number of degrees of freedom of the t distribution |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# t-QQ Plot for randomly generated standard normal data Ra <- rnorm(100) TQQPlot(Ra, 20)
# t-QQ Plot for randomly generated standard normal data Ra <- rnorm(100) TQQPlot(Ra, 20)
Estimates standard error of t quantile estimate
tQuantileStandardError(prob, n, mu, sigma, df, bin.size)
tQuantileStandardError(prob, n, mu, sigma, df, bin.size)
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 |
Vector or scalar depending on whether the probability is a vector or scalar
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# Estimates standard error of normal quantile estimate tQuantileStandardError(.8, 100, 0, .5, 5, 3)
# Estimates standard error of normal quantile estimate tQuantileStandardError(.8, 100, 0, .5, 5, 3)
Estimates the VaR of a portfolio assuming that P/L are t distributed, for specified confidence level and holding period.
tVaR(...)
tVaR(...)
... |
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 |
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.
Dinesh Acharya
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.
# 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)
# 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)
Plots the VaR of a portfolio against confidence level assuming that P/L are t- distributed, for specified confidence level and holding period.
tVaRDFPerc(...)
tVaRDFPerc(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 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.
tVaRESPlot2DCL(...)
tVaRESPlot2DCL(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
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.
tVaRFigure(...)
tVaRFigure(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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 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 the VaR of a portfolio against confidence level assuming that P/L data is t distributed, for specified confidence level and holding period.
tVaRPlot2DCL(...)
tVaRPlot2DCL(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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 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 the VaR of a portfolio against holding period assuming that P/L are t- distributed, for specified confidence level and holding period.
tVaRPlot2DHP(...)
tVaRPlot2DHP(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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 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.
tVaRPlot3D(...)
tVaRPlot3D(...)
... |
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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)
# 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)
Estimates the variance-covariance VaR of a portfolio assuming individual asset returns are normally distributed, for specified confidence level and holding period.
VarianceCovarianceES(vc.matrix, mu, positions, cl, hp)
VarianceCovarianceES(vc.matrix, mu, positions, cl, hp)
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
# 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 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)
Estimates the variance-covariance VaR of a portfolio assuming individual asset returns are normally distributed, for specified confidence level and holding period.
VarianceCovarianceVaR(vc.matrix, mu, positions, cl, hp)
VarianceCovarianceVaR(vc.matrix, mu, positions, cl, hp)
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 |
Dinesh Acharya
Dowd, K. Measuring Market Risk, Wiley, 2007.
AdjustedVarianceCovarianceVaR
# 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)
# 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)