SAS中文论坛

标题: Test A-IRB approach for credit rating [打印本页]

作者: shiyiming    时间: 2012-2-25 00:35
标题: Test A-IRB approach for credit rating
From Dapangmao's blog on sas-analysis

<div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/-Wem5f380zwY/T0euQohjvII/AAAAAAAAA8E/BMRAELKrDrM/s1600/SGPlot.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="http://3.bp.blogspot.com/-Wem5f380zwY/T0euQohjvII/AAAAAAAAA8E/BMRAELKrDrM/s400/SGPlot.png" width="400" /></a></div><br />
<a href="http://en.wikipedia.org/wiki/Basel_II">Basel II</a>&nbsp;or <a href="http://en.wikipedia.org/wiki/Basel_III">Basel&nbsp;III</a> framework would allow <a href="http://www.youtube.com/watch?v=o2kGYUP7Vro">qualified financial institutions</a> to apply their own rating systems for credit risks, such as&nbsp;<a href="http://en.wikipedia.org/wiki/Advanced_IRB">advanced internal ratings-based approach</a> (A-IRB). <a href="http://www.sasanalysis.com/2011/07/play-sas-with-basel-ii-accord-1-loan.html">The equations of required capital</a> play a big role in it. With full-fledging facility of SAS, an automatic selection system can be built by its’ macros, SQL syntax and function complier.  I just ran a simple experiment based on a standard seven-level grading system, toward a data set with a varying PD and the fixed EAD, LGD and maturity.<br />
<h3 class="r" style="background-color: white; color: #222222; font-family: arial, sans-serif; font-size: medium; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; overflow-x: hidden; overflow-y: hidden; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; text-overflow: ellipsis; white-space: nowrap;"><br />
</h3><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/-a5cTaHZ0xqk/T0eq5PzzYuI/AAAAAAAAA7s/TvhZkqzlE_s/s1600/SGPlot8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="http://1.bp.blogspot.com/-a5cTaHZ0xqk/T0eq5PzzYuI/AAAAAAAAA7s/TvhZkqzlE_s/s400/SGPlot8.png" width="400" /></a></div><br />
First 1000 rating structures were simulated. SAS's seeds are used to memorize the structures (Liang has <a href="http://www.sas-programming.com/2012/01/today-rick-blog-here-wrote-article.html">an interesting post</a> regarding the "seed trap" question.). <br />
<pre style="background-color: #ebebeb; border: 1px dashed rgb(153, 153, 153); color: #000001; font-size: 14px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>
%macro structgen(data = , var = , out = );
   proc sql noprint;
      create table &amp;out(y num, seed num, step num);
   quit;
   %do i = 1 %to 1000;
      data _tmp1;
         set &amp;data;
         retain y 0;
         y = y + ranuni(&amp;i)*(&amp;var-y);
         seed = &amp;i;
         step = _n_ ;
      run;
      proc sql noprint;
         insert into &amp;out
         select y, seed, step
         from _tmp1;
      quit;
   %end;
%mend;
%structgen(data = maxbound, var = maxvalue, out = final);

proc sgplot data = final;
   series x = step y = y / group = seed;
   yaxis label = 'Percentage'; xaxis grid;
run;
</code></pre><br />
<div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/-sbgW3EaJD2E/T0eq9dMJnRI/AAAAAAAAA74/L6tB9LFh5eU/s1600/SGPlot2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="http://4.bp.blogspot.com/-sbgW3EaJD2E/T0eq9dMJnRI/AAAAAAAAA74/L6tB9LFh5eU/s400/SGPlot2.png" width="400" /></a></div><br />
Second, for each of the rating structure, GINI and required capital were calculated. The min value of required capital turned out to be 0.069, while the max value of GINI is 0.749. <br />
<br />
<pre style="background-color: #ebebeb; border: 1px dashed rgb(153, 153, 153); color: #000001; font-size: 14px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;"><code>
%macro grdselect(lgd = 0.45, ead = 100, m = 2.5, out = want);
   proc sql noprint;
      select mean(pd)/100 into: avgpd from pd
      ;
      select count(pd) into: nobs from pd
      ;
      create table &amp;out(structure char(50), gini num, cr num)
      ;
   quit;   
   %do i = 1 %to 1000;
      data bound;
         set final;
         lowbound = y / 100;
         where seed = &amp;i;
      run;

      data _myfmt;
         merge bound(rename=(lowbound=start))
            bound(rename=(lowbound=end) firstobs=2);
         fmtname = 'range'; type = 'n';
         label = _n_;
         if end = . then end = 1;
      run;
      proc format cntlin = _myfmt;
      run;

      data _1;
         set pd;
         pd = pd / 100;
         grade = put(pd, range.);
         cr = reqcap(pd, &amp;lgd, &amp;m);
      run;

      proc sql noprint;
         select lowbound format=percent8.2 into: structure separated by '-' from bound
         ;
         create table _2 as
         select grade,
               count(grade) / &amp;nobs as ps 'share of portfolio',
               mean(pd) as gpd 'grade pd',
               calculated ps * calculated gpd / &amp;avgpd as esod 'expected share of default',
               reqcap(calculated gpd, &amp;lgd, &amp;m) as gcr 'grade cr'
         from _1
         group by grade
         ;
      quit;

      proc sort data = _2;
         by descending grade;
      run;
      data _3;
         set _2;
         retain _y 0;
         _y + esod;
         _x = _y - esod;
         label egc = 'Expected GINI values';
         egc = ps * (_x + esod/2);
      run;

      proc sql noprint;
         select (sum(egc)-0.5) / ((&amp;avgpd/2+(1-&amp;avgpd))-0.5) into: gini
         from _3
         ;
         select sum(&amp;ead*gcr)/sum(ead) into: cr
         from (select a.*, b.gcr
            from _1 as a left join _3 as b on a.grade = b.grade)
         ;
         insert into &amp;out
         values ("&amp;structure", &amp;gini, &amp;cr)
         ;
      quit;
   %end;
%mend;
%grdselect;

proc sgplot data = want;
   series x = seed y = cr;
   series x = seed y = gini / y2axis;
run;
</code></pre>Conclusion:<br />
1. The optimal rating structure depends on multiple factors, including <a href="http://edoc.hu-berlin.de/series/sfb-373-papers/2002-67/PDF/67.pdf">accuracy ratio</a> and required capital which I used in this test. Business decision would make significant difference, while an integrated evaluation index may need more modeling work. <br />
2. To save time from the high I/O operations involved with lots of loops, such as simulation, back testing, stress testing, etc., try to decrease the steps to write data to the hard disk. Memory-intensive PROC SQL or PROC IML sometimes is a more efficient way than the DATA step. Also avoid %IF-%THEN statement inside of a macro loop (some interesting discussions similar to this topic: Rick's post&nbsp;<a href="http://blogs.sas.com/content/iml/2012/02/13/avoid-unnecessary-if-then-statements-in-loops/">here</a> and my post&nbsp;<a href="http://www.sasanalysis.com/2012/01/benchmarking-of-cusum-function-in.html">here</a>).<div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3256159328630041416-4149797438216735553?l=www.sasanalysis.com' alt='' /></div><img src="http://feeds.feedburner.com/~r/SasAnalysis/~4/YLOMgwBWjtM" height="1" width="1"/>




欢迎光临 SAS中文论坛 (http://www.mysas.net/forum/) Powered by Discuz! X3.2