CS代写 Programming for Quantitative & Computational Finance

Programming for Quantitative & Computational Finance
Instructor: Ng March 25, 2022
Value-at-Risk

Copyright By PowCoder代写 加微信 powcoder

What is Value-at-Risk?
• Measure of portfolio value at risk due to market movements
• Eg. Equity portfolio: exposed to movements of its stock constituents
• Time window: 1-day? 5-day? 10-day?
• Confidence: 95%? 99%?
• 1-day 95% VaR: with 95% confidence, the portfolio loss over the next day will be less than or equal to this amount
Loss distribution
5% prob Loss
𝑃! : today’s portfolio value
𝑃!”#: tomorrow’s portfolio value Tomorrow’s daily P&L: ∆𝑃! = 𝑃!”# − 𝑃! Let 𝐿! = −∆𝑃!
Denote the 1-day 95% VaR by 𝑉𝑎𝑅
𝑃𝐿!≤𝑉𝑎𝑅 =95%

Expected shortfall
• With same VaR value, the tail distribution can exhibit different shapes
Loss distribution
5% prob 95% VaR Loss
Loss distribution
5% prob Loss
• Expected Shortfall (ES) is defined as the average of all losses which are greater than or equal to VaR
𝐸𝑆=𝐸 𝐿!|𝐿! ≥𝑉𝑎𝑅

VaR methodologies
Parametric VaR (RiskMetrics)
Historical VaR
Also known as variance- covariance VaR, delta VaR, linear VaR
• Assume ∆𝑃! follows a
normal distribution with
• Good estimate for linear
instruments (eg. equities,
bonds, swaps, FX positions)
• Simple and fast calculations
• No model assumption on ∆𝑃!
• Historical market data
• Apply to all instruments
• Model dependent (require estimates on model parameters)
• Simulation on market data
• Apply to all instruments
• Heavy computations

Parametric VaR: Equity portfolio example
• Consider a portfolio of two equity positions.
• 𝑃! = 10𝑆” 𝑡 + 20𝑆#(𝑡) where 𝑆”(𝑡), 𝑆#(𝑡) are the stock prices on day t •𝑃!$” =10𝑆” 𝑡+1 +20𝑆#(𝑡+1)=10𝑆” 𝑡 𝑒%! +20𝑆#(𝑡)𝑒%” •∆𝑃!=𝑃!$”−𝑃!=10𝑆” 𝑡 𝑒%!−1 +20𝑆# 𝑡(𝑒%”−1)
•∆𝑃!≈10𝑆” 𝑡𝑟”+20𝑆#(𝑡)𝑟#
• Assume that the log price returns are jointly normal with zero means.
• Then ∆𝑃! follows a normal distribution with zero mean and variance 𝜎&#.
• 97.5% 1-day VaR = 1.96𝜎& • 95% 1-day VaR = 1.65𝜎&
• 99% 1-day VaR = 2.33𝜎&

Parametric VaR
• Suppose 𝑆” , … , 𝑆’ are the market risk factors for the given portfolio •Logpricereturn:𝑟( =ln 𝑆( 𝑡+1 −ln 𝑆( 𝑡
• (𝑟”,…,𝑟’)~𝑁(0,Σ), Σ = (𝑎)*), 𝑎)* = 𝜌)*𝜎)𝜎* and 𝑎)) = 𝜎)#, 0 ≤ i,𝑗 ≤ 𝑛
•∆𝑃≈∑’ 𝑤𝑟~𝑁(0,𝜎#) !)+”)) &
• Step 1: Compute EWMA historical volatilities 𝜎) and correlations 𝜌)*
• Step 2: Find the 𝑤)’s
•Step3:Computethevariance𝜎#=𝑣𝑎𝑟∑’ 𝑤𝑟 =∑’ 𝑤#𝜎#+ ∑’ 𝑤𝑤𝜌𝜎𝜎 #& ! )+”)) )+”))
),*+”,)-* )*)*)*(or𝜎&=𝒘Σ𝒘)
• Step 4: Compute 1−day VaR (eg. 97.5% 1-day VaR = 1.96𝜎& )
• Step 5: Compute N-day VaR = 1-day VaR x 𝑁

Parametric VaR: Finding 𝑤!’s
• Given a portfolio of trades where its portfolio value can be expressed as •𝑃! =𝑓(𝑆”,…,𝑆’)where𝑆”,…,𝑆’ aretheriskfactors
• Apply 1st order Taylor expansion on 𝑓(𝑥”,…,𝑥’)
•∆𝑓𝑥”,…,𝑥’ ≈./∆𝑥”+⋯+./∆𝑥’ .0! .0#
•= 𝑥” ./ ∆0! +⋯+(𝑥’ ./)(∆0#) .0! 0! .0# 0#
•Logpricereturn:𝑟( =ln 2$ !$”]
=ln 1+∆2$ ≈∆2$ 2$ 2$
•∆𝑃! ≈∑’ 𝑆) ./ 𝑟) =∑’ 𝑤)𝑟) where𝑤) =𝑆) ./ )+” .2% )+” .2%

Parametric VaR: Loan portfolio
6 𝑚𝑜𝑛𝑡h 100𝑚 𝑈𝑆𝐷 𝑙𝑜𝑎𝑛 𝑎𝑡 2%
𝑁 = 100𝑚, 𝑇 = 0.5, 𝑐 = 100𝑚 ∗ 2% ∗ 0.5 = 1m 𝑃𝑉=−101𝑚∗𝐷𝐹 𝑇 +100𝑚
𝐷𝐹 𝑇 is the discount factor for maturity T
After 2 months:
This loan matures in 4 months, eg. T’= 4/12 𝑃𝑉 = − 𝑁 + 𝑐 𝐷𝐹 𝑇′
𝐷𝐹 𝑇′ is the discount factor for maturity T’
Loan portfolio:

Parametric VaR: Loan portfolio
• Select a set of standard tenors • 1M, 2M, 3M, 6M, 1Y, 2Y, …, 10Y
• Define the risk factors as the zero coupon bond prices 𝑆” , … , 𝑆’ for the standard tenors 𝑇”, … , 𝑇’
•Let𝑟? =logpricereturnof𝑆) fori=1,…,n • Goal: find 𝑤) s.t. ∆𝑃! ≈ ∑’ 𝑤)𝑟)
• Then for a portfolio of loans 𝐿B, … , 𝐿D we have:
• Suffice to consider the case for a portfolio with only one loan
• Suppose that we can find 𝑤?@ such that tomorrow’s daily P&L for a loan L is
∆𝑃!@ ?AB
•∆𝑃 =∑D ≈∑D ∑C =∑C ∑D 𝑟 ! ?AB ! ?AB EAB E E EAB ?AB E E

Parametric VaR: Loan portfolio
• Now consider a portfolio with only one loan L that will mature and pay a cash flow 𝐶 (including interest and principal repayment) at time 𝑇3
•Presentvalueoftheloan:𝑉3 =𝐶∗𝐷𝐹 𝑇3
• For a discount curve with the standard tenor points, 𝐷𝐹 𝑇3 can be
interpolated from its neighboring points using an interpolation method • Let’s say, the neighboring points are 𝑆( = 𝐷𝐹 𝑇( and 𝑆($” = 𝐷𝐹 𝑇($” •Then𝑉3 =𝐶∗𝐷𝐹 𝑇3 =𝑓(𝑆(,𝑆($”)forsomefunctionf
Example: Linear interpolation on zero rates
𝐷𝐹 𝑇 = exp(−𝑧𝑇)
𝑧=−ln𝐷𝐹𝑇 /𝑇
𝑧! = 𝑧” + (𝑧”#$ − 𝑧”)(𝑇! − 𝑇”)/(𝑇”#$ − 𝑇”) 𝐷𝐹 𝑇! = exp(−𝑧!𝑇!)
ß𝐷𝐹 6𝑚 3M 𝑇! 6M

• Given a portfolio of trades where its portfolio value can be expressed as 𝑃! =𝑓!(𝑆”,…,𝑆’)where𝑆”,…,𝑆’ aretheriskfactors
• Method: sample the distribution of ∆𝑃!
• Step 1: Simulate tomorrow’s value of the risk factors
• Today’sknownvalues𝑆B(𝑡),…,𝑆C 𝑡à𝑆B(𝑡+1),…,𝑆C 𝑡+1 • RunNsimulationstoobtainNsamplesof𝑆B(𝑡+1),…,𝑆C 𝑡+1
• Step 2: Find the sample distribution of 𝑃!$”
• ith sample: 𝑆(?), … , 𝑆(?)à𝑃(?) = 𝑓 (𝑆(?), … , 𝑆(?))
B C !IB !IB B C • Step 3: Find the sample distribution of ∆𝑃!
• ith sample: ∆𝑃(?) = 𝑃(?) − 𝑃! ! !IB
• 95% 1-day VaR = 5% percentile •ForT-dayVaR,findNsamplesof𝑆”(𝑡+𝑇),…,𝑆’ 𝑡+𝑇 inStep1

Historical VaR
• Given a portfolio of trades where its portfolio value can be expressed as 𝑃! =𝑓!(𝑆”,…,𝑆’)where𝑆”,…,𝑆’ aretheriskfactors
• Step 1: Sample tomorrow’s value of the risk factors from historical data • Suppose we have historical market data from day 𝑡 − 𝑁 to date 𝑡
•Goal:findNsamplesof𝑆”(𝑡+1),…,𝑆’ 𝑡+1
•Foreach𝑘 1≤𝑘≤𝑁 :
• Dayt−𝑘:𝑆B(𝑡−𝑘),…,𝑆C 𝑡−𝑘
• Dayt−𝑘+1:𝑆B(𝑡−𝑘+1),…,𝑆C 𝑡−𝑘+1
• Computelogpricereturns:𝑟? =ln𝑆? 𝑡−𝑘+1 −ln𝑆?(𝑡−𝑘),1≤𝑖≤𝑛 • Obtainkthsamplefromlogpricereturnsfromdayt−𝑘todayt−𝑘+1:
𝑆 B( D ) = 𝑆 B 𝑡 𝑒 J ” , … , 𝑆 C( D ) = 𝑆 C 𝑡 𝑒 J #

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com