程序代写代做代考 matlab algorithm FMO6

FMO6
FMO6 Lecture 7
Dr John Armstrong King’s College London August 3, 2016

FMO6
Risk Management
Risk Management

FMO6
Risk Management
Moderating the behaviour of traders
Traders are not allowed to buy and sell whatever they want. Here are the kind of constraints a risk manager would impose on a trader:
The maximum position in any one asset should be limited. The maximum position in any market sector should be limited. The maximum sensitivity to a change in the stock price should be limited.
More generally the maximum risk that a trader can take should be limited.
In addition, a risk manager will want to encourage sensible risk reduction practices:
Traders should diversify
Traders should hedge to lock in pro􏺉ts
All other things being equal, traders should choose the least risky strategy.

FMO6
Risk Management
Regulators
Regulators wish to ensure that bank depositors’ money is safe. They impose limits on how big a risk a bank can take.
They wanted to make sure that they never needed to bail out banks with trillions of dollars of tax payers money.
They want to make sure they don’t have to do it again. (Oops!)

FMO6
Risk Management
Incentives for Traders
Traders are typically payed a bonus determined by how much money they make.
If they make a lot of money for the bank, they earn a lot.
If they lose money, the worst that can happen is they lose their job…
The job of the risk manager is to control the resulting behaviour and to prevent Traders taking enormous risks.

FMO6
Risk Management
Shareholder and management incentives
Senior management have similar incentives. They can take home huge bonuses. Its the depositors and the shareholders who will have to pay the costs. E.g. Fred Goodwin: let’s buy ABN Amro, what’s the worst that could happen?
Shareholders have similar incentives. They’re can use depositors money for leverage. The worst that can happen is that the stock becomes worthless, who cares what happens to deposits.
If things get really bad, the government will probably bail us out… again.

FMO6
Risk Management
Risk management
The purpose of risk management in a bank is not typically to minimize risk!
The role of risk management is to use risk most e􏺈ectively. The regulators limit the maximum risk.
How much money can we make within the regulators constraints?
Summary of role
Make sure enough risk is being taken in 99% of cases
Make sure that nothing catastrophic happens in 1% of cases

FMO6
Risk Management
Thinking like a trader
Suppose that you have no risk manager
A stock price follows the Black Scholes model with a drift of
10%. and a volatility of How would you trade?

FMO6
Risk Management
Basel II
Basel is a city in Switzerland where bankers met to come up with an international regulatory framework.
Pillar I: Minimum Capital Requirements
The risks a bank can take are limited by the amount of
shareholder capital
There is a standard methodology for measuring the risks
Pillar II: Supervisory Review Process
Banks must have a risk management process that evaluates
and assures capital adequacy
This must be subject to external review
Pillar III: Market Discipline
Banks must publish information on their capital and risk so others can evaluate the bank for themselves.

FMO6
Risk Management
VaR
Basel II identi􏺉ed Value at Risk as the standard measure of risk that banks should use.
The de􏺉nition of Value at Risk requires you to choose a model for security prices. Once this model is chosen:
De􏺉nition
The p%, d-day Value at Risk of a position is the maximum amount of money you expect to lose over an d day period in the p% best case scenarios.
It is the current value of the position minus the lower
(100 − p)%-percentile of the distribution of future values of the position. This means that risky positions have positive Value at Risk.
Slightly di􏺈erent de􏺉nitions are possible. We are using the precise de􏺉nitions used by RiskMetrics for clarity.

FMO6
Risk Management
RiskMetrics
Return to RiskMetrics: The Evolution of a Standard Jorge Mina and Jerry Yi Xiao
RiskMetrics was a commercial risk management package that popularized VaR
They de􏺉ne various techniques of computing VaR in detail. We’ll use their de􏺉nitions today.

FMO6
Risk Management
Three methodologies
Monte Carlo VaR Historic VaR Parameteric VaR

FMO6
Monte Carlo VaR
Monte Carlo VaR

FMO6
Monte Carlo VaR
Monte Carlo VaR algorithm
Algorithm
Simulate a large number of price paths of the underlyings in the P measure over an d-day horizon.
For each price path, compute the value of your position on day d.
Read o􏺈 the (100 − p)% percentile of the distribution. Subtract this from the current market price of the position. This gives you an approximation to the p%, d-day VaR.
You might argue that it would be better to discount the 􏺉nal price by the risk free rate before subtracting it from the current price. This de􏺉nition is trying to follow the RiskMetrics de􏺉nitions. The risk free rate is dwarfed by the volatility so for stocks over a short time horizon the di􏺈erence isn’t interesting.

FMO6
Monte Carlo VaR
MATLAB implementation
function [ var ] = monteCarloVar( …
percent,days, …
strike, maturity, …
spot, drift, volatility, …
riskFreeRate, …
nPaths)
t = days/365;
stockPrices = generateBSPaths( …
t, spot, drift, volatility,…
nPaths, 1);
prices = blackScholesCallPrice( strike, maturity-t, …
stockPrices,riskFreeRate,volatility );
endPrice = prctile( prices, 100-percent );
startPrice = blackScholesCallPrice( …
strike, maturity, …
spot,riskFreeRate, volatility );
var = startPrice – endPrice;
end

FMO6
Monte Carlo VaR
Monte Carlo VaR con􏺉dence interval
Suppose we have computed the p% d-day VaR using m samples.
We want to compute a q% con􏺉dence interval. Letα=p/100,so0≤α<1. β=q/100. Let m be the number of samples created. De􏺉ne: r 􏶫α(1−α) 􏰔1−β􏰕 =α+ N−1 100 m 2 s 􏶫α(1−α) 􏰔1−β􏰕 =α− N−1 100 m 2 With q% con􏺉dence, the p% VaR 􏺉gure lies between the r% Var estimate and the s% VaR estimate. Justi􏺉cation: see FM05. FMO6 Monte Carlo VaR Monte Carlo VaR Summary Calculate value at risk by simulating price changes and reading o􏺈 the desired percentile. Good points Highly 􏺎exible, you can use any pricing model and compute VaR for any security that you know how to price. Intuitive and easy to program assuming you can already simulate your stochastic model and price your securities. Bad points Slow. We may have to run tens of thousands of scenarios and then price the security in each scenario. This may require an additional Monte Carlo simulation if the security is exotic. Thus we can easily need to generate hundreds of millions of scenarios in total. Subjective. Depends heavily upon the choice of model to generate prices, but which model is correct? Only as good as your model. If your model doesn't have fat tails, you will underestimate risk. FMO6 A standard model for the risk factors A standard model for the risk factors FMO6 A standard model for the risk factors Problem From a regulatory point of view, this VaR calculation is not enough to limit risk The choice of model is subjective How should μ and σ be chosen? We need standard models and standard ways of calibrating them to the market. FMO6 A standard model for the risk factors Multidimensional log normal model In the RiskMetrics methodology all 􏺆risk factors􏺊 are assumed to follow a multidimensional log normal process. Let P(1), P(2), . . . P(n) be the risk factors that a􏺈ect your position. The log return of a risk factor P(i) is de􏺉ned by: r(i) =log(PT) t,T pt We assume that log returns are normally distributed. r(i) = (μ − 1(σ(i))2)(T − t) + σ(i)ε(i)√T − t t,T 2 Where ε(i) is normally distributed with mean 0 and standard deviation 1 and Cov(ε(i),ε(j)) = ρ(i,j) for some correlation matrix ρ(i,j). FMO6 A standard model for the risk factors Choosing the drift term μ(i) What should we take as the drift?. This is not measurable in practice so we need a standard. Risk metrics say we should take μ (i) = 1 2 σ (i)2 . This means that log returns have mean 0. Notice in practice, σ has a far bigger e􏺈ect on the VaR than the choice of μ so this arbitrary decision isn't very signi􏺉cant. FMO6 A standard model for the risk factors Calibrating σ Let us consider a single factor model √ rt,T=σε T−t Write ri for the overnight return from day i to day i − 1. Note that i is in units of days and t is in units of years. ri = σε􏶣1/365 So 365 E(ri2) = σ2 Hence 365ri2 gives an estimate for σ2. FMO6 A standard model for the risk factors Weighted average Historic data series gives us lots of estimates, for σ2, one for each day. Presumably the more recent data more closely re􏺎ects the values of σ we should expect in the short term than the older data. Therefore we take a weighted average of the estimates, giving higher weights to recent data. Give the most recent data weight 1, the next most recent weight λ, the next most recent weight λ2 etc. for some choice of λ. FMO6 A standard model for the risk factors EWMA De􏺉nition Suppose we have historic return data for m + 1 days, then the exponentially weighted moving average (EWMA) estimate for σ is given by: 1 − λ 􏰃m σ2 =365× λjr2 1−λm+1 i−j j=0 for some choice of weighting parameter 0 < λ < 1. Riskmetrics recommends using λ = 0.94 for one day volatility and λ = 0.97 for one month volatility. For λ = 0.94 you only need 112 days of historic data to be accurate within 0.01%. For λ = 0.97 you only need 227 days of historic data. FMO6 A standard model for the risk factors EWMA for n risk factors The formula for n-risk factors is a simple generalization of the 1-dimensional case. 1−λ m Σ=σ(a)σ(b)ρ(a,b) =365× 􏰃λjr(a)r(b) Σ is the covariance matrix 1−λm+1 i−j i−j j=0 I used Ω for covariance matrices last week, but Σ is more standard so I'll switch convention for the rest of the course. FMO6 A standard model for the risk factors Coping with missing data RiskMetrics doesn't say what you should do about weekends and other days where no trading occurred. I recommend that you: Take the log of the risk factors each day they were traded Linearly interpolate missing data Now use RiskMetrics formulae. FMO6 A standard model for the risk factors MATLAB implementation function sigmaEstimate = ewma( prices, lambda ) %EWMA Compute the exponentially weighted moving average % of the returns logPrices = log( prices ); logReturns = diff( logPrices ); m = length( logReturns)-1; total = sum(lambda.^(0:m) .* logReturns.^2); sigmaSquaredEstimate = (1-lambda)/(1-lambda^(m+1))*total*365; sigmaEstimate = sqrt( sigmaSquaredEstimate ); end FMO6 Historic VaR Historic VaR Monte Carlo VaR relies on having a good model of returns on risk factors. Unfortunately there is no general agreeement on what the right model is? So why not use historic returns and assume that a similar pattern will be repeated. This approach is called historic VaR. FMO6 Historic VaR Historical VaR Algorithm Algorithm Suppose that we have m + 1 days of historical returns for N risk factors. r(a) is the return of risk factor a on day i. For each day i in our sample we generate a simulated d-day return by the formula: (a)√ ri d i We use these simulated returns to simulate the values of our risk factor on day d We then compute the VaR by reading o􏺈 the desired percentile. FMO6 Historic VaR Discussion We have used the familiar scaling properties of volatility and have assumed these hold for the risk factor under consideration. You could look at non overlapping historic d-day return values instead of doing this scaling, but that will not be practical for larger d due to the lack of historic data. FMO6 Historic VaR MATLAB code function [ var ] = historicVar( ... percent,days, ... strike, maturity, ... spot, historicPrices, ... riskFreeRate, volatility) dailyLogReturns = diff( log( historicPrices )); dDayLogReturns = dailyLogReturns .* sqrt( days ); stockPrices = exp(dDayLogReturns) * spot; t = days/365; prices = blackScholesCallPrice( strike, maturity-t, ... stockPrices,riskFreeRate,volatility ); endPrice = prctile( prices, 100-percent ); startPrice = blackScholesCallPrice( ... strike, maturity, ... spot,riskFreeRate, volatility ); var = startPrice - endPrice; end FMO6 Historic VaR Historic VaR summary If you can compute Monte Carlo VaR and have access to historic data, computing historic VaR is easy. Good points Historic VaR is less subjective than Monte Carlo VaR. Historic VaR may show fat tails behaviour, this is an important component of risk. As simple to calculate as Monte Carlo Var Bad points Relies on the assumption that the past will predict the future Not particularly accurate due to lack of historic data. FMO6 Parametric VaR Parametric VaR Let V be the price of a security that depends upon risk factors P(1), P(2), ..., P(n) De􏺉ne p(a) = log P(a). De􏺉ne δ(a) = ∂V = P((a)) ∂V ∂p(a) ∂P(a) In other words δ(a) is the sensitivity of the security price to the log return of P(a). FMO6 Parametric VaR Parameteric VaR We have the following Taylor series for V . V =V0 +􏰃δ(a)r(a) a Where r is the log return. Therefore to 􏺉rst order, the distribution for the change in V over a d-day period is normally distributed with mean 0 and standard deviation: 􏶫dδTΣδ 365 Here δ is the vector with components δ(a). Therefore the p% d-day VaR is given, to 􏺉rst order, by N−1􏰒 p 􏰓􏶫dδTΣδ 100 365 FMO6 Parametric VaR Parameteric VaR algorithm We can use the EWMA algorithm from earlier to estimate the matrix Σ. Thus we have a simple 􏺉rst order algorithm for estimating VaR. Algorithm Compute the sensitivities of V δ(a)=P(a) ∂V ∂P(a) Note that in the case where P is a stock, S this is S∆. Use the formula VaR≈N−1􏰒 p 􏰓􏶫dδTΣδ 100 365 FMO6 Parametric VaR Parameteric VaR Summary Good points: It's extremely quick and easy to calculate Bad points: For nonlinear securities such as call options, it is unlikely to be very accurate. It is tied 􏺉rmly to the multivariate normal distribution so will never account for fat tails. FMO6 Discussion Which VaR should I use? Given all these options, which VaR calculation should you use? All of them. Use Monte Carlo for a potentially more accurate 􏺉gure that re􏺎ects your beliefs about the market Use Historic VaR to backtest your Monte Carlo prices - do they really seem plausible? Use parametric VaR for rapid intra day recalculation of VaR. (Or innovate: this is an opportunity for your bank to be able to allocate money to the right place, so its a chance to gain a commercial edge) FMO6 Discussion Criticisms of VaR It ignores risk in the tails It is not sub-additive De􏺉nition A risk measure is sub-additive if the sum of the risk of two separate portfolios is greater than or equal to the risk of the combined portfolio. For sub-additive risk measure, if you diversify you will reduce your risk. Thus sub-additive risk measures encourage diversi􏺉cation. In an in􏺎uential paper, Artzner et al. de􏺉ned the concept of a 􏺆coherent risk measure􏺊. By de􏺉nition a coherent risk measure must be sub-additive, so VaR is not a 􏺆coherent risk measure􏺊. FMO6 Discussion Coherent risk measure De􏺉nition A coherent risk measure has the following properties Sub-additive Scaling: if you multiply the number of each asset held by n > 0, the risk increases by a factor of n.
Montonicity: if portfolio A can never out perform portfolio B, then portfolio A is riskier than portfolio B
Translation invariance: If you add cash to your portfolio, the risk increases by the same amount.
Note, the translation invariance assumes that you measure the risk of a position in terms of 􏺉nal value not in terms of change of value. So VaR isn’t translation invariant, but the 100 − p-th percentile of your loss distribution is translation invariant.

FMO6
Discussion
Example
Let X and Y be independent stocks.
We sell digital put options on X and Y with maturity in d days and strikes chosen such that the probability of them ending in the money is only 4%.
The 95% d-day value at risk of being short a put on X is zero since we only pay out 4% of the time.
The 95% d-day value at risk of being short a put on Y is zero since we only pay out 4% of the time.
The probability of one or other of the options ending up in the money is 1 − (0.96)(0.96) = 0.0784.
Therefore the 95% d-day value at risk of the portfolio is greater than 0.
Therefore VaR is not sub-additive.

FMO6
Discussion
How important is this?
The (obvious) fact that you can hide losses in the tails seems more important to me than the lack of sub-additivity.
As our example shows, the lack of sub-additivity comes from the fact that you can hide losses in the tails.
Price is a coherent risk measure, but I wouldn’t use it for risk management!
Is our example contrived?
You wouldn’t naturally come up with such a portfolio
On the other hand you might come up with such a portfolio if you were trying to maximize your bonus
Trader’s will seek weaknesses in your risk management.

FMO6
Discussion
CVaR – Expected shortfall
De􏺉nition
The p% d-day CVaR is the expected loss in the worst (100 − p)% of cases.
CVaR is also known as:
expected shortfall average value at risk

FMO6
Discussion
CVaR advantages and disadvantages
Advantages
It is quite easy to understand and explain to non-specialists It is a coherent risk measure
It doesn’t completely ignore the risk in the tail
It has some nice convexity properties which make it easy to use in optimizations
Disadvantages
It is more computationally expensive to calculate than VaR.
It is di􏺍cult to back test using historic data. It is not 􏺆elicitable􏺊.
It uses expectations in the tail, so it is e􏺈ectively 􏺆risk neutral􏺊 in the tail
It requires us to model the tail accurately, but that is the part of the model we understand least well.

FMO6
Discussion
VaR advantages and disadvantages
Advantages
It is easy to understand and explain to non-specialists
It is easy to back test – simply check whether real losses exceeeded the VaR the given percentage of times. The validity of this test does not depend on any strong assumptions about the distribution of returns.
Disadvantages
It ignores risk in the tail
It is not a coherent risk measure
It is fairly expensive to calculate Monte Carlo VaR, especially for exotics. But it is better than CVaR in this respect.

FMO6
Discussion
Other risk measures
Many other risk measures exist. Standard deviation
Expected utility for utility function u Expected utility in the worst 95% of cases …
The notion of 􏺆coherent risk measure􏺊 isn’t quite general enough. The scaling requirement is unnecessarily restrictive. So replace the scaling and the sub-additivity property with convexity:
If p and q are portfolios with risk r(p) and r(q), then the risk of the portfolio λp + (1 − λ)q for λ ∈ [0, 1] should be
≤ λr(p) + (1 − λ)r(q).
This de􏺉nes a 􏺆convex risk measure􏺊.

FMO6
Discussion
Basel II advantages and disadvantages
Advantages
Market transparency seems good on the face of it.
If everyone used a di􏺈erent methodology it would be hard to evaluate banks, so consistency seems a good idea. Regulation to prevent banks taking excessive risk seems necessary to prevent the need for government bail outs.
Disadvantages
The methodology for evaluating risk in Basel II is overly simplistic. In particular the evluation of credit risk is highly suspect.
If everyone is using the same methodology to compute risk and operating under similar constraints, this might lead to herd behaviour and hence crashes.
Any methodology to compute risk may lead to over con􏺉dence that risks are being properly accounted for.

FMO6
Discussion
Basel III
Basel III is a response to the 􏺉nancial crisis
Increase the amount of shareholder capital required for given levels of risk
Leverage ratio limit on ratio of tier I capital to total assets Liquidity coverage ratio
Use expected shortfall rather than VaR

Note that simple log normal models would not be considered su􏺍ciently conservative by modern standards as they underestimate risk in the tails. Models such as GARCH, student t-GARCH and from extreme value theory are likely to be preferred.

FMO6
Discussion
Wise words
According to Donald Rumsfeld:
As we know, there are known knowns; there are things we know that we know. There are known unknowns; that is to say, there are things that we now know we don’t know. But there are also unknown unknowns 􏺌 there are things we do not know we don’t know.
Risk measures can measure the known unknowns, but not the unknown unknowns.

FMO6
Mock exam question
Mock exam question

FMO6
Mock exam question
Mock exam question – part (i)
What is meant by VaR and CVaR? (20%)

FMO6
Mock exam question
Solution (i)
p% d-day VaR is minus 1 times maximum loss that a portfolio will experience over a d-day period for the p% best case scenarios. The p% d-day CVaR is the expected loss for the (100 − p)% worst case scenarios.

FMO6
Mock exam question
Mock exam question – part (ii)
What is the sub-additivity property of a coherent risk measure? Show that VaR is not sub-additive. (20%)

FMO6
Mock exam question
Solution (ii)
A risk measure is said to be sub-additive if it always measures the risk of a combined portfolio p + q to be less than the sum of the risks of the individual portfolios.
Consider the 95% VaR. One can sell a digital put option p on a stock such that the probability of losing money is 4%. One constructs a similar option q on an independent stock. The VaR of p and q independently is zero, but the VaR of p+q will be positive since (1 − 0.962) > 0.05.

FMO6
Mock exam question
Mock exam question – part (iii)
Write a di􏺈erence equation you could use to simulate a stock price that follows the Black-Scholes model. (20%)

FMO6
Mock exam question
Solution (iii)
Let si denote the log of the stock price at time point iδt Let Si denote the stock price.
We can use the following di􏺈erence equation to simulate stock prices:
s0 = log(S0)

s =s +(μ−σ2/2)δt+σ δtε
St =exp(St)
t t−1
t
Here the εt are independent random variables, normally distributed with mean 0 and standard deviation 1.

FMO6
Mock exam question
Mock exam question – part (iv)
Describe how you could use the results of such a simulation to estimate the VaR of a call option on a stock. (20%)

FMO6
Mock exam question
Solution (iv)
Using the di􏺈erence equation with one step and δt=d days, we can simulate the stock price in d days time. One can then use the Black Scholes formula to compute the price of a call option given the stock price. By running a large number of simulations, we obtain a set of simulated future option prices. One simply reads o􏺈 the desired percentile to 􏺉nd the scenario representing the
(1 − p)%-th worst 􏺉nal price. The VaR is then the current price minus this worst case.

FMO6
Mock exam question
Mock exam question – part (v)
Explain brie􏺎y how you could go about testing the results of this calculation. (20%)

FMO6
Mock exam question
Solution (v)
It is possible to derive an analytical formula for the VaR in this case, so one could simply use this formula to test the Monte Carlo calculation. (See homework)

FMO6
Mock exam question
End of mock exam question

FMO6
Exercises
Exercises 1
8 Use the Monte Carlo algorithm to compute the 95% 10 day VaR of a holding of 1 ACME corporation stock. Assume that the current stock price of ACME is $100, the volatility is 0.2. Use RiskMetrics assumptions for the drift.
8 Use the parametric VaR algorithm to compute the 95% 10 day VaR of a holding of 1 ACME corporation call option with strike 110 and maturity 100.
8 Write a function expectedShortfall which takes a vector of prices and produces the expected price for the worst p% of cases.
8 Enhance the monteCarloVar function given so that it provides a con􏺉dence interval for the estimate of VaR.

FMO6
Exercises
Exercises 2
8 Find an analytical formula for the VaR of a call option assuming that the stock follows the Black Scholes model with drift σ2/2. Use this to check your answers to the 􏺉rst two questions. Explain why Monte Carlo VaR and parametric VaR are still useful ideas.
8 Use the Monte Carlo algorithm to compute the CVaR of a call option on the ACME corporation with parameters as above.
8 Simulate stock paths according to the RiskMetrics model and then compute the EWMA volatility. Plot a histogram of the volatility estimates.

FMO6
Exercises
Exercises 3
8 Suppose that we have n risk factors P(1), P(2), . . . . These follow the RiskMetrics model with covariance matrix Σ. What is the parametric VaR of a portfolio α consisting of αa units of each risk factor P(a)? Is this formula an approximation of the VaR or is it the exact VaR of the portfolio?