Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Loop and graph with the results of simulation are not working

$
0
0

proc import datafile= '/home/u62192016/FINA 6271- MSF 2022/Assets.xlsx'dbms=xlsx out=original_data replace;run;

data pd_table;length RatingNum $3. PD1-PD5 8.;input RatingNum $ PD1-PD5;datalines;1 0.0000 0.0300 0.1300 0.2400 0.34002 0.0200 0.0600 0.1400 0.2500 0.35003 0.0500 0.1300 0.2200 0.3300 0.46004 0.1600 0.4300 0.7500 1.1400 1.54005 0.6300 1.9300 3.4600 4.9900 6.43006 3.3400 7.8000 11.7500 14.8900 17.3500;run;

data assets_pd_horizon;set assets_pd_rating;if RatingNum=1 then PD_horizon= (0.148+6)/100;else if RatingNum=2 then PD_horizon= (0.164+6)/100;else if RatingNum=3 then PD_horizon= (0.238+6)/100;else if RatingNum=4 then PD_horizon= (0.804+6)/100;else if RatingNum=5 then PD_horizon= (3.488+6)/100;else if RatingNum=6 then PD_horizon= (11.026+6)/100;output;run;

proc print data=assets_pd_horizon;run;

%macro simulate(n=1);data SimulationLoop;length Simulation $100 DefaultNum 8;run;%do sin_num= 1 %to &n;%let factor_loading=5;data assignment;set original_data;Horizon=5;Factor_loading= &factor_loading;proc print data=assignment;run;data Assets;do Asset= 1 to 200;if Asset=1 then do;S1 = probit(RAND("uniform"));S2 = probit(RAND("uniform"));S3 = probit(RAND("uniform"));S4 = probit(RAND("uniform"));S5 = probit(RAND("uniform"));Zi = probit(RAND("uniform"));end;output;if Asset>1 then do;S1=S1;S2=S2;S3=S3;S4=S4;Zi=probit(RAND("uniform"));end;output;end;run;

            `proc` print data=Assets;            run;            data combined_data;             merge Assets assignment;             run;            `proc` print data=combined_data;            run;            data assets_xi; set combined_data;                Xi = (F1*S1 + F2*S2 + F3*S3 + F4*S4 + F5*S5) +                (`Zi` * `SQRT`  (1 - F1**2+ F2**2 + F3**2 + F4**2 +F5**2));            run;            `proc` print data=assets_xi;            run;            data `assets_ui`;set assets_xi;                do `Ui` = `cdf`("Normal", Xi);                    output;                end;            run;            `proc` print data=`assets_ui`;            run;            data assets_pd; set `assets_ui`;                 `proc` format;                    value $`rating_to_num`'AAA'=1'AA'=2'A'=3'BBB'=4'BB'=5'B'=6;                run;                data assets_pd_rating;                    set assets_pd;                    `RatingNum` = input(put(Rating, $`rating_to_num`.), 8.);                    drop Rating;                run;                `proc` print data=assets_pd_rating;                run;                data rating_pd; set pd_table;                    `Average_PDs`= (sum(PD1+PD2+PD3+PD4+PD5)/5);                run;                data assets_pd_rating_default;                    length default $3;                    set assets_pd_horizon;                    retain Default;                    if `Ui` > PD_horizon then Default='No';                    else Default= 'Yes';                    output;                run;                `proc` print data=assets_pd_rating_default;                run;                `proc` freq data=assets_pd_rating_default;                    tables Default / `nocum nocol norow`;                run;                data assets_default;                    set assets_pd_rating_default;                    if _N_ < 201 or _N_ > 2010 then output;                run;                data `assets_defaultNum`; set assets_default;                    if Default='Yes' then `DefaultNum` = 1;                    else `DefaultNum` = 0;                run;                `proc` print data=`assets_defaultNum`;                run;                `proc` freq data=`assets_DefaultNum`;                    tables `DefaultNum` / `nocum nocol norow`;                run;                `proc sql noprint`;                    select count(*) as `DefaultNum`                    from simulation                    where `DefaultNum`= 1;                quit;                `proc` append base=simulation data=`DefaultNum` force; run;            %end;%mend simulate;

%simulate (n=100);

proc freq data=simulation noprint;tables DefaultNum / out=freqout;run;

proc sgplot data=Freqout;vbarDefaultNum / response=Percent datalabel;yaxis label="Probability";xaxis label="Number of defaults";run;i am supposed to get a proc freq data table at the end with all the defaults simulations, counting yes default (or 1 since i identify Yes=1) and the sglot graph of those simulations.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>