The GLMSELECT procedure in SAS 9.2.2 harnesses the power of variable selection and bootstrapping together. In the example, the trend of IDR is hard to tell, even with a 3-year moving average chart. Thus, I chose 10000 times of resampling. As the result, 3 of the four predictors remained with their corresponding satisfying parameters.
References:
1. Gunter Loeffler and Peter Posch. ‘Credit Risk Modeling using Excel and VBA’. The 2nd edition. Wiley.
2. Wensui Liu. ‘Improving credit scoring by generalized additive model’. SAS Global 2007.
3. Liang Xie. http://www.sas-programming.com
/*******************READ ME*********************************************
* - Bootstrap prediction models for probability of default -
*
* SAS VERSION: 9.2.2
* DATE: 09jun2011
* AUTHOR: hchao8@gmail.com
****************END OF READ ME******************************************/
****************(1) DATA INTEGRATION/TRANSFORMATION STEP*****************;
data idr;
infile datalines delimiter = ',' missover dsd lrecl=32767;
format year idr prf age bbb spr best12.;
input year idr prf age bbb spr;
datalines;
1981,0,-7.340255411,,27.02456779,2.77
/*To buy Gunter and Peter's book will have the full data*/
2005,0.030637255,3.183410997,6.673717385,45.77112235,1.91
;;;
run;
data idr_t;
merge idr(keep=idr firstobs=2 )
idr(rename=(idr=_idrforward year=_yearforward));
year = _yearforward + 1;
label idr = 'invesment grade default rate'
prf = 'forecasted change in corporate profits'
age = 'fraction of new issuers'
bbb = 'fraction of bbb-rated issuers'
spr = 'spread on baa bonds';
run;
****************(2) MODULE-BUILDING STEP********************************;
%macro idrbs(data =, nsamp =, out =);
/*****************************************************************
* MACRO: idrbs()
* GOAL: build prediction model by variable selection and
* bootstrapping
* PARAMETERS: data = dataset to use
* nsamp = numbers of bootstrapping
* out = name of scored dataset
*****************************************************************/
proc sgplot data = &data;
title 'the invesment grade default rates by years';
series x = year y = idr;
yaxis grid;
run;
ods graphics on;
proc macontrol data = &data;
title 'three year moving average chart for invesment grade default rate';
machart idr*year / span = 3 odstitle = title;
run;
proc glmselect data = &data plots = all;
model idr = prf age bbb spr/selection = stepwise(select = press);
modelaverage nsamples = &nsamp subset(best = 1);
output out = &out(drop = _:) p = pred_idr;
run;
ods graphics off;
%mend idrbs;
%idrbs(data = idr_t, nsamp = 10000, out = idr_scored);
****************END OF ALL CODING***************************************;
No comments:
Post a Comment