<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Momentum Strategy in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Momentum-Strategy/m-p/572670#M7738</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to replicate Jegadeesh and Titman's (1993) results. I found a code online and just need to makes a few changes to the code to complete both parts of their study.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So basically the thing that I have yet to accpmplish is to construct portfolios that are held one month after they were formed. For example, portfolio A is formed based from the returns of the previous 12 months and it will actually be held one month after it was formed, i.e. if formation date= t; formation period is t-12 months and holding period is t+1 month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS and what I basically did was to create a lag of the date variable and use that as the formation date. Can you guys let me know if what I did was correct given what I was trying to accomplish.&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* ********************************************************************************* */
/* ************** W R D S   R E S E A R C H   A P P L I C A T I O N S ************** */
/* ********************************************************************************* */
/* Summary   : Replicates Jegadeesh and Titman (JF, 1993) Momentum Portfolios        */
/* Date      : November 2004. Modified January, 2011                                 */
/* Author    : Gjergji Cici and Rabih Moussawi, WRDS                                 */
/* Variables : - J: # of Months in Formation Period to Create Momentum Portfolios    */
/*             - K: # of Months in Holding   Period to Buy and Hold Mom. Ports.      */
/*             - BEGDATE: Sample Start Date                                          */
/*             - ENDDATE: Sample End Date                                            */
/* ********************************************************************************* */
 
/* Step 1. Specifying Options */
%let J=12; /* Formation Period Length: J can be between 3 to 12 months */
%let K=3; /* Holding   Period Length: K can be between 3 to 12 months */
 
/* Jegadeesh and Titman's Footnote 4 page 69: 1965-1989 are holding period dates */
/* Need 2 years of return history to form mometum portfolios that start in 1965  */
%let begdate=01JAN1963;
%let enddate=31DEC1989;
 
/* Step 2. Extract CRSP Data for NYSE and AMEX Common Stocks */
/* Merge historical codes with CRSP Monthly Stock File       */
/* Restriction on Share Code: common shares only             */
/*      and Exchange Code: NYSE and AMEX securities only     */
%let filtr = (shrcd in (10,11) and exchcd in (1,2));
/*  Selected variables from the CRSP Monthly Stock File      */
%let fvars =  prc ret shrout cfacpr cfacshr;
/*  Selected variables from the CRSP Monthly Event File      */
%let evars =  shrcd exchcd siccd;
/* Invoke CRSPMERGE WRDS Research Macro. Data Output: CRSP_M */
%crspmerge(s=m,start=&amp;amp;begdate,end=&amp;amp;enddate,sfvars=&amp;amp;fvars,sevars=&amp;amp;evars,filters=&amp;amp;filtr);
 
/* Step 3. Create Momentum Port. Measures Based on Past (J) Month Compounded Returns */
/* Make sure to keep stocks with available return info in the formation period */
proc printto log=junk;
proc expand data=crsp_m (keep=permno date ret) out=umd method=none;
by permno;
id date;
convert ret = cum_return / transformin=(+1) transformout=(MOVPROD &amp;amp;J -1 trimleft &amp;amp;J);
quit;
proc printto; run;
 
/* Formation of 10 Momentum Portfolios Every Month */
proc sort data=umd; by date; run;
proc rank data=umd out=umd group=10;
  by date;
    var cum_return;
    ranks momr;
run;
 
/* Step 4. Assign Ranks to the Next 6 (K) Months After Portfolio Formation */
/* MOMR is the portfolio rank variable taking values between 1 and 10: */
/*          1 - the lowest  momentum group: Losers   */
/*         10 - the highest momentum group: Winners  */
data umd;
set umd (drop=cum_return);
where momr&amp;gt;=0;
momr=momr+1;
prevdate = lag(date);
HDATE1 = intnx("MONTH",date, 1,"B");
HDATE2 = intnx("MONTH",date,&amp;amp;K,"E");
label momr = "Momentum Portfolio";
label prevdate = "Formation Date";
label HDATE1= "First Holding Date";
label HDATE2= "Last Holding Date";
rename prevdate=form_date;
run;
 
proc sort data=umd nodupkey; by permno form_date; run;
 
/* Portfolio returns are average monthly returns rebalanced monthly */
proc sql;
    create table umd2
    as select distinct a.momr, a.form_date, a.permno, b.date, b.ret
    from umd as a, crsp_m as b
    where a.permno=b.permno
    and a.HDATE1&amp;lt;=b.date&amp;lt;=a.HDATE2;
quit;
 
/* Step 5. Calculate Equally-Weighted Average Monthly Returns */
proc sort data=umd2 nodupkey; by date momr form_date permno; run;
 
/* Calculate Equally-Weighted returns across portfolio stocks */
/* Every date, each MOM group has J portfolios identified by formation date */
proc means data = umd2 noprint;
  by date momr form_date;
    var ret;
    output out = umd3 mean=ret;
run;
 
/* Portfolio average monthly returns */
proc sort data=umd3; by date momr;
    where year(date) &amp;gt;= year("&amp;amp;begdate"d)+2;
run;
 
/* Create one return series per MOM group every month */
proc means data = umd3 noprint;
  by date momr;
    var ret;
    output out = ewretdat mean= ewret std = ewretstd;
run;
 
proc sort data=ewretdat; by momr ; run;
 
Title "Jegadeesh and Titman (1993) Table 1: Returns of Relative Strength Portfolios";
Title2 "Portfolios based on &amp;amp;J month lagged return and held for &amp;amp;K months";
 
proc means data=ewretdat n mean t probt;
  class momr;
    var ewret;
run;
 
/* Step 6. Calculate Long-Short Portfolio Returns */
proc sort data=ewretdat; by date momr; run;
proc transpose data=ewretdat out=ewretdat2
     (rename = (_1=LOSERS _2=PORT2 _3=PORT3 _4=PORT4 _5=PORT5
                     _6=PORT6 _7=PORT7 _8=PORT8 _9=PORT9 _10=WINNERS)
       drop=_NAME_ _LABEL_);
  by date;
  id momr;
   var ewret;
run;
 
/* Compute Long-Short Portfolio Cumulative Returns */
data ewretdat3;
set ewretdat2;
by DATE;
LONG_SHORT=WINNERS-LOSERS;
retain CUMRET_WINNERS CUMRET_LOSERS CUMRET_LONG_SHORT 0;
CUMRET_WINNERS     = (CUMRET_WINNERS+1)*(WINNERS+1)-1;
CUMRET_LOSERS      = (CUMRET_LOSERS +1)*(LOSERS +1)-1;
CUMRET_LONG_SHORT  = (CUMRET_LONG_SHORT+1)*(LONG_SHORT+1)-1;
format WINNERS LOSERS LONG_SHORT PORT: CUMRET_: percentn12.1;
run;
 
proc means data=ewretdat3 n mean t probt;
var WINNERS LOSERS LONG_SHORT;
run;
 
/* Step 7. Plot Time Series of Portfolio Returns */
axis1 label=none;
symbol interpol =join w = 4;
proc gplot data = ewretdat3;
   Title 'Time Series of Cumulative Momentum Portfolio Returns' ;
   Title2 "Based on Jegadeesh and Titman (1993) Momentum Portfolios " ;
   plot (CUMRET_WINNERS CUMRET_LOSERS)*date
        / overlay legend vaxis=axis1;
   format date year.;
run; quit;
 
proc gplot data = ewretdat3;
   Title 'Performance of Long/Short Momentum Strategy' ;
   Title2 "Based on Jegadeesh and Titman (1993) Momentum Portfolios";
   plot (CUMRET_LONG_SHORT)*date
        / overlay legend vaxis=axis1;
   format date year.;
run; quit;
 
/* ********************************************************************************* */
/* *************  Material Copyright Wharton Research Data Services  *************** */
/* ****************************** All Rights Reserved ****************************** */
/* ********************************************************************************* */&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 11 Jul 2019 12:07:13 GMT</pubDate>
    <dc:creator>arenq</dc:creator>
    <dc:date>2019-07-11T12:07:13Z</dc:date>
    <item>
      <title>Momentum Strategy</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Momentum-Strategy/m-p/572670#M7738</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to replicate Jegadeesh and Titman's (1993) results. I found a code online and just need to makes a few changes to the code to complete both parts of their study.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So basically the thing that I have yet to accpmplish is to construct portfolios that are held one month after they were formed. For example, portfolio A is formed based from the returns of the previous 12 months and it will actually be held one month after it was formed, i.e. if formation date= t; formation period is t-12 months and holding period is t+1 month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS and what I basically did was to create a lag of the date variable and use that as the formation date. Can you guys let me know if what I did was correct given what I was trying to accomplish.&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* ********************************************************************************* */
/* ************** W R D S   R E S E A R C H   A P P L I C A T I O N S ************** */
/* ********************************************************************************* */
/* Summary   : Replicates Jegadeesh and Titman (JF, 1993) Momentum Portfolios        */
/* Date      : November 2004. Modified January, 2011                                 */
/* Author    : Gjergji Cici and Rabih Moussawi, WRDS                                 */
/* Variables : - J: # of Months in Formation Period to Create Momentum Portfolios    */
/*             - K: # of Months in Holding   Period to Buy and Hold Mom. Ports.      */
/*             - BEGDATE: Sample Start Date                                          */
/*             - ENDDATE: Sample End Date                                            */
/* ********************************************************************************* */
 
/* Step 1. Specifying Options */
%let J=12; /* Formation Period Length: J can be between 3 to 12 months */
%let K=3; /* Holding   Period Length: K can be between 3 to 12 months */
 
/* Jegadeesh and Titman's Footnote 4 page 69: 1965-1989 are holding period dates */
/* Need 2 years of return history to form mometum portfolios that start in 1965  */
%let begdate=01JAN1963;
%let enddate=31DEC1989;
 
/* Step 2. Extract CRSP Data for NYSE and AMEX Common Stocks */
/* Merge historical codes with CRSP Monthly Stock File       */
/* Restriction on Share Code: common shares only             */
/*      and Exchange Code: NYSE and AMEX securities only     */
%let filtr = (shrcd in (10,11) and exchcd in (1,2));
/*  Selected variables from the CRSP Monthly Stock File      */
%let fvars =  prc ret shrout cfacpr cfacshr;
/*  Selected variables from the CRSP Monthly Event File      */
%let evars =  shrcd exchcd siccd;
/* Invoke CRSPMERGE WRDS Research Macro. Data Output: CRSP_M */
%crspmerge(s=m,start=&amp;amp;begdate,end=&amp;amp;enddate,sfvars=&amp;amp;fvars,sevars=&amp;amp;evars,filters=&amp;amp;filtr);
 
/* Step 3. Create Momentum Port. Measures Based on Past (J) Month Compounded Returns */
/* Make sure to keep stocks with available return info in the formation period */
proc printto log=junk;
proc expand data=crsp_m (keep=permno date ret) out=umd method=none;
by permno;
id date;
convert ret = cum_return / transformin=(+1) transformout=(MOVPROD &amp;amp;J -1 trimleft &amp;amp;J);
quit;
proc printto; run;
 
/* Formation of 10 Momentum Portfolios Every Month */
proc sort data=umd; by date; run;
proc rank data=umd out=umd group=10;
  by date;
    var cum_return;
    ranks momr;
run;
 
/* Step 4. Assign Ranks to the Next 6 (K) Months After Portfolio Formation */
/* MOMR is the portfolio rank variable taking values between 1 and 10: */
/*          1 - the lowest  momentum group: Losers   */
/*         10 - the highest momentum group: Winners  */
data umd;
set umd (drop=cum_return);
where momr&amp;gt;=0;
momr=momr+1;
prevdate = lag(date);
HDATE1 = intnx("MONTH",date, 1,"B");
HDATE2 = intnx("MONTH",date,&amp;amp;K,"E");
label momr = "Momentum Portfolio";
label prevdate = "Formation Date";
label HDATE1= "First Holding Date";
label HDATE2= "Last Holding Date";
rename prevdate=form_date;
run;
 
proc sort data=umd nodupkey; by permno form_date; run;
 
/* Portfolio returns are average monthly returns rebalanced monthly */
proc sql;
    create table umd2
    as select distinct a.momr, a.form_date, a.permno, b.date, b.ret
    from umd as a, crsp_m as b
    where a.permno=b.permno
    and a.HDATE1&amp;lt;=b.date&amp;lt;=a.HDATE2;
quit;
 
/* Step 5. Calculate Equally-Weighted Average Monthly Returns */
proc sort data=umd2 nodupkey; by date momr form_date permno; run;
 
/* Calculate Equally-Weighted returns across portfolio stocks */
/* Every date, each MOM group has J portfolios identified by formation date */
proc means data = umd2 noprint;
  by date momr form_date;
    var ret;
    output out = umd3 mean=ret;
run;
 
/* Portfolio average monthly returns */
proc sort data=umd3; by date momr;
    where year(date) &amp;gt;= year("&amp;amp;begdate"d)+2;
run;
 
/* Create one return series per MOM group every month */
proc means data = umd3 noprint;
  by date momr;
    var ret;
    output out = ewretdat mean= ewret std = ewretstd;
run;
 
proc sort data=ewretdat; by momr ; run;
 
Title "Jegadeesh and Titman (1993) Table 1: Returns of Relative Strength Portfolios";
Title2 "Portfolios based on &amp;amp;J month lagged return and held for &amp;amp;K months";
 
proc means data=ewretdat n mean t probt;
  class momr;
    var ewret;
run;
 
/* Step 6. Calculate Long-Short Portfolio Returns */
proc sort data=ewretdat; by date momr; run;
proc transpose data=ewretdat out=ewretdat2
     (rename = (_1=LOSERS _2=PORT2 _3=PORT3 _4=PORT4 _5=PORT5
                     _6=PORT6 _7=PORT7 _8=PORT8 _9=PORT9 _10=WINNERS)
       drop=_NAME_ _LABEL_);
  by date;
  id momr;
   var ewret;
run;
 
/* Compute Long-Short Portfolio Cumulative Returns */
data ewretdat3;
set ewretdat2;
by DATE;
LONG_SHORT=WINNERS-LOSERS;
retain CUMRET_WINNERS CUMRET_LOSERS CUMRET_LONG_SHORT 0;
CUMRET_WINNERS     = (CUMRET_WINNERS+1)*(WINNERS+1)-1;
CUMRET_LOSERS      = (CUMRET_LOSERS +1)*(LOSERS +1)-1;
CUMRET_LONG_SHORT  = (CUMRET_LONG_SHORT+1)*(LONG_SHORT+1)-1;
format WINNERS LOSERS LONG_SHORT PORT: CUMRET_: percentn12.1;
run;
 
proc means data=ewretdat3 n mean t probt;
var WINNERS LOSERS LONG_SHORT;
run;
 
/* Step 7. Plot Time Series of Portfolio Returns */
axis1 label=none;
symbol interpol =join w = 4;
proc gplot data = ewretdat3;
   Title 'Time Series of Cumulative Momentum Portfolio Returns' ;
   Title2 "Based on Jegadeesh and Titman (1993) Momentum Portfolios " ;
   plot (CUMRET_WINNERS CUMRET_LOSERS)*date
        / overlay legend vaxis=axis1;
   format date year.;
run; quit;
 
proc gplot data = ewretdat3;
   Title 'Performance of Long/Short Momentum Strategy' ;
   Title2 "Based on Jegadeesh and Titman (1993) Momentum Portfolios";
   plot (CUMRET_LONG_SHORT)*date
        / overlay legend vaxis=axis1;
   format date year.;
run; quit;
 
/* ********************************************************************************* */
/* *************  Material Copyright Wharton Research Data Services  *************** */
/* ****************************** All Rights Reserved ****************************** */
/* ********************************************************************************* */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Jul 2019 12:07:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Momentum-Strategy/m-p/572670#M7738</guid>
      <dc:creator>arenq</dc:creator>
      <dc:date>2019-07-11T12:07:13Z</dc:date>
    </item>
  </channel>
</rss>

