The summary of my question: I have a sas file ("KF.sas") that produces parameter estimates of state space model equations through Kalman Filter algorithm and Maximum Likelihood method. With inputs of individual fund's return, "KF.sas" produces the individual fund's parameter estimates. However, I need to find the parameter estimates of 200 mutual funds in order to do a bootstrap analysis or out-of-sample analysis. The number of mutual funds are overwhelming. Plus, I need to divide the time series of 16 years into 4 years and apply "KF.sas" to each 4 year periods. So, I am basically applying "KF.sas" to more than 200x4=800 times. Could you help me making a macro that applies "KF.sas" to a group of mutual funds?
Here is detail. Suppose that I have the following monthly return time series data of mutual funds, say work.mutualfunds :
The first column is trading month which runs over from 200207 to 201806, which gives you 192 months. For simplicity, let's assume that there are 10 funds, whose returns are in the columns ExPR_0:ExPR_9. The columns mktrf, SMB, VMG are market information. In order to find the parameter estimates of fund ExPR_0 over 200207 to 200606 (which is the first one-fourth row of the column ExPR_0), I can write a code as follows.
%let infile = work.mutualfunds;
%let variable1 = ExPR_0 (In fact, I first need to divide ExPR_0 (192 months) into 48 months, and then plug into variable 1);
%let variable2 = mktrf (In fact, I first need to divide ExPR_0 (192 months) into 48 months, and then plug into variable 2);
%let variable3 = SMB (In fact, I first need to divide ExPR_0 (192 months) into 48 months, and then plug into variable 3);
%let variable4 = VMG (In fact, I first need to divide ExPR_0 (192 months) into 48 months, and then plug into variable 4);
/* initial states and parameters required to run Kalman Filter*/
%let lead =0;
%let mu0=0;
%let sigma0 =0.7 ;
%let v = 0.3;
%let alpha =0.05;
%let beta=1;
%let gamma=0.15;
%let delta=1;
%let sigma_eta=0.7;
%let sigma_eps=0.01;
/* Condition for convergence in Maximum likelihood method*/
%let opt = %str ({0 2 2 2 2 2 2});
%let tc = %str ({3000 9000});
%let blc = %str ({ . . . . . 0 0,
. . . . . . .});
/* Run Kalman Filter*/
%include "KF.sas";
This produces the parameter estimates of an individual fund over 48 months. Could you give me some tips for making a macro for applying this to the rest of funds (ExPR_1:ExPR_9) and time periods (49-96 months, 97-144 months, 145-192 months) ?
For individual funds the above code takes 2 minutes to produce the result. The above is just an example. The number of mutual funds that I really need to deal with is more than 200. I am worried about the time it takes. I read a few articles that recommend BY-statement for Bootstrap analysis. However, I am not sure if similar BY-statement can be useful for my analysis.
I would be grateful if someone could help me. Thank you.
When making code dynamic, you need to follow these steps:
So you need to show us first what is relevant with regards to #2.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.