Help using Base SAS procedures

Cumulative returns per porfolio

Reply
Occasional Contributor
Posts: 14

Cumulative returns per porfolio

Dear Sas members,

I have two stocks per portfolio which I randomly selected.Each stock stays three days in the portfolio and have returns per day. Then the stocks are sold and are invested in the new portfolio.

So I have trouble in porgramming the following;

1) for every portfolio I have to calculate the cumulative return per stock (ok, works for me)

2) At the end of the portfolio (day 3) the stocks are sold and I have to sum the cumulative returns, divide it by two and reinvest it equally in the next two stocks of portfolio 2, and so on.

I have difficulties implementing step 2...

I have uploaded sample data in the attachement;

this is my code for step 1

proc

sort data=WORK.QUERY_FOR_RETURNS out

=RENDER;

by

PORT STOCK DATE;

run

;

 

data

POD_100;

set

RENDER;

by

PORT STOCK;

 

 

*Calculating the retunr per stock in the portfolio;

if first.stock then do

;

if ret=. then cumret=1

;

end

;

else if ret NE . then do

;

cumret=cumret*ret+cumret;

end

;

retain

cumret;

 

 

 

run

;

Attachment
Respected Advisor
Posts: 3,156

Cumulative returns per porfolio

I am not 100% sure about what you asked for. Here just to start discussion, if you are after the initial investment for each company:

data want (drop=_: cumret);

do until (last.port);

  set have;

   by port stock date;

   if first.port then do;

     _d=_c;

     _c=0;

invest=_d/2;

end;

   if first.stock then

               cumret=1;

   cumret+cumret*ret;

   if last.stock then _c+cumret;

   output;

end;

run;

Regards,

Haikuo

Occasional Contributor
Posts: 14

Cumulative returns per porfolio

Thanks,

But i should have the cumulative return of each stock in portfolio 1. After portfolio 1 the cumulative return of the stocks should be taken (summed/2) and invested against the returns of the stocks of portfolio 2 and so on.

kind regards,

Stefaan

Respected Advisor
Posts: 3,156

Cumulative returns per porfolio

I am still not sure I have completely understand what you want. I thought my solution could do what you just asked. if you could just post several line of data to show what your wanted table look like, that would definitely help.

Regards,

Haikuo

Ask a Question
Discussion stats
  • 3 replies
  • 846 views
  • 0 likes
  • 2 in conversation