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

hi there, How do i compute monthly stock returns using monthly end prices in sas. The data i have is for 500 different stocks stacked together.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

proc sort data=sashelp.stocks out=stocks;

by stock date;

run;

data returns;

set stocks;

by stock;

prev_open=lag(open);

return=log(open/prev_open);

if first.stock then return=.;

run;

View solution in original post

10 REPLIES 10
Astounding
PROC Star

Is your data already in a SAS data set?

If not, what are your plans to get it into a SAS data set?

If it is already a SAS data set, what are the names of the variables?  Which ones are character and which ones are numeric?

Is the data complete (no months skipped in the middle)?

Do you want month over month returns, or some other returns?


ivanpersie
Fluorite | Level 6

Yes its already in Sas. The Variable names are DATE TICKER  PRICE  .....All of them are Character. All months are available. And i want month over month returns

Reeza
Super User

How are you defining RETURN?

ivanpersie
Fluorite | Level 6

Return = Ln(Price t/ Price t-1)...where price t is today's price and price t-1 is previous month price of a given ticker.

Reeza
Super User

proc sort data=sashelp.stocks out=stocks;

by stock date;

run;

data returns;

set stocks;

by stock;

prev_open=lag(open);

return=log(open/prev_open);

if first.stock then return=.;

run;

ivanpersie
Fluorite | Level 6

Thanks a bunch. It worked out well.

naveen_srini
Quartz | Level 8

Hi, I wondering you are having problems in how to frame or ask a question by explaining the right set of details. Let the folks know,

1. what does your input dataset have

2. variable names and type

3. Your wanted output i.e present us a figure of your sample dataset: have(your input dataset) and want(your output dataset)

4. a Convert business logic or formula, something like a defined business requirement that is meant to be used in the input to get your wanted output.

5. size of the dataset, long or wide and how big?

I think had a link or a page that explains how to ask a question.  You really need to let us the folks know as much details(simulated) as possible to get the best possible help.

ivanpersie
Fluorite | Level 6

Just another step, how do i compute the trailing/rolling standard deviation for the returns i have generated for the different Tickers/stocks

omer2020
Obsidian | Level 7
proc sort data=input; by tic date; run;
proc expand data=input out=output method = none ;
by tic;
convert ret= ret; convert ret=RETVOL / transformout=(MOVSTD 4); * 4 = number of 4 past/trailing obs to calculate std;
label RETVOL =rollingSTDofRET;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 10 replies
  • 3405 views
  • 3 likes
  • 5 in conversation