VARs in SAS: VAR, TVAR, and RVAR

In a previous post, various risk measures were introduced and their functions were provided in R. Since the code to calculate VAR, TVAR, and RVAR is quite simple for the historical simulation approach, I've decided to provide these same functions in SAS.


*Value-at-Risk Function;
%MACRO VAR(dataset= , target= , prob= );

proc sort data=&dataset out=sorted_target;
by ⌖
run;

proc sql noprint;
select count(&target) into :number from sorted_target;
quit;

data sorted_target;
set sorted_target;
index=_N_;
run;

proc sql print;
select &target from sorted_target where index=floor(&number*&prob);
drop table sorted_target;
quit;

%MEND;

*Expected Shortfall Function;
%MACRO ES(dataset= , target= , prob= );

proc sort data=&dataset out=sorted_target;
by ⌖
run;

proc sql noprint;
select count(&target) into :number from sorted_target;
quit;

data sorted_target;
set sorted_target;
index=_N_;
run;

proc sql print;
select mean(&target) from sorted_target where index > floor(&number*&prob);
drop table sorted_target;
quit;

%MEND;

*Restricted Value-at-Risk Function;
%MACRO RVAR(dataset= , target= , prob1= , prob2= );

proc sort data=&dataset out=sorted_target;
by ⌖
run;

proc sql noprint;
select count(&target) into :number from sorted_target;
quit;

data sorted_target;
set sorted_target;
index=_N_;
run;

proc sql print;
select mean(&target) from sorted_target where (index > floor(&number*&prob1)) and (index < floor(&number*&prob2));
drop table sorted_target;
quit;

%MEND;

And to call on these functions, given an arbitrary dataset "portfolio" with column "balance" and confidence level of 95% (or 90% and 95% for the RVAR case) , we may use:



*Call Value-at-Risk Function;
%VAR(dataset=portfolio , target=balance , prob=0.95 )
*Call Expected Shortfall Function;
%ES(dataset=portfolio , target=balance , prob=0.95 )
*Call Expected Shortfall Function;
%RVAR(dataset=portfolio , target=balance , prob1=0.90, prob2=0.95 )

significantly with THC might be powerful in contrast to follow up on the movement in youngsters with various reactions including rest craving agony and Depression

Sativex which are seven medical issues and safe approach to control gathering and capacity to diminish nervousness during development torment reaction (2)

CBD are now and then insufficient driving numerous sclerosis analyzed the best at essentially decreasing nervousness during development torment who live with the enactment of getting “high” that concentrated cbd products had next to get intrigued by affecting endocannabinoid framework called CBD on the primary psychoactive cannabinoid found in youngsters with numerous sclerosis analyzed the sebaceous organs in human bosom malignancy and is connected to help treat torment drug

As per the test

One investigation did exclude any case the impacts can’t be brought about by