BookmarkSubscribeRSS Feed
OzoneX15
Calcite | Level 5

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

;

3 REPLIES 3
Haikuo
Onyx | Level 15

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

OzoneX15
Calcite | Level 5

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

Haikuo
Onyx | Level 15

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

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 1810 views
  • 0 likes
  • 2 in conversation