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;

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 720 views
  • 0 likes
  • 2 in conversation