BookmarkSubscribeRSS Feed
ZZB
Obsidian | Level 7 ZZB
Obsidian | Level 7

 I am trying to create a reference price measure that is an average of past 250 days stock prices, weighted by the probabilities of a stock not being traded since the date of the corresponding price:
reference_pricet=(pricet-250*turnover_ratiot-250*(1-turnover_ratiot-249)*(1-turnover_ratiot-248)*...*(1-turnover_ratiot-1)+pricet-249*turnover_ratiot-249*(1-turnover_ratiot-248)*(1-turnover_ratiot-247)*...*(1-turnover_ratiot-1)+...+pricet-1*turnover_ratiot-1)/k, where k is a constant that ensure price weights add up to 1 (see the formula below).

 

The following link is for STATA:

https://www.statalist.org/forums/forum/general-stata-discussion/general/1329146-generating-a-referen...

 

For each stock, how to code the reference price in SAS? Price, Turnover ratio each day are given.

 

Thanks very much! 

6 REPLIES 6
ZZB
Obsidian | Level 7 ZZB
Obsidian | Level 7

The format of the dataset is as follow:

 

ID             Date             Price             Turnover

AAA       1990/08/25         8                    0.05

AAA        1990/08/26         8.05               0.06

.....

BBB

....

 

CCC

 

and so on

ZZB
Obsidian | Level 7 ZZB
Obsidian | Level 7
I am not sure if my sas has it. How to check it?

If I have it, how to code it?
ballardw
Super User

@ZZB wrote:
I am not sure if my sas has it. How to check it?

If I have it, how to code it?

I think that you may actually want IML, SAS's matrix language more than ETS. ETS does time series analysis but I haven't had a license for 20 years so no practice...

To check license run:

Proc setinit;
run;

If you see SAS/ETS in the output of the log you have a license for ETS.

 

If you have the license run:

Proc product_status;
run;

to see if it is installed. If licensed and not installed then update the installation.

 

ZZB
Obsidian | Level 7 ZZB
Obsidian | Level 7

Any help? Thanks! 

ZZB
Obsidian | Level 7 ZZB
Obsidian | Level 7

I use the simple data steps to calculate the above formula, in this case I just replace "t-250" with "t-4" for simplicity. 

If I want to back to t-250, how to code efficiently?

 

/****************************************/

*proc printto log=junk;
proc expand data=MSF out=TO method=none;
by permno;
id date;
convert TO = Lead_TO / transformout=(lead 1);
run;
*proc printto;

data TO1;
set TO;
Lead_TO_1=1-Lead_TO;
run;


*proc printto log=junk;
proc expand data=TO1 (keep=permno date prc TO Lead_TO_1) out=TO2 method=none;
by permno;
id date;
convert Lead_TO_1 = CUM_Lead_TO3 / transformout=(MOVPROD 3 trimleft 2); *** 1990/5 vs. 1990/1, 3=Date interval - 1;
convert Lead_TO_1 = CUM_Lead_TO2 / transformout=(MOVPROD 2 trimleft 1); *** 1990/5 vs. 1990/2;
convert Lead_TO_1 = CUM_Lead_TO1 / transformout=(MOVPROD 1); *** 1990/5 vs. 1990/3;
run;
*proc printto;


*proc printto log=junk;
proc expand data=TO2 out=TO3 method=none;
by permno;
id date;
convert CUM_Lead_TO3 = Lead_CUM_Lead_TO3 / transformout=(lead 2); *** 1990/5 vs. 1990/1;
convert CUM_Lead_TO2 = Lead_CUM_Lead_TO2 / transformout=(lead 1); *** 1990/5 vs. 1990/2;
run;
*proc printto;

data TO4;
set TO3;
PRC4=PRC*TO*Lead_CUM_Lead_TO3;
PRC3=PRC*TO*Lead_CUM_Lead_TO2;
PRC2=PRC*TO*Lead_TO_1;
PRC1=PRC*TO;
run;

data TO4;
set TO4;
K4=TO*Lead_CUM_Lead_TO3;
K3=TO*Lead_CUM_Lead_TO2;
K2=TO*Lead_TO_1;
K1=TO;
run;

*proc printto log=junk;
proc expand data=TO4 out=TO5 method=none;
by permno;
id date;
convert PRC4 = LAG_TO4 / transformout=(lag 4);
convert PRC3 = LAG_TO3 / transformout=(lag 3);
convert PRC2 = LAG_TO2 / transformout=(lag 2);
convert PRC1 = LAG_TO1 / transformout=(lag 1);

convert K4 = LAG_K4 / transformout=(lag 4);
convert K3 = LAG_K3 / transformout=(lag 3);
convert K2 = LAG_K2 / transformout=(lag 2);
convert K1 = LAG_K1 / transformout=(lag 1);
run;
*proc printto;

data TO6;
set TO5;
RP=(LAG_TO4+LAG_TO3+LAG_TO2+LAG_TO1)/(LAG_K4+LAG_K3+LAG_K2+LAG_K1);
run;

 

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 6 replies
  • 1028 views
  • 0 likes
  • 3 in conversation