BookmarkSubscribeRSS Feed
emilykingjr
Calcite | Level 5

Hi everyone,

 

I am now in a seminar of advanced investments, where i have an assignment of sorting the portfolios and construct the investing strategy based on momentum and volatility. However, I don't know anything about programming and I was told that SAS is the only the program that can do this assignment. I know this is a very troublesome question, as i need help from the very beginning with SAS...

 

Here is the code for creating momentum that my teacher gave us. and we need to do something similar for the variance ( a proxy for volatility). And how shall i do it?

 

data stkid;
set work.example;
yearmth=year*12+12-month;
run;
keep stock code year month yearmth;
retyearmth=year*12+12-month;
run;

data ret;
set work.example;
keep stock_code year month retyearmth return;
run;

proc sql ;
create table data as select *, log(b.return+1) as logretfrom stkid as a,ret as b
where a.stock_code=b.stock_code and (yearmth-12)<=b.retyearmth<=(yearmth-2);
quit;

proc sort data=data;by stock_code yearmth;
run;

proc means


Also here are the codes for the major steps of the assignment, single sorting and double sorting. But don't know how to use it...

My variable name are: stockid, yearmonth, return.

 

https://sites.google.com/site/jiejaycao/home/tools1.  SAS with SQL

 

I really tried to learn it by myself from all the materials online, but i am afraid this is really not my area. I relly run out of options so that's why i come here to ask this big question, hoping someone can help me work out the whole code, actually the main connections. I shall be more than grateful!

2 REPLIES 2
mohamed_zaki
Barite | Level 11

I can not follow you....

What do you want to do you want us to help you with exactly?

Be specific with what you need.

Give sample data and say how you want it to be, so we can help...

emilykingjr
Calcite | Level 5

Hello Mohamed,

 

The data is too big, so I will not upload it, but it looks like this:

 

time         stockid       return

200501    123             0.55

200502     123           -0.01

200501      234           0.09

200502      234            0.08

 

So it is a panel data, with around 500 stocks' monthly return in around 10 year's time. And the time format in the raw data is year together with month.

 

The assignment is to create and test two investing strategies based on momentum and volatility. Momentum will be the return of a stock of the past 12 month minus the past 1 month. So for example, the momentum for stock 123 in 200501 will be its cumulative return during 200401-200412. The proxy for volatility will be the variance, which is calculated based on the past 3 years. For example again, the volatility for stock 123 in 200501 will be calculated using the returns from 200201-200412.

 

Firstly I need to construct the two measures in my data set, then I need to follow the first two steps in the link (winsorize, single sorting). The macros are already there, but I do not know how to connect them... I would appreciate your help very much!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1602 views
  • 0 likes
  • 2 in conversation