A Comparison Of Value-At-Risk Methods For
Portfolios Consisting Of Interest Rate Swaps And
FRAs
Robyn Engelbrecht Supervisor: Dr. Graeme West
Acknowledgements
Contents
1 Introduction 5
1.1 Introduction to Value at Risk . . . 5
1.2 Problem Description . . . 7
2 Assumptions and Background 9
2.1 Choice of Return . . . 9
2.2 The Holding Period . . . 10
2.3 Choice of Risk Factors when Dealing with the Yield Curve . . 11
2.4 Modelling Risk Factors . . . 11
2.5 The Historical Data . . . 12
3 The Portfolios 15
3.1 Decomposing Instruments into their Building Blocks . . . 15
3.2 Mapping Cashflows onto the set of Standard Maturities . . . 17
4 The Delta-Normal Method 18
4.2 Description of Method . . . 18
5 Historical Value at Risk 21
5.1 Classical Historical Simulation . . . 21
5.1.1 Background . . . 21
5.1.2 Description of Method . . . 22
5.2 Historical Simulation with Volatility Updating (Hull-White Historical Simulation) . . . 23
5.2.1 Background . . . 23
5.2.2 Description of Method . . . 23
6 Monte Carlo Simulation 25
6.1 Background . . . 25
6.2 Monte Carlo Simulation using Cholesky decomposition . . . . 26
6.3 Monte Carlo Simulation using Principal Components Analysis 26
7 Results 30
8 Conclusions 36
A Appendix 39
A.1 The EWMA Model . . . 39
A.2 Cash Flow Mappping . . . 40
A.3 The Variance of the Return on a Portfolio . . . 41
B.1 VBA Code: Bootstrapping Module . . . 42
B.2 VBA Code: VaR Module . . . 44
Chapter 1
Introduction
1.1
Introduction to Value at Risk
Value at Risk, or VaR, is a widely used measure of financial risk, which provides a way of quantifying and managing the risk of a portfolio. It has, in the past few years, become a key component of the management of market risk for many financial institutions1. It is used as an internal risk management tool, and has also been chosen by the Basel Committee on Banking Supervision as the international standard for external regulatory purposes2.
Definition 1.1The VaR of a portfolio is a function of 2 parameters, a time period and a confidence interval. It equals the loss on a portfolio that will not be exceeded by the end of the time period with the specified confidence level [2].
Estimating the VaR of a portfolio thus involves determining a probability distribution for the change in the value of the portfolio over the time period (known as the holding period). Consider a portfolio of financial instruments i= 1, . . . , n, whose values at timet depend on thek market variables (risk factors)
xt:=
³
x(1)t , . . . , x(tk) ´
1Market risk is the risk associated with uncertainty about future earnings relating to
changes in asset prices and market rates.
2The capital that a bank is required to hold against its market risk is based on VaR
with a 10-day holding period at a 99% confidence level. Specifically, the regulatory capital requirement for market risk is defined as max(VaRt−1, k×Avg{V aRt−i|i= 1, . . . ,60}).
Herekis the multiplication factor, which is set to between 3 and 4 depending on previous backtest results, and VaRt refers to a VaR estimate for daytbased on a 10 day holding
These market variables could be exchange rates, stock prices, interest rates, etc. Denote the monetary positions in these instruments by
W := (W1, . . . , Wn)
(A fundamental assumption of VaR is that the positions in each instrument remain static over the holding period, so the subscript t above has been omitted.) Let the values of the instruments at timet be given by
Pt:= ³
Pt(1)(xt), . . . , Pt(n)(xt) ´
(1.1.1)
wherePt(i)(xt), i∈ {1, . . . , n}are pricing formulae, such as the Black-Scholes
pricing formula. The value of the portfolio at timetis given by
Vt(Pt, W) = n
X
i=1
WiPt(i)(xt) (1.1.2)
Let δt be the length of the holding period, and α ∈ (0,1) be the level of significance3. VaR can be defined in terms of either the distribution of the portfolio valueVt+δt, or in terms of the distribution of the arithmetic return
of the portfolioRt+δt= (Vt+δt−Vt)/Vt. Consider the (100×α)th percentile of the distribution of values of the portfolio att+δt. This is given by the valuevα in the expression4
P[Vt+δt≥vα] =α
LetRα be the arithmetic return corresponding to vα. In other wordsvα =
Vt(1 +Rα). The relative VaR of the portfolio is defined by
VaR(relative) :=Et[Vt+δt]−vα =−Vt(Rα−Et[Rt+δt]) (1.1.3) (1.1.3) gives the monetary loss of the portfolio over the holding period rela-tive to the mean of the distribution. Sometimes, the value of the portfolio at timet,Vt, is used instead of Et[Vt+δt]. This is known as the absolute VaR:
VaR(absolute) :=Vt−vα=−VtRα (1.1.4)
(1.1.4) gives the monetary loss relative to zero, or without reference to the ex-pected value. The equations above follow from the fact thatEt[Vt+δt]−vα=
Vt(1 +Et[Rt+δt])−Vt(1 +Rα) andVt−vα=Vt−Vt(1 +Rα). When the time
horizon is small, the expected return can be quite small, and so the results of (1.1.3) and (1.1.4) can be similar, but (1.1.3) is a better estimate in general,
3Typicallyα= 0.05 or α= 0.01, which correspond to a confidence level of 95% and
99% respectively.
4This percentile always corresponds to a negative value, but VaR is given by a positive
since it accounts for the time value of money, and pull-to-par effects which may become significant towards the end of the life of a portfolio [3].
Thus the problem of estimating VaR is reduced to the problem of esti-mating the distribution of the portfolio value, or that of the portfolio return, at the end of the holding period. Typically this is done via the estimation of the distribution of the underlying risk factors. However, there is no sin-gle industry standard used to do this. The general techniques commonly used include analytic techniques (the Normal method and the Delta-Gamma method), Historical simulation, and Monte Carlo simulation. As described in [4], the techniques differ along two lines:
Local/Full valuation This refers to whether the distribution is estimated
using a Taylor series approximation (local valuation), or whether the method generates a number of scenarios and estimates the distribution by revaluing a portfolio under these scenarios (full valuation).
Parametric/Nonparametric Parametric techniques involve the selection
of a distribution for the returns of the market variables, and the esti-mation of the statistical parameters of these returns. Nonparametric techniques do not rely on these estimations, since it is assumed that the sample distribution is an adequate proxy for the population dis-tribution.
For large portfolios, the decision of which method is chosen presents a trade-off of speed against accuracy, with the fast analytic methods relying on rough approximations; and the most realistic approach, Monte Carlo simulation, often considered too slow to be practical.
1.2
Problem Description
The aim of this project is to implement various VaR methods, and to com-pare these methods on portfolios consisting of the linear interest rate deriva-tives, forward rate agreements (FRAs) and interest rate swaps. The perfor-mance of a VaR method depends very much on the type of portfolio being considered, and the aim of this project is therefore to determine which of the methods is best for this type of portfolio. These derivatives represent an important share of the interest rate component of a bank’s trading port-folios, since the more complicated interest rate derivatives don’t trade that much in this country. The methods to be considered are:
2. Historical Simulation
3. Historical Simulation with Volatility updating
4. Monte Carlo simulation using Cholesky decomposition
5. Monte Carlo Simulation using Principal components analysis
Although the Delta-Normal method and Monte Carlo simulation are para-metric, and Historical simulation is nonparapara-metric, direct comparison is pos-sible since the distributional parameters will be estimated using the same historical data as will be used to generate scenarios for the Historical sim-ulation methods. The methods will be tested on various hypothetical port-folios, by estimating VaR for these portfolios over the historical period, and comparing the estimates to the actual losses that occurred. VaR will be estimated for these portfolios at both the 95% and 99% confidence levels. Implementation of the methods is to be done in VBA. This was decided on mostly for convenience, due to the large amount of data that needs to be read from and written to spreadsheet.
Chapter 2
Assumptions and
Background
2.1
Choice of Return
The arithmetic return on an instrument at timet+δtis given by
Ra(Pt(+i)δt) = (Pt(+i)δt−Pt(i))/Pt(i) The equivalent geometric return is given by
Rg(Pt(+i)δt) = ln(Pt(+i)δt/Pt(i))
We define the arithmetic returns in the risk factors,Ra(x(i)
t+δt) andR
g(x(i) t+δt) in exactly the same way. Both formulations have their own advantages and disadvantages. The arithmetic return of an instrument is needed when aggregating assets across portfolios, since the arithmetic return of a portfolio is a weighted linear sum of the arithmetic returns of the individual assets (the corresponding formula for the return of a portfolio in terms of geometric returns of the assets is not linear). However, the geometric return aggregates better across time (the n day return is equal to a linear sum of the 1 day returns, whereas the corresponding formula for thenday arithmetic return is not so simple). See [4] for more detail on this.
looking at the left tail of the distribution of these returns,Ra(P(i)
t+δt)→ −∞ implies thatPt(+i)δt <0.
If returns are small, then the difference betweenRa(P(i)
t+δt) andR
g(P(i) t+δt) is small, since we can use a Taylor series approximation to get
Rg(Pt(+i)δt) = ln(Pt(+i)δt/Pt(i))
= ln((Pt(+i)δt−Pt(i))/Pt(i)+ 1) = (Pt(+i)δt−Pt(i))/Pt(i)− 1
2((P (i)
t+δt−P
(i)
t )/Pt(i))2+. . .
≈ (Pt(+i)δt−Pt(i))/Pt(i) (2.1.1) to first order. (Equivalently, for Rg(x(t+i)δt).) In practice, when modelling returns, for the above reasons, geometric returns are preferred, but the as-sumption is always made, for convenience, that the geometric return of a portfolio is the linear weighted sum of the geometric returns of the individ-ual instruments.
Also, the definitions in (1.1.3) and (1.1.4) pertain to the arithmetic re-turns of a portfolio. In practice, regarding these definitions, the distribution is again modelled according to geometric returns, and the assumption in (2.1.1) is used.
2.2
The Holding Period
Although the holding period is typically a day, 10 days (for regulatory pur-poses), or a month, VaR calculations are always initially done on a holding period of 1 day, since this provides the maximum amount of historical in-formation with which to estimate parameters. Time aggregation techniques are then used to transform the distribution for daily VaR into a distribution for the longer holding period. (This is described in [3]). In the case where portfolio returns can be assumed to bei.i.d., it is possible to simply scale the VaR number obtained by multiplying it by the square root of the required time horizon. So from now on we assume thatδt= 1 day.1
1Note that the short term market risk measurement which VaR concerns itself with is
2.3
Choice of Risk Factors when Dealing with the
Yield Curve
The distribution used to estimate the VaR of a portfolio is determined from the distribution of the risk factors to which the portfolio is exposed. The first step to measuring the risk of a portfolio is to determine what these risk factors are. When dealing with the yield curve, the question which arises, due to the nontraded nature of interest rates, is whether the underlying risk factors are in fact the rates themselves, or the corresponding zero coupon bond prices. In this project, they were taken to be the zero coupon bond prices2. However, both methods are used in practice.
2.4
Modelling Risk Factors
The easiest and most common model for risk factors is the geometric Brow-nian motion model, in other words, the risk factors follow the process
dx(ti)=µix(ti)dt+σix(ti)dWt(i)
for 1≤i≤k, whereµi andσi represent the instantaneous drift and
volatil-ity, respectively, of the process for the ith risk factor and (Wt(i))t≥0 are Brownian motions, which will typically be correlated. To determine an ex-pression for x(tj), let g(xj) = lnxj. Then ∂x∂gi = δijx1i and ∂
2g
∂xi∂xj = −δij 1
x2
i whereδij is the indicator function. By the multidimensional Ito formula we get
dg(xjt) =
k
X
i=1 ∂g ∂xidx
(i)
t + 1 2 k X i=1 k X j=1 ∂2g ∂xi∂xjdx
(i)
t dx(tj) (2.4.2)
=
k
X
i=1 ∂g ∂xidx
(i)
t + 1 2 k X i=1 ∂2g ∂x2
i
(dx(ti))2
= 1
x(tj)dx (j)
t +
1 2
Ã
−1 (x(ti))2
!
(dx(ti))2
= µ
µj−12σj2
¶
dt+σjdWt(j)
Thus, discretizing this, overδt,
x(tj+)δt = x(tj)exp µµ
µj−12σj2
¶
δt+σjδWt(j)
¶
= x(tj)exp µµ
µj−12σj2
¶
δt+σj
√
δtZj
¶
≈ x(tj)exp ³
σj
√
δtZj
´
(2.4.3)
where Z ∼φk(0,Σ) and Σ is the variance-covariance matrix which will be
defined in (4.2.2). (2.4.3) follows since the holding periodδtis only one day. The major problem with the normality assumption is that, as described in [5], the distribution of daily returns of any risk factor would in reality typically show significant amounts of positive kurtosis. This leads to fatter tails and extreme outcomes occurring much more frequently than would be predicted by the normal distribution assumption, which would lead to an underestimation of VaR (since VaR is concerned with the tails of the distri-bution). But the model is generally considered to be an adequate description of the process followed by risk factors such as equities and exchange rates.
However, when dealing with the yield curve, the assumption of normality of returns clearly does not give an adequate description of reality, since inter-est rates are known to be mean reverting, and zero coupon bonds are subject to pull-to-par effects towards the end of their life. Although a simple inter-est rate model, such as a short rate model, may price an instrument more accurately (since it would capture the mean reverting property of interest rates), short rate models assume that all rates along the curve are perfectly correlated with the short rate, and thus will all move in the same direction. Since this is of course not the case in reality, it doesn’t give much of an in-dication of the risk of a portfolio to moves in the yield curve. A multi-factor model increases complexity dramatically, and still does not give us what we want. To illustrate this, suppose that rates have been on the increase for a while. An interest rate model would model a decrease in rates due to the mean reverting effect which would come into play. However, what a risk measurement technique is in fact interested in, is a continued upward trend. So although the normality assumption would lead to unrealistic term struc-tures over longer time horizons, since we are dealing with a holding period of a day, the assumption seems to be appropriate for risk measurement, since to quote [3], ”for risk management purposes, what matters is to capture the richness in movements of the term structure, not necessarily to price today’s instruments to the last decimal point.”
2.5
The Historical Data
• overnight, 1 month, and 3 month rates (simple yields)
• 3v6, 6v9, 9v12, 12v15, 15v18, 18v21 and 21v24 FRA rates (simple yields) and
• 3, 4, 5,. . . , 10, 12, 15, 20, 23, 25, 30 year swap rates (NACQ),
for the period from 2 July 2001 to 30 June 2003. Each array of rates was bootstrapped to determine a daily NACC swap curve. This was done using the Monotone Piecewise Convergence (MPC) interpolation method3. Given that a large portfolio could depend on any number of the rates on the curve, and that measuring the risk of a portfolio typically involves the estimation of a variance-covariance matrix of the underlying risk factors, it can become in-feasible, if not impossible, to estimate the risk of a portfolio to each of these rates individually. A standard set of maturities needs to be defined in order to implement a risk measurement technique with a fixed set of data require-ments. The rates at these standard maturities are then assumed to describe the interest rate risk of the entire curve, and all calculations (of volatilities, correlations, etc) are done based on this standard set of maturities. The standard maturities selected consists of the following 24 maturities, in days (these correspond as closely as possible to the actual/365 daycount used in South Africa):
1, 30, 91, 182, 273, 365, 456, 547, 638, 730, 1095, 1460, 1825, 2190, 2555, 2920, 3285, 3650, 4380, 5475, 6205, 7300, 9125 and 10950 days
Figure 2.1 shows daily zero coupon yield data over the 2 year period for the standard set of maturities. From this graph it is evident that interest rates were quite volatile during this period. In particular, note the ’spike’ in almost all the rates which occurs in December 2001. (This event significantly affects the results seen). Also, note that in June 2002, the entire yield curve inverts, resulting in the term structure changing from being approximately increasing to approximately decreasing.
3For an explanation of this interpolation method, see [6]. The bootstrapping code was
Chapter 3
The Portfolios
3.1
Decomposing Instruments into their Building
Blocks
Since it is impossible to measure the risk of each of the enormous number of risk factors which a portfolio could depend on, simplifications are required. The first step to measuring the risk of a portfolio is to decompose the in-struments making up a portfolio into simpler components. Both FRAs and swaps can be valued by decomposing them into a series of zero-coupon in-struments1. The next step is to map these positions onto positions for which we have prices of the components. Finally, we estimate VaR of the mapped portfolio.
Aforward rate agreement(FRA) is an agreement that a certain interest rate will apply to certain notional principal during a specific future period of time [7]. If the contract, with a notional principal of L, is entered into at timet, and applies for the period T1 toT2 (T2 - T1 is always 3 months), then the party on the long side of the contract agrees to pay a fixed rate r (the FRA rate) and receive a floating rate rf (3 month JIBAR, a simple yield rate) overT1 toT2. This is equivalent to the following cashflows:
timeT1: −L
timeT2: +L(1 +r(T2−T1))
So at any time s, where t ≤ s ≤ T1, a FRA can be valued by
discount-1Although FRAs and swaps can both be represented in terms of implied forward rates,
ing these cashflows. In other words
V =LB(s, T2)(1 +r(T2−T1))−LB(s, T1)
where B(s, T) is the discount factor at s for the period s to T. The value to the short side is just the negative of this amount.
Aswap is an agreement between two counterparties to exchange a series of future cashflows. The party on the long side of the swap agrees to make a series of fixed payments and to receive a series of floating payments, typically every 3 months, based on the notional principal L. The floating payments are based on the floating rate (typically 3 month JIBAR) observed at the beginning of that 3 month period. Payments always occur in arrears, i.e. they follow the natural time lag which many interest rate derivatives follow, allowing us to value a swap in terms of bonds. The value of the swap to the long side can be determined as the exchange of a fixed rate bond for a floating rate bond.
V =Bfloat−Bfix
The value to the short side is just the negative of this. LetLbe the notional principal andR the effective swap rate per period, let there benpayments remaining in the life of the swap, and let the time till the ith payment be ti, 1≤i≤n. Then the value of the fixed leg at timetis
Bfix =RL
n
X
i=1
B(t, ti)
Iftis a cashflow date, then the value of the floating leg is just
Bfloat =L(1−B(t, tn))
Iftis not a cashflow date, then the value of the fixed leg is unchanged, but the value of the floating leg is determined using prespecified JIBAR rate for the next payment. Supposeti−1 < t < ti. Let the JIBAR rate for (ti−1, ti]
berf (simple yield rate). Then the value of the floating leg is
Bfloat =L µ
1 +rf(ti365−t)
¶
B(t, ti)−LB(t, tn)
3.2
Mapping Cashflows onto the set of Standard
Maturities
In general, we have a cashflow occurring at timet2, and two standard matu-ritiest1 andt3 which brackett2. We need a way of determining the value of the discount factor att2, which will necessarily involve some type of interpo-lation. There are various procedures for mapping cashflows of interest rate positions. The technique of cash flow mapping used here, again consistent with [4, Ch 6], splits each cashflow into two cashflows occurring at its closest standard vertices, and has the property that it assigns weights to these two vertices in such a way that
• Market value is preserved i.e. the total market value of the two stan-dardized cash flows is equal to the market value of the original cash flow.
• Variance is preserved i.e. the variance of the portfolio of the two standardized cash flows is equal to the variance of the original cash flow.
• Sign is preserved i.e. the standardized cash flows have the same sign as the original cash flow.
The method is described in Appendix A.2. This mapping technique is done for all cashflows in a portfolio, except of course in the case where the cash-flow corresponds exactly to one of the standard vertices, where mapping becomes redundant. Using the mapped cashflows, we are able to determine VaR for the portfolio, since we have the required volatilities and correlations of the bond prices for these maturities.
Chapter 4
The Delta-Normal Method
4.1
Background
The Delta-Normal method (classic RiskMetrics Approach) is a parametric, analytic technique where the distributional assumption made is that the daily geometric returns of the market variables are multivariate normally distributed with mean return zero. The major advantage of this is that we can use the normal probability density function to estimate VaR analyti-cally, using just a local valuation.
The normality assumption for returns of the underlying risk factors was discussed in Section 2.4. The more problematic assumption in general is the linearity assumption, since a first order approximation won’t be able to adequately describe the risk of portfolios containing optionality. However, since this project is only concerned with linear instruments, the assumption is not problematic here.
The advantages of this method include its speed (since it is a local valua-tion technique) and simplicity, and the fact that the distribuvalua-tion of returns need not be assumed to be stationary through time, since volatility updating is incorporated into the parameter estimation.
4.2
Description of Method
of a portfolio as the standard deviation of returns, based on the variances and covariances of the returns of the underlying instruments. The only real difference here is that in Markowitz portfolio theory, the underlying variables are taken to be the instruments making up a portfolio, whereas in Delta-Normal VaR, because the distributional assumptions are based on the returns of the risk factors and not on the instruments, the underlying variables are taken to be the risk factors themselves. As a consequence of the linearity assumption, we can in fact consider a portfolio of holdings in n instruments as a portfolio of holdings, W = (W1, . . . , Wk), in the k
underlying risk factors, wherek is not necessarily equal ton. Scaling these to determine the relative holdingsωi = PW(ii)
t
,i= 1, . . . , k so that the latter sum to unity, we get the vectorω= (ω1, . . . , ωk),
LetR(ti) denote the arithmetic return of theith risk factor at timet. The (arithmetic) return of the portfolio at timet is
Rt= k
X
i=1 wiR(ti)
The expected return of the portfolio at timetis
E[Rt] =E
" k X
i=1 wiR(ti)
# =
k
X
i=1
wiE[R(ti)] = 0
using the approximation in (2.1.1) and the assumption that the geometric returns have mean zero. The variance of the portfolio return at time t is given by
Var[Rt] =ωTΣω (4.2.1)
where Σ is the Variance-Covariance matrix given by
Σ =
σ21 σ1σ2ρ1,2 . . . σ1σkρ1,k
σ2σ1ρ1,2 σ22 . . . σ2σkρ2,k
..
. ... . .. ... σkσ1ρ1,k σkσ2ρ2,k . . . σ2k
(4.2.2)
σi is the standard deviation (volatility) of the ith risk factor and ρi,j is the correlation coefficient of R(ti) and Rt(j), defined by ρi,j := Cov[R(ti),R
(j)
t ]
σiσj . See Appendix A.3 for the derivation of this. Now, under the assumption of normality of the distribution of Rt+δt, given the value of the standard
deviation ofRt+δt, SDev[Rt+δt] =
p
Var[Rt+δt], the VaR can be determined
of business days in a year). VaR is determined as
VaR(absolute) = −|Vt| ×zα×SDev[Rt+δt]×√1
250
= −|Vt| ×zα×
r ωTΣω
250
= −zα×
r
WTΣW
250 (4.2.3)
wherezα is the inverse of the cumulative normal distribution function. The
Chapter 5
Historical Value at Risk
5.1
Classical Historical Simulation
5.1.1 Background
Here the distribution of the returns of the risk factors is determined by drawing samples from the time series of historical returns. This is a non-parametric technique, since no distributional assumptions are made, other than assuming stationarity of the distribution of returns of market variables (in particular their volatility), through time. If this assumption did not hold, the returns would not bei.i.d., and the drawings would originate from different underlying distributions. The assumption does not hold in reality, since as described in [4], volatility changes through time, and periods of high volatility and low volatility tend to cluster together. Historical simulation is a full revaluation technique. A possible problem with the implementation of this method could be a lack of sufficient historical data. Also, comparing this method to Monte Carlo simulation, whereas Monte Carlo will typically simulate about 10000 sample paths for each risk factor, Historical simulation considers only one sample path for each risk factor (the one that actually happened).
5.1.2 Description of Method
The approach is straightforward. Let the window be of size N ≥ 250, to be in accordance with the regulatory requirements for minimum length of observation window. Scenarios are generated by determining a time series of historical day-to-day returns of the market variables over the lastN business days, and then assuming that the return of each market variable fromt to t+ 1 is the same as the return was over each day in the time series.
In other words, as described in [9], ifx(tj)∈xtis the value of a particular market variable at time t, then a set of hypothetical values x(t+1j,i) for all i∈ {t-N, . . . , t-1}is determined by the relationship
ln "
x(tj,i+1) x(tj)
#
= ln "
x(i+1j) x(ij)
#
(5.1.1)
⇒x(t+1j,i) = x(tj).x (j)
i+1 x(ij)
This is done for allj ∈ {1, . . . , k}, to determine the matrixxt(+1j,i), 1≤j≤k, 1≤i≤(N −1), and a full revaluation of each instrument in the portfolio is done for each column using (1.1.1), to determinePi
t+1, i∈ {t-N, . . . , t-1}. From these, we determine Vi
t+1, i ∈ {t-N, . . . , t-1} and sort the results to generate a histogram describing the pmf for the future portfolio value. VaR is then determined using definition (1.1.3), by determining the mean and appropriate percentile of this distribution.
Since interest rates are not taken to be the risk factors, and zero coupon bond prices are, to relate these to the above, letB(t, τ) denote the price of a τ−period zero coupon bond at timet, which corresponds to the continuously compounded annual yield to maturity rt(τ), so B(t, τ) = exp(−rt(τ)τ). Then (5.1.1) becomes
ln "
B(i)(t+ 1, τ) B(t, τ)
#
= ln ·
B(i+ 1, τ) B(i, τ)
¸
⇒ −
h
r(ti+1) (τ)−rt(τ)
i
τ = −[ri+1(τ)−ri(τ)]τ
5.2
Historical Simulation with Volatility Updating
(Hull-White Historical Simulation)
5.2.1 Background
This method is proposed in [2]. It is an extension of traditional Histori-cal Simulation, which does away with the drawback of assuming constant volatility. [2] mentions that the distribution of a market variable, when scaled by an estimate of its volatility, is often found to be approximately stationary. If the volatility of the return of a market variable at the current time t is high, then due to the tendency of volatility to cluster, one would expect a high return at timet+ 1. If historical volatility was in reality low relative to the value at t, however, the historical returns would underesti-mate the returns one would expect to occur fromt tot+ 1. The reverse is true if the volatility is low at timetand the historical volatility is high rela-tive to this. This approach incorporates the exponentially weighted moving average volatility updating scheme, used in the Delta-Normal method, into classical Historical Simulation.
5.2.2 Description of Method
Rather than assuming that the return of each market variable fromttot+1 is the same as it was over each day in the time series, it is now the returns scaled by their volatility which we assume will reoccur. This is described in [9]. Ifx(tj)∈xtis the value of a particular market variable at timet, andσt,j
is the volatility at timetof this market variable, then a set of hypothetical valuesx(t+1j,i) for all i∈ {t-N, . . . , t-1}, is determined by the relationship
1 σt,j
ln "
x(tj,i+1) x(tj)
#
= 1
σi,j
ln "
x(i+1j) x(ij)
#
(5.2.2)
⇒x(tj,i+1) = x(tj) Ã
x(ij+1) x(ij)
!σt,j σi,j
and we proceed as in (section 5.1.2). Relating this to interest rates, using the same notation as above, (5.2.2) becomes
1 σt,j ln
"
B(i)(t+ 1, τ) B(t, τ)
#
= 1
σi,j ln
·
B(i+ 1, τ) B(i, τ)
⇒ − 1
σt,j
h
rt(i+1) (τ)−rt(τ)
i
τ = − 1
σi,j [ri+1(τ)−ri(τ)]τ
⇒r(ti+1) (τ) = rt(τ) +σσt,j
Chapter 6
Monte Carlo Simulation
6.1
Background
Monte Carlo simulation techniques are by far the most flexible and powerful, since they are able to take into account all non-linearities of the portfolio value with respect to its underlying risk factors, and to incorporate all desir-able distributional properties, such as fat tails and time varying volatilities. Also, Monte Carlo simulations can be extended to apply over longer holding periods, making it possible to use these techniques for measuring credit risk. However, these techniques are also by far the most expensive computation-ally. Typically the number of simulations of each random variable needed, in order to get a sample which reasonably approximates the actual distribu-tion, is around 10000.
Like Historical simulation, this is a full revaluation approach. Here, how-ever, rather than drawing samples from the distribution of historical returns, a stochastic process is selected for each of the risk factors, the parameters of the returns process are estimated (again using exponentially weighted moving averages here), and scenarios are determined by simulating price paths for each of these risk factors, over the holding period. The portfolio is revaluated under each of these scenarios to determine a pmf of portfolio values, given by a histogram. VaR is determined as in historical simulation, using definition (1.1.3).
6.2
Monte Carlo Simulation using Cholesky
de-composition
Each bond price corresponding to the set of standard maturities is simu-lated according to its variance-covariance matrix, using (2.4.3). Returns are generated by performing a Cholesky decomposition of the matrix to de-termine the lower triangular matrix L such that Σ = LLT. (A derivation
of Cholesky decomposition is contained in [10]). Then, we can simulate normal random numbers according to this distribution by simulating the in-dependant normal random vectorZ ∼φk(0, I), and calculating the matrix productX=LZ, since we have that E[X] =LE[Z] = 0, and
Var[X] = E[(LZ)(LZ)T] = E[LZZTLT] = LE[ZZT]LT = LLT
= Σ
An issue to note here is that Cholesky decomposition can only be performed on matrices which are positive semi-definite1. Theoretically, this will be the case, since the formula for the variance of a portfolio, given by (4.2.1), where w is a (nonzero) vector of portfolio weights, can never be negative. How-ever, in practice, when dealing with large covariance matrices with highly correlated components, this theoretical property can break down. Thus co-variance matrices should always be checked for positive semi-definiteness before trying to apply Cholesky decomposition (or principal components analysis, which is discussed below). A solution to the problem is described in [11].
6.3
Monte Carlo Simulation using Principal
Com-ponents Analysis
Principal Component Analysis (PCA) provides a way of decreasing the di-mensionality of a set of random variables which are highly correlated. It is in fact often possible to describe a very large proportion of the movements
in these random variables using a relatively small number of principal com-ponents, which can very effectively decrease the computational time needed for simulation. As could be seen in Figure 2.1, the movements of rates along the yield curve are highly interdependant, thus PCA is often applied to the yield curve. The random variables are now taken to be the returns in zero coupon yields at all 24 standard maturities, as opposed to using the bond price returns, as was done in the previous methods considered.
Principal components are hypothetical random variables that are con-structed to be uncorrelated with one another. Suppose we have a vec-tor of returns in zero coupon yields (dropping the subscript t for now) x = (x1, . . . , xk)T. The first step is to determine the normalized k ×1
vector of returns y = (y1, . . . , yk)T where yi = xi/σi2. y is transformed
into a vector of principal components,d = (d1, . . . , dk), where each
princi-pal component is a simple linear combination of the original random vector. At the same time, it is determined how much of the total variation of the original vector is described by each of the principal components.
Suppose thek×kcorrelation matrix ofyis given byρy = [ρij], 1≤i, j≤
k. It is determined from the covariance matrix (4.2.2) ofx, found by expo-nentially weighted moving averages. To define the principal components of y, as described in [12], define the the k×1 vector λ:= (λ1, . . . , λk)T to be
the vector of eigenvalues of ρy, ordered in decreasing order of magnitude.
Also define the k×k matrix ν := [ν(1), . . . , ν(k)], where the columns ν(i), 1 ≤ i ≤ k are the orthonormal3 eigenvectors of ρ
y, corresponding to λi.
The principal components are defined by
d:=νTy (6.3.1)
Sinceν is orthogonal, premultiplying by ν gives
ννTy=y=νd (6.3.2)
⇒yi =d1νi(1)+d2νi(2)+. . .+dkνi(k) (6.3.3)
In other words,y can be determined as a linear combination of the compo-nents. Now, since the new random variablesdi are ordered by the amount
of variation they explain4, considering the ith entry ofy, we get
yi = d1νi(1)+d2νi(2)+. . .+dmνi(m)+εi
≈ d1νi(1)+d2νi(2)+. . .+dmνi(m) (6.3.4)
2The normalized random variables are defined as y
i = (xi−µi)/σi where µi and σi
are the mean and standard deviation ofxi, but as before, we assume a mean return of 0.
The analysis is done on these normalized variables, and once the components have been determined, we simply transform back to the original form of the data.
3Ak×kmatrixU is orthonormal iffUTU =I=U UT.
4The total variation described by theith eigenvector is measured asλ
wherem < kand the error termεi is introduced since we are only using the firstmcomponents. Thesemcomponents are then considered to be the key risk factors, with the rest of the variation iny being considered as noise.
As shown in [13], the principal components di are also orthogonal, in other words they are uncorrelated, so their covariance matrix is just the diagonal matrix of their variances. Also, their variances are equal to their corresponding eigenvaluesλi. This means they can be easily simulated
inde-pendantly, without the need for Cholesky decomposition, which cuts down the computational requirements even further. Now, using the approximation (6.3.4), we can rewrite (6.3.2) as
y≈νbdb (6.3.5)
whereνbis thek×mmatrix of the firstmeigenvectors, anddb= (d1, . . . , dm)T
is anm×1 vector. Simulatingdbenables us to obtain an approximation for y. The more components that are taken, the better the approximation. Here the assumption was made that the yields are lognormally distributed, so by simulating the components according to the normal distribution, we obtain an approximation for the vector of normalized returnsy as a linear combination of these (this is also normally distributed). This is transformed back into the form of the returnsx, from which we can determine a scenario vector for the yields themselves.
Chapter 7
Results
The way in which a VaR model is assessed statistically is by performing a backtest, which determines if the number of times VaR is exceeded is consis-tent with what is expected for the model. The Basel Committee regulatory requirements for the backtesting window for Historical simulation methods is 250 trading days. This is over and above the 250 trading day observation window needed to estimate VaR itself, which means that backtesting can only begin 500 days into the data. There is therefore insufficient historical data to perform a backtest and so a qualitative assessment is done instead. The methods will be tested on various hypothetical portfolios, by estimating VaR for these portfolios over the historical period, and comparing the esti-mates to the actual losses that occurred. Test portfolios consist of individual instruments (a swap or a FRA). A variety of maturities were considered so that some portfolios were only exposed to short term interest rate risk, and others to more medium term interest rate risk. Both long and short posi-tions were considered.
Note that we are interested in the ability of a method to estimate VaR for a specific portfolio, so, for example, if we are estimating VaR of a portfolio consisting of a 3v6 FRA at timet, we are estimating the value of that port-folio one business day into its life, at timet+ 1. When we are at timet+ 1 we are interested in estimating the VaR of a new 3v6 FRA, one business day into its life. In all graphs, the histogram shows the daily profit-and-loss (P&L), and the line graphs show the negative daily VaR of the various methods (negative in order to correspond with the losses of theP&L). From here on, methods are abbreviated as follows.
DN Delta-Normal method
HW Hull-White Historical simulation
MC Monte Carlo simulation using Cholesky decomposition
My code for Monte Carlo simulation using PCA unfortunately has a bug in it which, due to time constraints, I was unable to fix, so the results for this method have not been graphed. Looking at the trends of results, though, the method seems to correspond fairly well to MC, but results are on a much smaller scale.
Figure 7.1 and Figure 7.2 give results for a long position in a 3v6 FRA with a notional principal of R10m, using all methods, at the 95% and 99% confidence levels respectively. Notice that the high period of volatility to-wards the end of 2001, which we saw in Figure 2.1, is very prevalent here, and in all the results. In both the graphs, apart from very slight sampling errors in MC (which was done using 8000 simulations), DN and MC track one another exactly. This is because the FRA is completely linear in the underlying zero coupon bond prices; both methods assumed that the daily bond price returns were multivariate normally distributed; and both meth-ods are using the same volatility and correlation estimates. In this case, therefore, the use of MC is not justified at all, since the computational time required was enormous in comparison to that of DN. This was the case for all portfolios considered, since swaps are completely linear in the underlying bond prices as well.
Now, to consider the performance of the methods, notice how quickly MC and DN react to increases in volatility. This is due to the exponentially weighted moving average technique which places a very high weighting on recent events. Often these methods can overreact to a sudden increase in volatility because of this. Considering Figure 7.1 and Figure 7.2, DN and MC do seem to be overreacting to large losses, relative to the other methods. DN and MC seem to be performing similarly at both the 95% and 99% con-fidence levels (although of course 99% VaR is necessarily higher than 95% VaR).
Consider the performance of the HS. At the 95% confidence level, al-though VaR is not underestimated or overestimated very badly, the method just doesn’t react to changes in P&L. At the 99% confidence level, the method is reacting slightly more, but is overestimating VaR badly. The rea-son it is reacting more, is because the 99% confidence level takes us further into the tails of the distribution. Essentially, what HS does, is to take an unweighted average of the 1st or the 5th percentile of the estimated value dis-tribution, based on a 250 day window. Considering Figure 7.2, the volatile period towards the end of 2001 will therefore contribute significantly, up until the day it drops out of the observation window, at which point the VaR drops dramatically.
drop in VaR of the other methods. However, the reason for the drop is because this is exactly the point where the very volatile from a year ago begins to drop out of the window. By the time we get to February 2003, HS is at its lowest, whilst the other methods are at their highest. At this point, however, it begins to increase again, since there are now enough days in the new window which had relatively high returns. HS then remains high, even though the last four months were very quiet.
Finally, considering HW, at the 95% confidence level, we see that this method is a major improvement on HS. In this particular graph, it performs better than all the other methods. It is reacting well to changes in volatility, yet not overreacting, which is the case with DN and MC.
At the 99% confidence level, HW isn’t performing well at all, however, and is overreacting to changes in volatility even more than DN and HS. There is no obvious explanation for this, and it perhaps merits further in-vestigation.
Figure 7.3 and Figure 7.4 show results for a short position in a 3 year in-terest rate swap, with a notional principal of R1m and quarterly payments, using the 4 methods, at the 95% and 99% confidence levels respectively. Again we see that December 2001 is prevalent. Considering the 95% Con-fidence level, we see that DN and MC are performing very well over most of the period, except for a few months in early 2002 where it is overesti-mating VaR. The performance of HS in this case is almost identicle to DN and MC, and, in this graph, even HS seems to be performing reasonably, although it is overestimating VaR until the volatile period drops out of the window. The 99% confidence level shows up bigger differences in the meth-ods, with DN and MC definitely performing better than HS and HW. HS is again completely overestimating VaR, for the reasons explained above. The deeper into the tails we go, the greater the effect of December 2001 will be on HS, since the 1st percentile would correspond to worse loss than the 5th percentile, which means VaR is overestimated even more.
Figure 7.5 shows results for a long position in a 5 year interest rate swap, with a notional principal of R1m and quarterly payments, at the 95% confidence level. (MC is not included since it is equivalent to DN again.) This longer dated swap is exposed to bond prices at three monthly intervals out to five years. We see a similar pattern to before, with HW reacting best to changes in theP&Lat the 95% confidence level, but the performance of all methods seems to be satisfactory.
Figure 7.1: Long 3v6 FRA at 95% confidence level
Figure 7.3: Short 3 year swap at 95% confidence level
Chapter 8
Conclusions
Bibliography
[1] Basel Committee on Banking Supervision. Amendment to the capi-tal accord to incorporate market risks. www.bis.org/publ/bcbs24.htm, January 1996.
[2] John Hull and Alan White. Incorporating volatility up-dating into the historical simulation method for V@R. Journal of Risk, Fall 1998.
[3] Philippe Jorion. Value at Risk: the new benchmark for controlling market risk. McGraw-Hill, second edition, 2001.
[4] J.P.Morgan and Reuters. RiskMetrics - Technical Document. J.P.Morgan and Reuters, New York, fourth edition, December 18, 1996. www.riskmetrics.com.
[5] John Hull and Alan White. V@R when daily changes are not normal.
Journal of Derivatives, Spring 1998.
[6] James M. Hyman. Accurate monotonicity preserving cubic interpola-tion. SIAM Journal of Statistics and Computation, 4(4):645–654, 1983.
[7] John Hull. Options, Futures, and Other Derivatives. Prentice Hall, fifth edition, 2002.
[8] Robert Jarrow and Stuart Turnbull. Derivative Securities. Second edition, 2000.
[9] Graeme West. Risk Measurement. Financial Modelling Agency, 2003. [email protected].
[10] Gene Golub and Charles Van Loan. Matrix Computations. Third edi-tion, 1996.
[12] Glyn A. Holton. Value at Risk: Theory and Practice. Academic Press, 2003.
Appendix A
Appendix
A.1
The EWMA Model
The exponentially weighted moving average (EMWA) model is the model used by [4] to determine historical volatility and correlation estimates. A moving average of historical observations is used, where the latest observa-tions carry the highest weight in the estimates. This is taken from [9]. If we have historical data for market variablesx0, x1, . . . , xn, first determine the
geometric returns of these variables
ui(x) = lnxxi
i−1,1≤i≤n For time 0, define
σ0(x)2 = 10
n
X
i=1 ui(x)2
Cov0(x, y) = 10
n
X
i=1
ui(x)ui(y),1≤i≤n
For 1 ≤ i ≤ n, the volatilities and covariances are updated recursively according to the decay factorλ, which, in this case, is defined to beλ= 0.94. The updating equations are
σi(x)2=λσi2−1+ (1−λ)u2i250
Covi(x, y) =λCovi−1(x, y) + (1−λ)ui(x)ui(y)250
These equations give an annualized measure of the volatility and covariance. To determine correlations, for 0≤i≤n, set
A.2
Cash Flow Mappping
This is adapted from the description in [4]. Suppose a cashflow occurs at the non-standard maturityt2, wheret2 is bracketed by the standard maturities t1 and t3. The cashflow occurring at time t2 is mapped onto two cashflows occurring att1and t3as follows. Firstly, since bond prices don’t interpolate without further assumptions, the interpolation is done on yields. Lety1,y2, and y3 be the continuously compounded yields corresponding to maturities t1, t2, and t3 respectively, so B(t1) = exp (−y1t1), B(t2) = exp (−y2t2), B(t3) = exp (−y3t3). Let σ1, σ2 and σ3 be the volatilities of these bond prices. The procedure is to firstly linearly interpolate betweeny1 and y3 to determine y2, and to linearly interpolate between σ1 and σ3 to determine σ2. We want a portfolio consisting of the two assets B(t1) and B(t3) with relative weights ω and (1−ω) invested in each, such that the volatility of this portfolio is equivalent toσ2. The variance of the portfolio is given by (4.2.1), and so we have
σ22 = £ ω (1−ω) ¤ ·
σ12 σ1σ3ρ13 σ3σ1ρ13 σ23
¸ · ω (1−ω)
¸
= ω2σ12+ 2ω(1−ω)ρ13σ1σ3+ (1−ω)2σ23
whereρ13 is the correlation coefficient ofB(t1) andB(t3). Rearranging the above equation gives a quadratic equation inω:
ω2σ21+ 2ω(1−ω)ρ13σ1σ3+ (1−ω)2σ32−σ22 = 0
⇒(σ12−2ρ13σ1σ3+σ32)ω2+ (2ρ13σ1σ3−2σ32)ω+ (σ23−σ22) = 0
⇒aω2+bω+c = 0
where
a = σ12−2ρ13σ1σ3+σ32 b = 2ρ13σ1σ3−2σ32 c = σ32−σ22
A.3
The Variance of the Return on a Portfolio
The Variance of the return of a portfolio of assets, based on Markowitz portfolio theory, is given by the following, which is derived in [9].
Var[Rt] = E[(Rt−E[Rt])2]
= E Ã k X i=1
wi(Rt,i−E[Rt])
!2
= E
Xk
i=1
k
X
j=1
wiwj(Rt,i−E[Rt])(Rt,j−E[Rt])
= k X i=1 k X j=1
wiwjE[(Rt,i−E[Rt])(Rt,j −E[Rt])]
= k X i=1 k X j=1
wiwjCov[Rt,i, Rt,j]
= k X i=1 k X j=1
wiwjρi,jσiσj
whereσi is the standard deviation (volatility) of theith risk factor and ρi,j
is the correlation coefficient ofRt,i andRt,j, defined byρi,j := Cov[σRit,iσj,Rt,j].
(A.3.1) can be written in matrix form as
Var[Rt] =ωTΣω
where Σ is the Variance-Covariance matrix given by
Σ = σ2
1 σ1σ2ρ1,2 . . . σ1σkρ1,k
σ2σ1ρ1,2 σ2
2 . . . σ2σkρ2,k
..
. ... . .. ... σkσ1ρ1,k σkσ2ρ2,k . . . σ2
Appendix B
Appendix
B.1
VBA Code: Bootstrapping Module
Option Explicit
Public Sub generateCurves()
Dim numRates As Integer ’number of rates included in the array of market yields Dim i As Integer, j As Integer, col As Integer
Dim writerow, writecol As Integer Dim d As Date
Dim curveCount As Integer, readrow As Integer Dim SCB() As Object
Dim curve() As Double
’declare an array of standard days (out to 30 years) for which NACC rates will be written ’to the spreadsheet (these correspond approximately to the 365 day count used in SA) Dim stdVerts As Variant
stdVerts = Array(1, 30, 91, 182, 273, 365, 456, 547, 638, 730, 1095, 1460, 1825, _ 2190, 2555, 2920, 3285, 3650, 4380, 5475, 6205, 7300, 9125, 10950) Const stdVertCount As Integer = 24
Application.ScreenUpdating = False numRates = 24
’determine the number of curves in the historical data With Sheets("Hist Data")
readrow = 2 curveCount = 0
Do Until .Cells(readrow + 1, 1) = "" readrow = readrow + 1
ReDim SCB(1 To curveCount) For i = 1 To curveCount
Set SCB(i) = CreateObject("YieldCurve.SwapCurveBootstrap") Next i
’read data into the SCB objects For i = 1 To curveCount
Application.StatusBar = "Processing data for curve " & i col = 1
SCB(i).Effective_Date = .Cells(2 + i, 1) SCB(i).IntMethod = "MPC"
For j = 1 To numRates
’avoid leaving gaps in the arrays in the case where some rates are missing If .Cells(2 + i, 1 + j) <> "" Then
SCB(i).Values(col) = .Cells(2 + i, 1 + j) SCB(i).Rate_Type(col) = .Cells(2, 1 + j)
SCB(i).Rate_Term_Description(col) = .Cells(1, 1 + j) col = col + 1
End If Next j
SCB(i).Top_Index = col - 1 Next i
End With ’sheets("Hist Data")
’generate the NACC spot and forward curves and output With Sheets("NACC Swap Curves")
.Range(.Cells(1, 1), .Cells(11000, 256)).ClearContents For writecol = 1 To stdVertCount
.Cells(1, writecol + 1) = stdVerts(writecol - 1) Next writecol
writerow = 2
For i = 1 To curveCount
Application.StatusBar = "Generating curve " & i
ReDim curve(1 To (SCB(i).Curve_Termination_Date - SCB(i).Effective_Date + 1)) For d = SCB(i).Effective_Date + 1 To SCB(i).Curve_Termination_Date
curve(d - SCB(i).Effective_Date) = SCB(i).Output_Rate(d) Next d
.Cells(writerow, 1) = SCB(i).Effective_Date .Cells(writerow, 1).NumberFormat = "d-mmm-yy" For writecol = 1 To stdVertCount
.Cells(writerow, writecol + 1) = curve(stdVerts(writecol - 1)) Next writecol
writerow = writerow + 1 Next i
End With ’Sheets("NACC Swap Curves") For i = 1 To curveCount
Set SCB(i) = Nothing Next i
Application.StatusBar = "Done!" Beep
B.2
VBA Code: VaR Module
Option Explicit
Private P() As Double
Private vol() As Double, covol() As Double Private volR() As Double, covolR() As Double Private dates() As Date
Private n As Integer ’# rows Private stdVerts() As Variant Const m As Integer = 24 ’# cols Const window = 250
Public Sub main()
Const lambda As Double = 0.94, confidenceLevel As Double = 0.95 ’0.95
Dim i As Integer, j As Integer, k As Integer, readrow As Integer, readcol As Integer Dim data1 As Range, data2 As Range, data3 As Range
’data1 is a row of dates, data2 is the matrix of market variables through time. stdVerts = Array(1, 30, 91, 182, 273, 365, 456, 547, 638, 730, 1095, 1460, 1825, _
2190, 2555, 2920, 3285, 3650, 4380, 5475, 6205, 7300, 9125, 10950) With Sheets("NACC swap curves")
readrow = 2 n = 0
Do Until .Cells(readrow + 1, 1) = "" readrow = readrow + 1
n = n + 1 Loop n = n + 1
Set data1 = .Range(.Cells(2, 1), .Cells(n, 1)) Set data2 = .Range(.Cells(2, 2), .Cells(n, m)) ReDim dates(0 To n)
For i = 0 To n - 1
dates(i) = data1.Cells(i + 1, 1) Next i
dates(n) = dates(n - 1) + 1 End With
Application.StatusBar = "Estimating Parameters..." Call emwa(data2, lambda)
With Sheets("Disc factors")
Set data3 = .Range(.Cells(3, 2), .Cells(n + 1, m)) End With
Call profitAndLoss(data2)
Application.StatusBar = "Calculating Historical VaR..." Call histVar(data2, confidenceLevel)
Call deltaNormal(data2, confidenceLevel) Call monteCarlo(data2, 0.99)
Call doPCA(data2, confidenceLevel) Application.StatusBar = "Done!" End Sub
ReDim P(1 To n - 1, 1 To m) ReDim vol(0 To n - 1, 1 To m)
ReDim covol(0 To n - 1, 1 To m, 1 To m) For i = 1 To n - 1
For j = 1 To m
P(i, j) = (data.Cells(i, j) - _
data.Cells(i + 1, j)) * stdVerts(j - 1) / 365 ’bond price log returns Next j
Next i
’get initial vols and covols ReDim sum(1 To m)
ReDim sum2(1 To m, 1 To m) For k = 1 To 25
For j = 1 To m
sum(j) = sum(j) + P(k, j) ^ 2 For i = 1 To m
sum2(j, i) = sum2(j, i) + P(k, j) * P(k, i) Next i
Next j Next k
For j = 1 To m
volR(0, j) = (10 * sum(j)) ^ 0.5 For k = 1 To m
covol(0, j, k) = sum2(j, k) * 10 Next k
Next j
’rolling calculator for vols and covols For i = 1 To n - 1
For j = 1 To m
volR(i, j) = (lambda * (volR(i - 1, j) ^ 2 + (1 - lambda) * (P(i, j) ^ 2) * 250)) ^ 0.5 For k = 1 To m
covol(i, j, k) = lambda * covol(i - 1, j, k) + _ (1 - lambda) * P(i, j) * P(i, k) * 250 Next k
Next j Next i
Call displayVols("vols", vol, dates, n, m) Call displayCovars("rate covar", covolR, n, m) End Sub
Public Sub histVar(data As Range, confidenceLevel As Double)
Dim i As Integer, j As Integer, today As Integer, vposn As Integer, k As Integer Dim hs_v(1 To window) As Double ’portfolio values for each scenario
Dim hw_v(1 To window) As Double
Dim hsPercentile As Double, hwPercentile As Double
Dim hsRateScenario(0 To m - 1) As Double ’Historical simulation Dim hwRateScenario(0 To m - 1) As Double ’Hull White Historical Dim hsVar() As Double, hwVar() As Double
Dim hsSum As Double, hwSum As Double, percentile As Double
ReDim hsVar(1 To n - window) ReDim hwVar(1 To n - window)
Application.StatusBar = "Busy with historical VaR for " & dates(today - 1) vposn = 1
hsSum = 0 hwSum = 0
For i = today - window To today - 1 For j = 1 To m
hsRateScenario(j - 1) = data.Cells(today, j) + _ data.Cells(i + 1, j) - data.Cells(i, j) hwRateScenario(j - 1) = data.Cells(today, j) + _
vol(today - 1, j) / vol(i - 1, j) * (data.Cells(i + 1, j) - data.Cells(i, j)) Next j
’contract entered into today, we are interested how much we could lose on it tomorrow: ’hs_v(vposn) = valueFRA(hsRateScenario, stdVerts, today, dates(today - 1), dates(today)) ’hs_v(vposn) = valueSwap1(hsRateScenario, stdVerts, today, dates(today - 1), dates(today)) hs_v(vposn) = valueSwap2(hsRateScenario, stdVerts, today, dates(today - 1), dates(today)) ’hw_v(vposn) = valueFRA(hwRateScenario, stdVerts, today, dates(today - 1), dates(today)) ’hw_v(vposn) = valueSwap1(hwRateScenario, stdVerts, today, dates(today - 1), dates(today)) hw_v(vposn) = valueSwap2(hwRateScenario, stdVerts, today, dates(today - 1), dates(today)) hsSum = hsSum + hs_v(vposn)
hwSum = hwSum + hw_v(vposn) vposn = vposn + 1
Next i
quickSort hs_v quickSort hw_v
percentile = window * (1 - confidenceLevel) If Round(percentile) = percentile Then
hsVar(today - window) = hsSum / (n - window) - hs_v(percentile) hwVar(today - window) = hwSum / (n - window) - hw_v(percentile) Else ’interpolate
hsVar(today - window) = hsSum / (n - window) - 0.5 * (hs_v(Round(percentile)) _ + hs_v(Round(percentile) - 1))
hwVar(today - window) = hwSum / (n - window) - 0.5 * (hw_v(Round(percentile)) _ + hw_v(Round(percentile) - 1))
End If Next today
With Sheets("long swap") For i = 1 To n - window
.Cells(window + 3 + i, 2) = hsVar(i) .Cells(window + 3 + i, 4) = hwVar(i) Next i
End With End Sub
Public Sub doPCA(data As Range, confidenceLevel As Double) Dim i As Integer, readrow As Integer, corr() As Double
Dim today As Integer, pcaCorr() As Double, pcaCov() As Double, k As Integer Dim v() As Double ’the 5 eigenvects corresp to the largest evals
Dim sqrtLambda() As Double, lambdaTruncated(1 To 3, 1 To 3) As Double Dim rates() As Double, j As Integer, sum As Double, percentile As Double Dim rateScenario() As Double, vols() As Double
Dim u(1 To 3) As Double, z(1 To 3, 1 To 1) As Double Dim vals() As Double, mcVar() As Double, result As Variant
ReDim sqrtLambda(1 To m, 1 To m)
ReDim v(1 To m, 1 To 3), rates(0 To m - 1) ReDim rateScenario(0 To m - 1), vals(1 To 8000) ReDim mcVar(1 To n), vols(0 To m - 1)
Dim A As Double Dim summ As Double Dim l As Integer
Randomize readrow = 2 For today = 1 To n
sum = 0
Application.StatusBar = "Busy with PCA for " & dates(today - 1) With Sheets("rate covar")
Call covarToCorr(corr, .Range(.Cells(readrow, 1), .Cells(readrow + m, m)), m) For j = 1 To m
rates(j - 1) = data.Cells(today, j) vols(j - 1) = volR(today - 1, j) Next j
A = 0
For j = 1 To 24
A = A + vols(j - 1) ^ 2 Next j
A = Sqr(A / 24 / 250)
Call findComponents(sqrtLambda, lambdaTruncated, pcaCorr, v, m, corr) ’need to convert the corr matrix into a cov matrix
For i = 1 To m For j = 1 To m
pcaCov(i, j) = pcaCorr(i, j) * vols(i - 1) * vols(j - 1) Next j
Next i
’now we can simulate the components (which are independant) For k = 1 To 8000
For i = 1 To 3 u(i) = Rnd()
If u(i) > 0.999999 Then u(i) = 0.999999 If u(i) < 0.000001 Then u(i) = 0.000001
z(i, 1) = Application.WorksheetFunction.NormSInv(u(i)) ’std normal random numbers Next i
For i = 1 To 5
lambdaTruncated(i, i) = lambdaTruncated(i, i) ^ 0.5 Next i
result = Application.WorksheetFunction.MMult(v, lambdaTruncated) result = Application.WorksheetFunction.MMult(result, z)
summ = 0 For j = 1 To m
rateScenario(j - 1) = rates(j - 1) + A * result(j,1) Next j
’vals(k) = valueFRA(rateScenario, stdVerts, today, dates(today - 1), dates(today)) ’vals(k) = valueSwap1(rateScenario, stdVerts, today, dates(today - 1), dates(today)) vals(k) = valueSwap2(rateScenario, stdVerts, today, dates(today - 1), dates(today)) sum = sum + vals(k)
readrow = readrow + m End With
quickSort vals
percentile = 8000 * (1 - confidenceLevel) If Round(percentile) = percentile Then
mcVar(today) = sum / 8000 - vals(percentile) Else ’interpolate
mcVar(today) = sum / 1000 - 0.5 * (vals(Round(percentile)) _
+ vals(Round(percentile) - 1)) ’sum / 8000 - 0.5 * (vals(Round(percentile)) _ End If
Next today
With Sheets("long swap") For i = 1 To n
.Cells(3 + i, 15) = mcVar(i) Next i
End With End Sub
Public Sub findComponents(ByRef sqrtLambda() As Double, ByRef lambdaTruncated() _ As Double, ByRef pcaCorr() As Double, ByRef v() As Double, size As Integer, _ corr() As Double)
Dim evals As Variant, evecs As Variant Dim i As Integer, j As Integer
Dim result As Variant, inv As Variant Dim eigval() As Double, count As Double
ReDim eigval(1 To size)
result = Application.Run("NTpca", corr) ’get eigenvalues and eigenvectors For i = 1 To size
eigval(i) = result(1, i) For j = 1 To size
If i = j Then
sqrtLambda(i, i) = result(1, i) ^ 0.5 End If
Next j Next i
For count = 1 To 3 For i = 2 To size + 1
v(i - 1, count) = result(i, count) Next i
Next count
Call getCovPC(lambdaTruncated, eigval) With Applica