You are on page 1of 14

athWorks Nordic - Counterparty Credit Risk and CVA - MATLAB & Simulink 2012-11-12

Counterparty Credit Risk and CVA


This example show s how to compute the unilateral Credit Value (Valuation) Adjustment (CVA) for a bank holding a portfolio of vanilla interest rate sw aps w ith several counterparties. CVA is the expected loss on an over-thecounter instrument or portfolio of instruments due to counterparty default. The CVA for a particular counterparty is defined as the sum over all points in time of the discounted expected exposure at each moment multiplied by the probability that the counterparty defaults at that moment, all multiplied by 1 minus the recovery rate. The Credit Value (Valuation) Adjustment (CVA) formula is:

Where Ris the recovery, d s E the discounted expected exposure at time t, and P the default probability icE D distribution. The expected exposure is computed by first simulating many future scenarios of risk factors for the given instrument or portfolio. Risk factors can be interest rates, FX rates, equity or commodity prices, or anything that w ill affect the market value of the instruments. Once a sufficient set of scenarios has been simulated, the contract or portfolio can be priced on a series of future dates for each scenario. The result is a matrix, or "cube", of instrument values. These prices are converted into exposures after taking into account collateral agreements that the bank might have in place as w ell as netting agreements w here the values of several instruments may offset each other, low ering their total exposure. The instrument values for each scenario are discounted to compute the discounted exposures. The discounted expected exposures can then be computed by a simple average of the discounted exposures at each simulation date. Finally, counterparty default probabilities are typically derived from credit default sw ap market quotes and the CVA for the counterparty can be computed according to the above formula. For this example w e w ill w ork w ith a portfolio of vanilla interest rate sw aps w ith the goal of computing the CVA for a particular counterparty. This example can run slow ly on some machines. If you have the Parallel Computing Toolbox installed it can improve the performance. Read Sw ap Portfolio The portfolio of sw aps is close to zero value at time t=0. Each sw ap is associated w ith a counterparty and may or may not be included in a netting agreement.

%Ra sasfo sraset ed wp rm pedhe saFl ='v-wpprfloxs; wpie casa-otoi.l' saDt =dtst'LFl'saFl) wpaa aae(XSie,wpie; sas=src(. wp tut.. 'onepry,].. Cutrat'[,. 'etnI'[,. NtigD,].. 'rnia'[,. Picpl,].. 'auiy,].. Mtrt'[,. 'eRt'[,. Lgae,]..
www.mathworks.se/help/fininst/counterparty-credit-risk-and-cva.html 1/14

athWorks Nordic - Counterparty Credit Risk and CVA - MATLAB & Simulink 2012-11-12

'eTp'[,. Lgye,].. 'aetlaigae,].. LtsFotnRt'[,. 'atlaigae,]; LsFotnDt'[) sasCutrat =saDt.onepryD wp.onepry wpaaCutratI; sasNtigD wp.etnI sasPicpl wp.rnia sasMtrt wp.auiy sasLgye wp.eTp sasLgae wp.eRt sasPro wp.eid =saDt.etnI; wpaaNtigD =saDt.rnia; wpaaPicpl =saDt.auiy wpaaMtrt; =[wpaaLgye~wpaaLgye; saDt.eTp saDt.eTp] =[wpaaLgaeeevn saDt.eRtPyn] saDt.eRtRciig wpaaLgaeaig; =saDt.eid wpaaPro;

sasLtsFotnRt =saDt.aetlaigae wp.aetlaigae wpaaLtsFotnRt;

nmwp =nmlsasCutrat) uSas ue(wp.onepry; nmonepris=mxsasCutrat) uCutrate a(wp.onepry;

Create RateSpec from the Interest Rate Curve

Stl ete

=dtnm'4Dc20'; aeu(1-e-07)

Tnr =[ 61 51 71 1*22*23*2' eo 3 2 *2 *2 01 01 01]; ZrRts=[.3 004005000002004008007]; eoae 003 .3 .3 .4 .4 .4 .4 .45' ZrDts=dtmt(eteTnr; eoae aenhStl,eo) Cmonig=2 opudn ; Bss=0 ai ; RtSe =itnst'trDts,Stl,Edae' ZrDts.. aepc neve(Satae' ete'nDts, eoae,. 'ae' ZrRts'opudn'Cmonig'ai'Bss; Rts, eoae,Cmonig,opudn,Bss,ai) %Cet a ICreojc. W wl ueti frcmuig rae n Ruv bet e il s hs o optn isatnos ntnaeu %fradrtsdrn tecluaino teHl-ht sotrt owr ae uig h aclto f h ulWie hr ae pt. ah RtCreb =IDtCre'eo,eteZrDtsZrRts.. aeuvOj Raauv(Zr'Stl,eoae,eoae,. 'opudn' Cmonig'ai' Bss; Cmonig, opudn,Bss, ai)

Setup Tunable Sim ulation Param eters We can vary the number of simulated interest rate scenarios w e generate by tuning the variable here. We set our simulation dates to be more frequent at first, then turning less frequent further in the future.

%Nme o MneCrosmltos ubr f ot al iuain nmcnro =6; uSeais 4 %Cmuemnhysmlto dts te qatrydtsltr opt otl iuain ae, hn urel ae ae. smltoDts=dtmt(ete111) iuainae aenhStl+,:2; smltoDts=[iuainae iuainae smltoDts dtmt(iuainae(n)336); aenhsmltoDtsed,::4]

Com pute Initial Prices for All Sw aps

cretrcs=sabzr(aepc.. urnPie wpyeoRtSe,. sasLgae.. wp.eRt,. Stl,. ete..


www.mathworks.se/help/fininst/counterparty-credit-risk-and-cva.html 2/14

athWorks Nordic - Counterparty Credit Risk and CVA - MATLAB & Simulink 2012-11-12

sasMtrt,. wp.auiy.. 'rnia'sasPicpl.. Picpl,wp.rnia,. 'eTp'sasLgye.. Lgye,wp.eTp,. 'aetlaigae,wp.aetlaigae; LtsFotnRt'sasLtsFotnRt) %Frec smlto dt,cmuels fotn rstdt prsa o ah iuain ae opt at laig ee ae e wp fotae =cdtsStl-6,wp.auiysasPro) laDts fae(ete30sasMtrt,wp.eid; sasLsFotnDt =zrsnmwp,ue(iuainae); wp.atlaigae eo(uSasnmlsmltoDts) fri=nmlsmltoDts:11 o ue(iuainae)-: tiDt =smltoDtsi; hsae iuainae() fotae(laDts>tiDt)=0 laDtsfotae hsae ; sasLsFotnDt(,)=mxfotae,]2; wp.atlaigae:i a(laDts[,) ed n

Setup Hull-White Single Factor Model The risk factor w e w ill simulate to value our instruments is the zero curve. For this example w e w ill model the interest rate term structure using the one-factor Hull-White model. This is a model of the short rate and is defined as:

w here : Change in the short rate after a small change in time, : Mean reversion rate : Volatility of the short rate : A Weiner process (a standard normal process) : Drift function defined as:

: Instantaneous forw ard rate at time : Partial derivative of w ith respect to time

Once w e have simulated a path of the short rate w e generate a full yield curve at each simulation date using the formula:

: Zero rate at time for a period of : Price of a zero coupon bond at time that pays one dollar at time

www.mathworks.se/help/fininst/counterparty-credit-risk-and-cva.html

3/14

athWorks Nordic - Counterparty Credit Risk and CVA - MATLAB & Simulink 2012-11-12

Each scenario contains the full term structure moving forw ard through time, modeled at each of our selected simulation dates. Refer to "Calibrating the Hull-White Model Using Market Data" example in the Financial Instruments Toolbox Users' Guide for more details on Hull-White single factor model calibration.

Apa=02 lh .; Sga=005 im .1; r =RtCreb.eZrRtsStl+,Cmonig,1; 0 aeuvOjgteoae(ete1'opudn'-) t =Stl; 0 ete %CntutSEojc osrc D bet hlwie =hvApa@tx ulht1 w(lh,(,) h1eeFnt,,aeuvOjApaSga,. wLvlu(0tRtCreb,lh,im).. Sga'trSae,0; im,Sattt'r) %Soealmdlclbainifrain tr l oe airto nomto clbainRtCreb =RtCreb; airto.aeuvOj aeuvOj clbainTnr=Tnr airto.eo eo; clbainSotaeoe =hlwie; airto.hrRtMdl ulht1 clbainApa=Apa airto.lh lh; clbainSga=Sga airto.im im;

Sim ulate Scenarios and Com pute Mark-To-Market Values For each scenario the sw ap portfolio is priced at each future simulation date. Prices are computed using s a b z r and the simulated zero curve at each date. The prices are then aggregated into a "cube" of vales wpyeo w hich contains all future instrument values at each simulation date for each scenario. The resulting cube of instrument prices is a 3 dimensional matrix w here each row represents an instrument, each column a simulation date, and each "page" a different simulated scenario.

%Alct cb o smltdvle:rw crepn t isrmns loae ue f iuae aus os orsod o ntuet, %clmst vlaindts "ae"t seais oun o auto ae, pgs o cnro smltdaus=zrsnmwp,ue(iuainae)nmcnro) iuaeVle eo(uSasnmlsmltoDts,uSeais; %Pealct seaisdt srcue r-loae cnro aa tutr smlSeai =heeaecnroclbainStl,iuainae) apecnro gnrtSeai(airto,etesmltoDts; seais=rpa(apecnronmcnro,) cnro emtsmlSeai,uSeais1; iiilnYaRt =RtCreb.eZrRtsStl + ntaOeerae aeuvOjgteoae(ete 35'opudn'-) 6,Cmonig,1;

For each scenario, w e model a future interest rate curve at each valuation date. Using the complete future interest rate path, w e compute the value of all instruments at each valuation date. Since the simulation dates do not correspond to the sw aps cash flow dates (w here the floating rates are reset) w e estimate the latest floating rate w ith the 1-year rate (all of these sw aps have period 1 year) interpolated betw een the nearest simulated rate curves. The scenario generation and pricing are done in parallel using the p r o loop if the Parallel Computing Toolbox is afr installed. The scenarios and their respective instrument values are computed in parallel across all MATLAB w orkers.
www.mathworks.se/help/fininst/counterparty-credit-risk-and-cva.html 4/14

athWorks Nordic - Counterparty Credit Risk and CVA - MATLAB & Simulink 2012-11-12

%Uerpouil rno nme gnrtr(aytese t poue s erdcbe adm ubr eeao vr h ed o rdc %dfeetrno seais ifrn adm cnro) sra =RnSra.rae'r3ka,Nmtem'nmcnro,. tem adtemcet(mg23''uSras,uSeais.. 'ed,) Se'0; %Smlt alseaisadcmueisrmn vle i prle. I iuae l cnro n opt ntuet aus n aall f yu o %hv tePrle CmuigTobx yusol oe amtapo ae h aall optn olo, o hud pn albol bfr eoe %rnigti scin unn hs eto. pro seaiIx=1nmcnro afr cnrod :uSeais %Sv saeo rno nme gnrtr ae tt f adm ubr eeao dfuttemoa =RnSra.eGoaSra(; ealSraLcl adtemgtlbltem) svdttLcl=dfuttemoa.tt; aeSaeoa ealSraLclSae %Stpnwrno nme gnrtrsaefrec seai eu e adm ubr eeao tt o ah cnro RnSra.eGoaSra(tem; adtemstlbltemsra) stsra,Sbtem,cnrod) e(tem'usra'seaiIx; %Cet aseai rae cnro seaisseaiIx =heeaecnroclbain.. cnro(cnrod) gnrtSeai(airto,. Stl,iuainae) etesmltoDts; %Cmuealmr-omre vle frti seai opt l akt-akt aus o hs cnro tiSeaiVle =hoptMMaussassmltoDts.. hscnroaus cmueTVle(wp,iuainae,. seaisseaiIx,eteiiilnYaRt) cnro(cnrod)Stl,ntaOeerae; %Ageaedt grgt aa smltdaus::seaiIx =tiSeaiVle; iuaeVle(,,cnrod) hscnroaus %Rsoerno nme gnrtrsae etr adm ubr eeao tt RnSra.eGoaSra(ealSraLcl; adtemstlbltemdfuttemoa) dfuttemoa.tt =svdttLcl ealSraLclSae aeSaeoa; ed n

Visualize Sim ulated Portfolio Values We plot the total portfolio value for each scenario of our simulation. As each scenario moves forw ard in time the values of the instruments w ill move up or dow n depending on how the modeled interest rate term structure changes. As the sw aps get closer to maturity, their values w ill begin to approach zero since the aggregate value of all remaining cash flow s w ill decrease after each cash flow date.

%Apn iiilpie/aet orsmlto dt ped nta rcsdt o u iuain aa vle =ct2rpa(urnPie,11 aus a(,emtcretrcs[ nmcnro],iuaeVle) uSeais)smltdaus; dts=[etesmltoDts; ae Stl iuainae] %Ve prflovleoe tm iw otoi au vr ie fgr; iue ttlotaus=sueesmvle); oaPrVle qez(u(aus) po(ae,oaPrVle) ltdtsttlotaus; tte'iuae MMPrfloVle) il(Smltd T otoi au'; dttc(x,mmy) aeik'''my'
www.mathworks.se/help/fininst/counterparty-credit-risk-and-cva.html 5/14

athWorks Nordic - Counterparty Credit Risk and CVA - MATLAB & Simulink 2012-11-12

yae(PrfloVle()) lbl'otoi au $' xae(Smlto Dts) lbl'iuain ae'

Com pute Exposure by Counterparty The exposure of a particular contract (i) at time t is the maximum of the contract value (Vi) and 0:

And the exposure for a particular counterparty is simply a sum of the individual contract exposures:

In the presence of netting agreements, how ever, contracts are aggregated together and can offset each other. Therefore the total exposure of all instruments in a netting agreement is

We compute these exposures for each counterparty at each simulation date.

%Adtv epsr i cmue a tentigstlvl diie xoue s optd t h etn e ee. Epsr o xoue f a n %unte isrmn i eult temre vleo teisrmn i netd ntuet s qa o h akt au f h ntuet f te h %isrmn hspstv vle ohriei i zr. ntuet a oiie au, tews t s eo isrmn_xoue =zrssz(aus) ntuetepsrs eo(ievle); unteIx=sasNtigD= 0 netdd wp.etnI = ; isrmn_xoue(netdd,,)=mxvle(netdd,,)0; ntuetepsrsunteIx:: a(ausunteIx::,) %Isrmnsicue i antigareethv epsr eult ntuet nldd n etn gemn ae xoue qa o ter hi %vlewe tentigareethspstv ageaevle au hn h etn gemn a oiie grgt au, ohrie tews
www.mathworks.se/help/fininst/counterparty-credit-risk-and-cva.html

athWorks Nordic - Counterparty Credit Risk and CVA - MATLAB & Simulink 2012-11-12

%terepsr i zr. W cmueti prntigareet bti hi xoue s eo e opt hs e etn gemn, u n %ti cs ec cutrat hsol asnl ntigareet hs ae ah onepry a ny ige etn gemn. frj=1nmonepris o :uCutrate nteIx=sasNtigD= j etdd wp.etnI = ; %Epsrsfrisrmnsudrntigareet xoue o ntuet ne etn gemns nteVle =vle(etdd,,) etdaus ausnteIx::; nteEpsr =mxsmnteVle,)0; etdxoue a(u(etdaus1,) pstvIx=nteEpsr >0 oiied etdxoue ; isrmn_xoue(etdd,oiied)= ntuetepsrsnteIxpstvIx vle(etdd,oiied) ausnteIxpstvIx; ed n %Smteisrmn epsrsfrec cutrat u h ntuet xoue o ah onepry epsrs=zrsnmoneprisnmldts,uSeais; xoue eo(uCutrate,ue(ae)nmcnro) frj=1nmonepris o :uCutrate cSaIx=sasCutrat = j pwpd wp.onepry = ; epsrsj:: = xoue(,,) sueesmisrmn_xoue(pwpd,,)1) qez(u(ntuetepsrscSaIx::,); ed n

We plot the total portfolio exposure for each scenario in our simulation. Similar to the plot of instrument values, the exposures for each scenario w ill approach zero as the sw aps mature.

%Ve prfloepsr oe tm iw otoi xoue vr ie fgr iue ttlotxoue=sueesmepsrs1) oaPrEpsr qez(u(xoue,); po(ae,oaPrEpsr) ltdtsttlotxoue; tte'iuae PrfloEpsr'; il(Smltd otoi xoue) dttc(x,mmy) aeik'''my' yae(Epsr ()) lbl'xoue $' xae(Smlto Dts) lbl'iuain ae'

www.mathworks.se/help/fininst/counterparty-credit-risk-and-cva.html

7/14

athWorks Nordic - Counterparty Credit Risk and CVA - MATLAB & Simulink 2012-11-12

Exposure Profiles Several exposure profiles are useful w hen analyzing the potential future exposure of a bank to a counterparty. Here w e compute several (non-discounted) exposure profiles per counterparty as w ell as for the entire portfolio. P : Peak Exposure : A high percentile (95%) of the distribution of exposures at any particular future date E M E: Maximum Peak Exposure : The maximum peak exposure across all dates P E : Expected Exposure : The mean (average) of the distribution of exposures at each date E E E: Expected Positive Exposure : Weighted average over time of the expected exposure P E f E: Effective Expected Exposure : The maximum expected exposure at any time, t, or previous time fE E f P : Effective Expected Positive Exposure : The w eighted average of the effective expected exposure fEE For further definitions, see for example Basel II document in references.

%Cmueetr prfloepsr opt nie otoi xoue epot=sueesmepsrs); xPr qez(u(xoue)' %Pa Epsr (aea PtnilFtr Epsr) ek xoue sm s oeta uue xoue Pc Ep =pcieepsrs9,) rtl(xoue,53; Ppr =pcieepot9) Eot rtl(xPr,5; %MxmmPa Epsr aiu ek xoue MEp Pc =mxPc,]2; a(Ep[,) MEot=mxPpr) Ppr a(Eot; %Epce Epsr xetd xoue Ec Ep =ma(xoue,) enepsrs3; Epr =ma(xPr) Eot enepot; %Epce Pstv Epsr:Wihe aeaeoe tm o E xetd oiie xoue egtd vrg vr ie f E %*I cniuu tm,ti i teaeaeepce epsrsoe n otnos ie hs s h vrg xetd xoue vr tm, ie % a itga o E()oe tetm itra,dvddb telnt n nerl f Et vr h ie nevl iie y h egh
8/14

www.mathworks.se/help/fininst/counterparty-credit-risk-and-cva.html

athWorks Nordic - Counterparty Credit Risk and CVA - MATLAB & Simulink

o f % teitra h nevl %*Cmueuiga"rpzia"apoc hr opt sn taeodl prah ee smienevl=yafa(ete dts 1; iTmItra errcStl, ae, ) smoaTm =smienevled-iTmItra() iTtlie iTmItra(n)smienevl1; EEp Pc =05(Ep:1ed .*Ec(,:n1+Ep:2ed)df(iTmItra)/iTtlie )Ec(,:n)*ifsmienevl'smoaTm; EEot=05(Eot1ed Ppr .*Epr(:n1+Eot2ed)df(iTmItra)/iTtlie )Epr(:n)*ifsmienevl'smoaTm; %EfcieEpce Epsr:MxE u t tm smienevl fetv xetd xoue a E p o ie iTmItra EfEp=zrssz(Ep) fEc eo(ieEc); fri=1sz(Ep1 o :ieEc,) %Cmuecmltv mxmm opt uuaie aiu m=Ec(,) Epi1; frj=1nmldts o :ue(ae) i Ec(,)>m f Epij m=Ec(,) Epij; ed n EfEpij =m fEc(,) ; ed n ed n %Cmuecmltv mxmmfrprflo opt uuaie aiu o otoi EfEot=zrssz(Eot) fEpr eo(ieEpr); m=Epr() Eot1; frj=1nmldts o :ue(ae) i Epr()>m f Eotj m=Epr() Eotj; ed n EfEotj =m fEpr() ; ed n %EfcieEpce Pstv Epsr:Wihe aeaeoe tm o fetv xetd oiie xoue egtd vrg vr ie f EfE fE EfPc fEEp =05(fEc(,:n.*EfEp:1ed 1+fEc(,:n)*ifsmienevl'smoaTm; )EfEp:2ed)df(iTmItra)/iTtlie EfPpr =05(fEpr(:nfEEot .*EfEot1ed 1+fEpr(:n)*ifsmienevl'smoaTm; )EfEot2ed)df(iTmItra)/iTtlie

We visualize the exposure profiles, first for the entire portfolio, then for a particular counterparty.

%Vsaieprfloepsr poie iulz otoi xoue rfls fgr iue po(ae,Eot.. ltdtsPpr,. dtsMEotoe(iePpr),. ae,Ppr*nssz(Eot).. dtsEpr,. ae,Eot.. dtsEEotoe(iePpr),. ae,Ppr*nssz(Eot).. dtsEfEot.. ae,fEpr,. dtsEfPpr*nssz(Eot) ae,fEEotoe(iePpr)) lgn('E(5),ME(5),E''P''fE''fEE} eed{P 9%''P 9%''E,EE,EfE,EfP') dttc(x,mmy) aeik'''my' tte'otoi Epsr Poie'; il(Prflo xoue rfls) yae(Epsr ()) lbl'xoue $'
www.mathworks.se/help/fininst/counterparty-credit-risk-and-cva.html 9/14

athWorks Nordic - Counterparty Credit Risk and CVA - MATLAB & Simulink 2012-11-12

xae(Smlto Dts) lbl'iuain ae' %Vsaieepsr poie frapriua cutrat iulz xoue rfls o atclr onepry cIx=5 pd ; fgr iue po(ae,EpcIx:,. ltdtsPc(pd,).. dtsMEpcIx:*nssz(EpcIx:),. ae,Pc(pd,)oe(iePc(pd,)).. dtsEc(pd,).. ae,EpcIx:,. dtsEEpcIx:*nssz(EpcIx:),. ae,Pc(pd,)oe(iePc(pd,)).. dtsEfEpcIx:,. ae,fEc(pd,).. dtsEfPc(pd,)oe(iePc(pd,)) ae,fEEpcIx:*nssz(EpcIx:)) lgn('E(5),ME(5),E''P''fE''fEE} eed{P 9%''P 9%''E,EE,EfE,EfP') dttc(x,mmy) aeik'''my' ttesrnf'onepry% Epsr Poie'cIx) il(pit(Cutrat d xoue rfls,pd); yae(Epsr ()) lbl'xoue $' xae(Smlto Dts) lbl'iuain ae'

www.mathworks.se/help/fininst/counterparty-credit-risk-and-cva.html

10/14

athWorks Nordic - Counterparty Credit Risk and CVA - MATLAB & Simulink 2012-11-12

Discounted Exposures We compute the discounted expected exposures using the discount factors from each simulated interest rate scenario. The discount factor for a given valuation date in a given scenario is the product of the incremental discount factors from one simulation date to the next, along the interest rate path of that scenario.

%Gtdsone epsrsprcutrat,frec seai e icutd xoue e onepry o ah cnro dsEp=zrssz(xoue); icx eo(ieepsrs) fri1nmcnro o =:uSeais dsEp::i =bxu(tmsseaisi.icepsrs::i) icx(,,) sfn@ie,cnro()Ds,xoue(,,); ed n %Dsone epce epsr icutd xetd xoue dsE =ma(icx,) icE endsEp3;

We plot the discounted expected exposures for the aggregate portfolio as w ell as for each counterparty.

%Prflodsone E otoi icutd E fgr; iue po(ae,u(icE) ltdtssmdsE) dttc(x,mmy) aeik'''my' tte'icutdEpce Epsr frPrflo) il(Dsone xetd xoue o otoi'; yae(Dsone Epsr ()) lbl'icutd xoue $' xae(Smlto Dts) lbl'iuain ae' %Cutrat dsone E onepry icutd E fgr; iue po(ae,icE ltdtsdsE) dttc(x,mmy) aeik'''my' tte'icutdEpce Epsr frEc Cutrat'; il(Dsone xetd xoue o ah onepry) yae(Dsone Epsr ()) lbl'icutd xoue $' xae(Smlto Dts) lbl'iuain ae'

www.mathworks.se/help/fininst/counterparty-credit-risk-and-cva.html

11/14

athWorks Nordic - Counterparty Credit Risk and CVA - MATLAB & Simulink 2012-11-12

Calibrating Probability of Default Curve for One Counterparty The default probability for a given counterparty is implied by the current market spreads of the counterparty's credit default sw aps. We use the function c s o t t a to generate the cumulative probability of default at each dbosrp simulation date.

%CSMre Ifrainfrtecutrat cIx D akt nomto o h onepry pd CSae =dtnm{2-a-8,2-a-9,2-a-0,2-a-1,. DDts aeu('0Mr0''0Mr0''0Mr1''0Mr1'.. '0Mr1') 2-a-2}; CSped =[4 15202530' DSras 10 7 1 6 1]; CSaa=[DDtsCSped] DDt CSae DSras; ZrDt =[aepcEdae RtSe.ae] eoaa RtSe.nDts aepcRts; %ClbaeDfutPoaiiyt CSQoe airt eal rbblt o D uts
www.mathworks.se/help/fininst/counterparty-credit-risk-and-cva.html 12/14

athWorks Nordic - Counterparty Credit Risk and CVA - MATLAB & Simulink 2012-11-12

Dfrbaa=csotta(eoaaCSaaStl,. ePoDt dbosrpZrDt,DDt,ete.. 'rbae'dts) PoDts,ae';

We plot of the cumulative probability of default for the counterparty in question.

fgr iue po(ePoDt(,)Dfrbaa:2) ltDfrbaa:1,ePoDt(,) ttesrnf'eal PoaiiyCrefrCutrat %'cIx) il(pit(Dfut rbblt uv o onepry d,pd); xae(Dt' lbl'ae) yae(Cmltv Poaiiy) lbl'uuaie rbblt' dttc(x,mmy) aeik'''my' yae(Poaiiyo Dfut) lbl'rbblt f eal' xae(Smlto Dts) lbl'iuain ae'

CVA Com putation The Credit Value (Valuation) Adjustment (CVA) formula is:

Where Ris the recovery, d s E the discounted expected exposure at time t, and P the default probability icE D distribution. This assumes the exposure is independent of default (no w rong-w ay risk), and it also assumes the exposure w ere obtained using risk-neutral probabilities. Here w e approximate the integral w ith a finite sum over the valuation dates as:

w here t_1 is todays date, t_2,...,t_n the future valuation dates. We assume CDS info corresponds to counterparty w ith index cpIdx. The computed CVA is the present market value of our credit exposure to counterparty cpIdx. For this example w e set the recovery rate at 40%.
www.mathworks.se/help/fininst/counterparty-credit-risk-and-cva.html 13/14

athWorks Nordic - Counterparty Credit Risk and CVA - MATLAB & Simulink 2012-11-12

Rcvr =04 eoey .; CA=(-eoey*u(icEcIx2ed'*ifDfrbaa:2); V 1Rcvr)smdsE(pd,:n).df(ePoDt(,)) frnf'V frcutrat % =$.fn,pd,V) pit(CA o onepry d %2\'cIxCA

CAfrcutrat 5=$645 V o onepry 48.7

References 1. Pykhtin, Michael, and Steven Zhu, A Guide to Modelling Counterparty Credit Risk, GARP, July/August 2007, issue 37, pp. 16-22. Available at: http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1032522. 2. Basel II: http://w w w .bis.org/publ/bcbs128.pdf page 256

Was this topic helpful?

Yes

No

Try MATLAB, Simulink, and Other Products


Get trial now

www.mathworks.se/help/fininst/counterparty-credit-risk-and-cva.html

14/14

You might also like