Contributor
Posts: 27

# Monthly stock returns from monthly prices

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.

Super User
Posts: 5,511

## Re: Monthly stock returns from monthly prices

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?

Contributor
Posts: 27

## Re: Monthly stock returns from monthly prices

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

Super User
Posts: 19,815

## Re: Monthly stock returns from monthly prices

How are you defining RETURN?

Contributor
Posts: 27

## Re: Monthly stock returns from monthly prices

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.

Super User
Posts: 19,815

## Re: Monthly stock returns from monthly prices

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;

Contributor
Posts: 27

## Re: Monthly stock returns from monthly prices

Thanks a bunch. It worked out well.

Frequent Contributor
Posts: 115

## Re: Monthly stock returns from monthly prices

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

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.

Super User
Posts: 19,815

Contributor
Posts: 27

## Re: Monthly stock returns from monthly prices

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

Contributor
Posts: 22

[ Edited ]