BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Lukito
Calcite | Level 5

Hi,

I have a database with monthly observation.

Screenshot 2020-05-20 at 08.53.36.png

i want to annualize volatility and Sharpe ratio, i used this piece of code for each month:

 

proc sql;
create table sampledecember1 as
select i.*, sum(EW*ret) as EW_ret,
/*create annualized volatility*/
sum((sqrt(12)*(volatility))*100) as vol_annual,
/*create annualized return*/
sum(((1+ret)**12)-1) as ret_annual,
sum(EW*L_beta) as ex_ante_beta
from Sampledecember i
group by month_bucket;
data sampledecember1a;
set sampledecember1;
/*create annualized Sharpe ratio*/
SP_annual= sum(ret_annual/vol_annual);
by month_bucket;
run;

 

The result value are too higher. 

Is correct this code?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

When using summary functions with group by, only the summarized columns and the group columns should be in the select, otherwise you will get a "remerge" :

proc sql;
create table sampledecember1 as
select i.month_bucket, sum(EW*ret) as EW_ret,
/*create annualized volatility*/
sum((sqrt(12)*(volatility))*100) as vol_annual,
/*create annualized return*/
sum(((1+ret)**12)-1) as ret_annual,
sum(EW*L_beta) as ex_ante_beta
from Sampledecember i
group by month_bucket;

 

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

When using summary functions with group by, only the summarized columns and the group columns should be in the select, otherwise you will get a "remerge" :

proc sql;
create table sampledecember1 as
select i.month_bucket, sum(EW*ret) as EW_ret,
/*create annualized volatility*/
sum((sqrt(12)*(volatility))*100) as vol_annual,
/*create annualized return*/
sum(((1+ret)**12)-1) as ret_annual,
sum(EW*L_beta) as ex_ante_beta
from Sampledecember i
group by month_bucket;