QRM 12 – Laptop session
Introduction
The objectives of the session are
(a). To perform Age-weighted HS
(b). To perform Hull-White Historical Simulation.
Let’s prepare the data
d <- EuStockMarkets[,c(1,4)]
dax.ft <- diff(d)/lag(d, k=-1)
dax <- dax.ft[,1]
ft <- dax.ft[,2]
Age-weighted Historical Simulation
Cut and paste the AW-HS function from Moodle. Find the AW-HS VaR and ES for the
Dax portfolio (dax.ft[,1]).
Amend the function so that it works for a two asset portfolio.
Volatility Adjustment
Here we review how to perform volatility adjustment. This is simple to do for the Two
asset case, but for brevity we look at the single asset case. We look at the FTSE data
again. First, we need to load fGarch:
library(fGarch)
Before estimating Garch models, it is conventional to remove the mean (hence the
first line below). We need to remember to add it back after adjusting the volatility.
ft.dm <- ft - mean(ft)
Then we use garchFit which estimates the model. We can store the results for later
use - I use the variable gf for this purpose.
gf <- garchFit(data=ft.dm)
We can extract the volatilities using the volatility() function on the fitted object:
vol <- volatility(gf)
vol.p <- vol[length(vol)]
st <- vol.p/vol
And finally we adjust the returns, then add back the mean:
ft.adj <- ft.dm * st
ft.adj <- ft.adj + mean(ft)
Now we have generated volatility adjusted returns.
Hull-White Historical Simulation
Once we have volatility-adjusted returns, we can use them to perform Historical Sim-
ulation. This is what is meant by the Hull-White procedure.
So to find risk measures using the Hull-White method:
Pt <- 1000
loss <- -Pt*ft.adj
v95 <- quantile(loss,0.95)
v95
t.loss <- loss[loss>v95]
ES95 <- mean(t.loss)
ES95
b.v <- boot(loss,var95.boot,R=1000)
b.v
plot(b.v)
boot.ci(b.v,type="basic")
b.es <- boot(loss,es95.boot,R=1000)
b.es
plot(b.es)
boot.ci(b.es,type="basic")
The two-asset case is trivial, but shown here for completeness:
First we do volatility adjustment on each asset (we have already done this for FTSE,
so just need DAX):
dax.dm <- dax - mean(dax)
gf.dax <- garchFit(data=dax.dm)
vol.dax <- volatility(gf.dax)
vol.p.dax <- vol.dax[length(vol.dax)]
st.dax <- vol.p.dax/vol.dax
dax.adj <- dax.dm * st.dax
dax.adj <- dax.adj + mean(dax)
dax.ft.adj <- cbind(dax.adj, ft.adj)
Then calulate losses and risk measures as before.
P <- 1000
w <- c(0.75,0.25)
Pw <- -P*w
loss <- rowSums(t(Pw * t(dax.ft.adj)))
## use the functions we wrote as before
v95 <- quantile(loss,0.95)
v95
t.loss <- loss[loss>v95]
ES95 <- mean(t.loss)
ES95
## Bootstrapping
## VaR 95%
b.v <- boot(loss,var95.boot,R=1000)
b.v
plot(b.v)
boot.ci(b.v,type="basic")
## ES 95%
b.es <- boot(loss,es95.boot,R=1000)
b.es
plot(b.es)
boot.ci(b.es,type="basic")
Exercise: Has the Hull-White procedure changed the VaR and ES estimates as com-
pared to the results previously obtained for the FTSE portfolio Which of the two sets
of results would you trust more
Resources
The Quick-R page has material and references to the bootstrap: http://www.statmethods.
net/advstats/bootstrapping.html