Finally things are clear. R users who want to work with a Student t mixture distribution in the context of Value at Risk or Expected Shortfall can feel safe to use an implementation similar to the one given below (in an older mail of mine), but choosing "std" instead of "sstd" when using the "rugarch" package or alternatively applying the function "pTF2" when using the "gamlss.dist" package.

The following corrections will be interesting mainly for people who work with the book (Market Risk Analysis IV - first edition printed in 2009) of C.Alexander.

The implementation of the objective function (details were given earlier)
     L * P(X < (q-m)/r) + (1-L) * P(Y < (q-n)/s) - theta = 0
by C.Alexander is wrong, both in theory (see p. 117) and practice (see e.g. the Excel Example IV.2.23 on the CD).

TDIST(-(-C25-D8)/D10*SQRT(C22/(C22-2)),C22,1)

would be the correct transformation of the random variable to be Student t with variance C22/(C22-2), which is the variance of a standard Student t (NOT a STANDARDIZED one!) random variable with degrees of freedom "C22" - given that "C22" > 2 of course. This is because Excel has only the standard Student t distribution implemented (in a quite cumbersome form).

(Remark: In this example "C25" is the desired quantile, "D8" is the mean of the respective Student t and "D10" is its standard deviation.)

The implementation given in the spreadsheets which can be found on the CD contained in the book is however

SQRT(C22/(C22-2))*TDIST(-(-C25-D8)/D10,C22,1)

Which makes the same mistake as the footnote on page 117:
"In general, if X has distribution F(x) and Y=aX, a being a constant, then y has distribution function a^(−1) * F(x)"

I want to thank Alexios for his support in clearifying things!
Best,
Johannes





Am 25.04.2014 15:17, schrieb Johannes Moser:
Thanks for your help so far, Alexios!

I didn`t want to write down all the datails of the exercise because my text alredy was lengthly and also because I didn`t want to violate any copyrights. Rather, I was hoping that someone has the book and the CD at hand because I think that the book is pretty popular.

To answer your question: The EXCEL example from the book was adapted by me in the following way:

1) change the risk horizon to 1 day (so that there would be no scaling
and the autocorrelation doesn`t matter)
2) if necessary change the significance level (1% or 0,1% in my example)

this has already been stated in my first mail. So the numbers for for mu_stress, variance_quiet and variance_stress are the (annualized) numbers given in the example scaled to one day. I just did copy and paste with the down-scaled numbers from the EXCEL spreadsheet to check if my own R syntax leads to the same results as the EXCEL setup given by the CD in the book of C.Alexander.

A general description of my approach might be given by the following sketch: Calculate 1-day VaR with confidence level 99% (and 99,9%) of a bivariate student t mixture distribution by means of backing out the quantile from the formula
    L * P(X < (q-m)/r) + (1-L) * P(Y < (q-n)/s) = theta
(see C.Alexander p.113)
(the VaR is just minus the 1% or 0.1% quantile "q")
"L" is the mixing law giving the probability for the mixture random variable to follow the same student-t distribution as the random variable "X" with mean "m", standard deviation "r" and degrees of freedom "df1". The mixture random variable follows a student t distribution with mean "n", standard deviation "s" and degrees of freedom "df2" with probability "(1-L)". This is the distribution for the random variable "Y". "q" ist the required "theta"-quantile (as pointed out, "theta" is set to 0.01 and 0.001 in my example)

The notation in my R code is:

p_quiet = L
mu_quiet = m
mu_stress = n
df_quiet = df1
df_stress = df2
variance_quiet = r^2
variance_stress = s^2
theta = theta

I hope that with these details everyone can evaluate if my syntax is set up correctly. The values for these variables as to the modified example from Alexanders book can be read in the R syntax given in my first mail.

My aim (later!) is to simulate a fictive return series in a regime-switching manner using student t mixture models and calculate the analytical VaR and Expected Shortfall in a dynamical way. Then I want to apply several other estimation techniques to the simulated mixture series and examine their performance in relation to the analytic results. But first I have to make sure that my analytic VaR for the student t mixture model is correct. However, verification of the Example given by C.Alexander indeed requires her book and the enclosed CD with the EXCEL workbooks.
I just can`t post all this stuff here.




Am 25.04.2014 14:15, schrieb alexios ghalanos:
I suggest you take a break and consider that in order to help you, it is
required that you state ALL the assumptions and provide a complete
example. Since the book is not generally available, and you have told us
very little about the problem and its assumptions (other than a page and
example number), then you shouldn't expect much help.

Alexios

PS How did you come up with the numbers for mu_stress, variance_quiet
and variance_stress? From what I am told, the book example provides the
annualized values and you are required to calculate the 10-day VaR (so
you are required to rescale the numbers to their 10-day equivalents).

On 25/04/2014 11:23, Johannes Moser wrote:
Thanks a lot, Alexios!
I have corrected this issue. The result is the same, though.

I forgot to mention that the RUGARCH-package is required to run the code.

At the moment I try to find the error in either
- my own theoretical thoughts (e.g. confusing the scale parameter with
the standard deviation)
- the implementation made by C.Alexander (on page 117 she writes in a
footnote: "In general, if X has distribution F(x) and Y=aX, a being a
constant, then y has distribution function a^(−1) * F(x)". Either I am
completely burnout right now, or this must be "F(a^(−1)*x)" in the end.
So maybe this is not just a typo, but also incorrectly implemented in
the quite complicated EXCEL formula.)
- some EXCEL or R issue. I think her EXCEL syntax has been programmed in
version 2003, but I`m running 2010.

Any help is appreciated a lot!



Am 25.04.2014 11:46, schrieb Alexios Ghalanos:
A quick look at your code suggests that you should use "std" (student)
not "sstd" (skew student) for distribution.

Alexios

On 25 Apr 2014, at 09:49, Johannes Moser <jzmo...@gmail.com> wrote:

Dear R community,

in trying to set up a little simulation study I adapt the ideas found in "Carol Alexander: Market Risk IV - Value at Risk Models" on page 111 ff.
and implement them in R.
This project is about student t mixture distributions and Value at Risk
/ Expected Shortfall.

The following code is my setup so far, and the syntax is calibrated to
resemble the Example 2.23 on page 118 in the mentioned book of
Alexander. There is a  EXCEL-file coming with the book and I noticed
that my results don`t match the results of the EXCEL implementation.

e.g. my result for theta=0.001 is

0.0841052 (method 1) and

0.0842109 (method 2)
... but the EXCEL-file coming with the book says that it was 0.1152


setting theta=0.01 gives

0.04493586 (method 1) and

0.04490717 (method 2)

... but the EXCEL-file coming with the book says that it was 0.0616


Maybe some of you guys have this book at hand and are able to verify and
hopefully find a solution for my worries.
Or even if you don`t have the book you might still be able to assess the
correctness of my approach and implementation?




##################################################################################################

# SET UP MIXTURE INGREDIENTS (calibrate to C.Alexander Market Risk
Analysis IV Exercise 2.23)

p_quiet <- 0.75
mu_quiet <- 0.0
mu_stress <- -0.0004
df_quiet <- 10
df_stress <- 5
variance_quiet <- 0.0126^2
variance_stress <- 0.0253^2
theta <- 0.001


# METHOD_1)   Backing out mixture VaR from implicit analytic formula:
find_quant <- function(quant) {
       (p_quiet*pdist(distribution = "sstd",
(quant-mu_quiet)/sqrt(variance_quiet)  , mu = 0, sigma = 1, shape =
df_quiet)
       + (1-p_quiet)*pdist(distribution = "sstd",
(quant-mu_stress)/sqrt(variance_stress)  , mu = 0, sigma = 1, shape =
df_stress) - theta)
}
bestquant <- uniroot(f = find_quant, interval = c(-5, 1))
t_mix_VaR1 <- -bestquant$root


# METHOD_2)   Estimating mixture VaR by simulation:
nsim <- 10000000
u_mix <- x <- 1*(runif(nsim) < p_quiet)
t_quiet <- rdist(distribution = "sstd", nsim , mu = mu_quiet, sigma =
sqrt(variance_quiet), shape = df_quiet)
t_stress <- rdist(distribution = "sstd", nsim , mu = mu_stress, sigma =
sqrt(variance_stress), shape = df_stress)
t_mixture <- u_mix*t_quiet + (1-u_mix)*t_stress
t_mix_VaR2 <- as.numeric(-quantile( t_mixture , probs=theta  ))

# Compare results
t_mix_VaR1
t_mix_VaR2
##################################################################################################





The EXCEL spreadsheet "EX_IV.2.23" in the workbook "Examples_IV.2.xls"
has been used and modified as follows:
1) change the risk horizon to 1 day (so that there would be no scaling
and the autocorrelation doesn`t matter)
2) if necessary change the significance level (1% or 0,1% in my example) 3) press F11 to recalcualte the mixture parameters over the risk horizon 4) apply EXCEL SOLVER to line C24 while allowing for changing cell C25
to get the t Mixture VaR

Thanks a lot for any ideas or suggestions!
Johannes













     [[alternative HTML version deleted]]

_______________________________________________
R-SIG-Finance@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R
questions should go.



--
_________________________
Johannes Moser
Sophie-Charlotten-Str. 35
14059 Berlin
Tel: 0176 2171 2196

_______________________________________________
R-SIG-Finance@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should 
go.

Reply via email to