asm help file and detailed description


asm: Stata Program to Construct J-K Overlapping Momentum Portfolios

[Download This Paper in PDF]

                                                                                                     https://www.dropbox.com/s/6ejxjpd8fplarxs/How%20asm%20works.pdf?dl=0

 

 

Attaullah Shah

 

Institute of Management Sciences, Peshawar

Email: attaullah.shah@imsciences.edu.pk

Working Paper

 

July 22, 2015

 

Abstract

 

In this working paper, I show how to use asm – a Stata program to construct J-K overlapping momentum portfolios. Also, I outline details of the primary functions/ features of the program. The methods used in this program for constructing momentum portfolios are generally in line with Jegadesh and Titman (1993). However, the program offers additional features that were suggested/used in more recent papers. For example, (i) the program offers to calculate one-period as well as n-periods cumulative holding periods returns; (ii) construct portfolios on the basis of winners and losers stocks that can be defined using any deciles of their past returns; (iii) construct momentum portfolios using daily, weekly, or monthly frequencies; (iv) skip user’s specified n-periods between formation and holding periods to control for bid-ask spread or non-synchronous trading and (v) perform t-tests on the holding period returns.

Program download details are available at

http://www.OpenDoors.Pk/home/paid-solutions/stata-program-to-construct-j-k-overlappy-momentum-portfolios-strategy


 

 

Contents

Abstract 1

1. Introduction. 3

2. Program Requirements. 3

3. Program Syntax Format 3

4. Options for Different Time Frequencies. 4

4.1 Daily Frequency. 4

4.2 Weekly Frequency. 4

4.3 Converting from Daily to Weekly Frequency. 4

4.4 Monthly Frequency. 5

4.5 Converting from Daily to Monthly Frequency. 5

4.5 Converting from Daily to any other Desirable Frequency. 5

5. Cumulative Periodic Returns. 6

6. T-tests Results Reporting. 6

7. Skipping Periods between Formation and Holding. 7

8. Ranking Deciles. 7

9. Results Directory. 8

10. Reading the Output Files. 8

11. Calculation of Formation and Holding Periods Returns. 9

11.1 Variables Names for Holding Period Returns. 9

11.2 The Missing Rows. 10

 


 

1. Introduction

In a seminal paper, Jegadesh and Titman (1993) documented evidence of the profitability of momentum portfolios. They calculated momentum portfolio returns as the difference between current returns of past winners stocks minus current returns of past losers stocks. For increasing power of their tests, they used portfolios with overlapping holding periods. Thus, for a given month m, , they suggested to hold  a  series  of portfolios  that  are  selected  in  the  current month  as  well  as  in  the  previous  K  - 1  months,  where  K  is  the  holding period. Specifically, a strategy that selects stocks on the basis of returns over the past J months and holds them for K months (referred as J-month/K-month  strategy)  is  constructed  as  follows:  At  the  beginning  of  each  month  m,  the securities  are ranked in ascending order on the  basis  of their  returns  in  the  past  J  months.  Based  on  these  rankings,  ten  decile portfolios  are  formed  that equally  weight  the  stocks  contained  in  the  top decile,  the  second  decile,  and  so  on.  The top decile portfolio is called the "losers" decile and the bottom decile is called the "winners" decile.  In each month m, the strategy buys the winner portfolio and sells the loser portfolio, holding this position for K months.

 

2. Program Requirements

The program written for momentum portfolio strategy is named as asm. asm has the following three requirements.

·         Stock returns named as ri

·         Market returns named as rm

·         Data set already declared as panel data, with the command xtset

If market returns are not needed, then simply generate rm variable with returns equal to zero, i.e.

gen rm=0

 

3. Program Syntax Format

asm follows the following syntax format:

asm # # , weekly monthly wgenerate mgenerate results directory bottom top skip cumulative

The underlined letters show that this is the minimum that the user will have to write to invoke a specific option.

The first # after asm is to specify the number of formation periods, while the second # is to specify the number of holding periods. For example,

asm 3 6

The above command uses formation periods up to 3 (i.e., J = 1, 2, 3) for ranking stocks on their past J-periods lagged returns and holding periods up to 6 (i.e., K = 1, 2, 3, 4, 5, 6). The holding period momentum portfolio returns will be saved to the directory “Results - F3 - T6 current_date_time” in the user’s current directory. Three files with the name F1.dta, F2.dta, and F3.dta will be created in that directory, each one corresponding to formations based on one period returns, formations based on two periods of returns, and formation based on three periods of returns. Each of these files will have periodic returns of winners stock (column WT), losers stock (LT) and winners minus losers (WML) for holding period 1, 2, 3, 4, 5, and 6.  Details of formation and holding periods’ returns are given in Section 5 and 6.

 

4. Options for Different Time Frequencies

asm can handle Stata date formats of daily, weekly, and monthly. Further, the program can convert stock returns from daily frequency into weekly or monthly frequency. Details and example of these options are given below.

 

4.1 Daily Frequency

If your data is in daily frequency, i.e. the date variable has spacing of one, then the command does not need any option related to date frequency. For example;

asm 3 6

The above command is also applicable to a data that has already been converted to weekly, monthly, or quarterly frequency and the date variable has spacing of one. If the date variable shows gaps of weeks, months, or quarters, then the above command will not work. In such cases, relevant option from the following should be chosen.

 

4.2 Weekly Frequency

Data that has been converted into weekly frequency and the date variable has weekly frequency, the weekly option needs to be used with asm. For example,

asm 3 6, weekly  (can also be written as asm 3 6, w)

It will use up to 3 periods of formation and up to 6 periods of holding. The option weekly tells the program that the stocks and market returns are already in weekly format and that the date variable has weekly frequency, hence the data does not need to be converted to weekly returns.

 

4.3 Converting from Daily to Weekly Frequency

If stock returns and market returns data has daily frequency and the date variable has spacing of one unit, it can be converted into weekly frequency using the wgenerate option. The wgenerate option uses the total function of egen package to convert returns from daily to weekly frequency. See the following example.

asm 6 12, wgenerate (can also we written as asm 6 12, wg)

It will use up to 6 periods of formation and up to 12 periods of holding. The option wgenerate tells the program that the stocks and market returns have daily frequency, and need to be converted into weekly returns.


4.4 Monthly Frequency

Monthly returns with date variable having monthly frequency, the option monthly needs to be used with asm. For example,

asm 8 12, monthly  (can also be written as asm 3 6, m)

It will use up to 8 periods of formation and up to 12 periods of holding. The option monthly tells the program that the stocks and market returns have already been converted into monthly frequency and that the date variable has monthly frequency, hence the data does not need to be converted to monthly returns.


4.5 Converting from Daily to Monthly Frequency

If stock returns and market returns data has daily frequency and the date variable has spacing of one unit, it can be converted into monthly frequency using the mgenerate option. The mgenerate option uses the total function of egen package to convert returns from daily to monthly frequency. See the following example.

asm 6 12, mgenerate (can also we written as asm 6 12, mg)

It will use up to 6 periods of formation and up to 12 periods of holding. The option mgenerate tells the program that the stocks and market returns have daily frequency, and need to be converted into monthly returns.


4.5 Converting from Daily to any other Desirable Frequency

Data in daily frequency can be converted into any desirable frequency using Stata’s built-in date functionality. In the following example, I illustrate conversion of daily returns into quarterly, and then feeding them to the asm program.

Save your data before applying the following code.

tempvar timevar q year

xtset

local id `r(panelvar)'

local timevar `r(timevar)'   

gen `year'=year(`timevar')

gen `q'=quarter(`timevar')

gen quarter_id=yq(`year', `q')

format %tq quarter_id

bys `id' quarter_id: egen ri_quarterly = total (ri) if ri! =.

bys `id' quarter_id : egen rm_quarterly = total (rm) if rm! =.

bys `id' quarter_id: keep if _n==_N

tsset `id' quarter_id

 

 

With the above code, both stock and market returns will be converted to quarterly frequency. Now asm can be applied as follows.

            asm 6 12

Note that no time related option was used with the above code. The reason is asm without time options assumes that the date variable increments by a value of one. The above code transforms the date variable first to quarterly frequency, then with the yq option to a quarterly form that increments by value of one. You can see it by applying the number format to quarter_id variable i.e.

format %9.0g quarter_id

browse

 

5. Cumulative Periodic Returns

The asm program offers two option to calculate holding period returns of the momentum portfolios. The first option calculates returns for a single period of K, while the second option calculates cumulative returns over specified number of holding periods, i.e  K=1 to K=n. For example,

asm 2 5, cumulative (can also we written as asm 6 12, c)

The above command will use two formation periods and five holding periods. The holding period returns will be calculated as follows:

Holding period 1: in the next period after formation, where  refer to stock returns in excess of market returns

Holding period 2:

Holding period 3: +

Holding period 4: +

Holding period 4: +

By default, the asm program calculates non-cumulative returns in the holding periods, hence no additional option is required for invoking single period returns.

 

6. T-tests Results Reporting

The program also offers to run t-tests on the momentum portfolio returns in the holding period. This can be done by using the option results. For example

asm 3 6, wgenerate results (can also be written as asm 3 6, w r)

It will use up to 3 periods of formation and up to 6 periods of holding. The option wgenerate tells the program that the stocks and market returns are in daily format, and need to be converted into weekly returns. The option results tells the program that one sample t-test should be applied to the holding periods’ momentum portfolio returns. This will generate MS Word files with names Formation_1.doc, Formation_2.doc, and Formation_3.doc, each one of these files will contain t-test results for each holding period returns.

 

7. Skipping Periods between Formation and Holding

Due to bid-ask spread problems and non-synchronous trading, research suggests that one period should be skipped between formation and holding periods (see, Jegadesh and Titman, 1993). asm offers the option to skip any desired number of periods between formation and holding periods. This can be done using the option skip (#).

asm 3 6, mgenerate results skip(1)

(Can also be written as asm 3 6, mg r s(1))

It will use up to 3 periods of formation and up to 6 periods of holding. The option mgenerate tells the program that the stocks and market returns are in daily format, and need to be converted into monthly returns. The option results tells the program that one sample t-test should be applied on the holding period momentum portfolio returns. The option skip(1) tells the program to skip one period between formation and holding period while estimating momentum portfolio holding period returns. If more than one periods are to be skipped, the option skip will take the form skip(#), i.e. for two periods skipping, the option will be skip(2) and so on. The default value of skip is zero.

 

8. Ranking Deciles

Jegadesh and Titman (1993) used only top and bottom 10% stocks for ranking winners and losers stocks. However, subsequent studies also used different deciles, for example, using top and bottom 30% stocks for ranking of winners and losers stocks. asm program offers the option of selecting any desired percentage for ranking. See the example given below.

asm 3 6, weekly bottom(0.3) top(0.7)

[Can also be written as asm 3 6, w b(0.3) t(0.7)]

It will use up to 3 periods of formation and up to 6 periods of holding. The option weekly tells the program that the stocks and market returns are already in weekly format, and do not need to be converted in to weekly returns. The options bottom (0.3) and top (0.7) tell the program the momentum portfolio returns should be based on top 30% winners minus bottom 30% losers stocks. The default values for bottom and top are 10.0001% and 90.0001%, respectively. If users need to specify any other criteria, the bottom and top values can be changed accordingly.

asm 3 6, monthly directory (Test7)

[can also be written as asm 3 6, m d(test7)]

It will use up to 3 periods of formation and up to 6 periods of holding. The option monthly tells the program that the stocks and market returns are already in monthly format, and do not need to be converted in to monthly returns. The options directory tells the program to make a separate directory for momentum files and any other results file in the user’s current directory with the name Test7 current date_time

 

9. Results Directory

asm saves results to a new directory each time it is run. The directory is made in the user’s current directory with name structure of “Results – F# - T# - Current date current time”. However, if the director option is used, the results will be saved to the user’s specified directory. For example;

asm 3 6, results directory (Test1)

It will use up to 3 periods of formation and up to 6 periods of holding. The option results tells the program that one sample t-test should be applied on the holding period momentum portfolio returns. The options directory tells the program to make a separate directory for momentum files and any other results file in the user’s current directory with the name Test1 current date_time”.

 

10. Reading the Output Files

asm creates a separate directory for results with the structure of  “F_# - T_# - current date current time” in the users current director, and generates a clickable link to the results directory once all processes are complete. It also offers the option of directory (users specified directory name) with the structure of “user-specified name current date time”. The program generates files with names F_1.dta, F_2.dta, F3.dta and so on. The letter F refers to number of formation periods, thus for 5 formation periods i.e. J = 1, 2, 3, 4, 5, the program will make five files with names ranging from F_1 to F_5.dta. Each of these five files contain the following variables;

timevar WT#  LT#  WML#

Where timevar tracks the period in which the holding returns were calculated, this can be days, weeks, months, or quarters, depending upon the nature of the data or type of options used. i.e mgenerate, or wgenerate.

WT# refers to winner stocks returns using # number of holding periods. For example, for one period of formation, we have the next period i.e. period 2 for holding. Immediately after ranking of stocks on the basis of one period formation, the equally weighted returns of top 10% stock (ranking is done on the basis of stock returns in period 1) in the next holding period are recorded in variable WT1. Similarly, using one period formation and 2 periods of holding, the first two periods are used in ranking and the first holding period available starts from period 3. This way, the variable WT2 records returns of top 10% stocks in the holding period that are two periods away from the formation period.

Similarly, LT# refers to loser stocks returns using # number of holding periods. For example, for one period of formation, we have the next period i.e. period 2 for holding. Immediately after ranking of stocks on the basis of one period formation, the equally weighted returns of bottom 10% stocks (based on the ranking in period 1) in the holding periods are recorded in variable LT1. Similarly, using one period formation and two periods of holding, the first holding period be available is from period 3. This way, the variable LT2 records returns of bottom 10% stocks in the holding period that are two periods away from the formation period.

And finally, WML# refers to the LT# minus WT# i.e. return of winner stocks minus returns of losers stocks.

 

11. Calculation of Formation and Holding Periods Returns

Using mgenerate and wgenerate options, the returns calculations over n-periods follow a method of simple summation, using total function of the egen package.

 

11.1 Variables Names for Holding Period Returns

Using one period formation and one period holding, the formation period returns are available in period 1, however the holding period returns are available from period 2. So the figures in Table 1 can be read as:

WT1= the average returns in holding period (i.e., one period after the formation) of those stocks which were included in top 10% stocks in the formation period in period 1

LT1 = the average returns in holding period (i.e., one period after the formation) of those stocks which were included in the bottom 10% stocks in the formation period in period 1

WML1 = WT – LT

Table 1: Holding period returns using one formation and four holding periods

date

date

WT1

LT1

WML1

WT2

LT2

WML2

WT3

LT3

WML3

1

1960m1

1

1960m2

0.016705

0.029236

-0.01253

1

1960m3

0.003381

-0.03921

0.042594

-0.04387

0.017505

-0.06137

4

1960m4

0.039224

-0.0128

0.05202

0.022803

-0.00248

0.025279

-0.00643

0.023637

-0.03007

5

1960m5

0.009822

-0.01022

0.020042

0.090786

-0.01649

0.10728

0.021073

0.002225

0.018849

6

1960m6

-0.09871

-0.18403

0.085317

-0.11556

-0.17509

0.059534

-0.12851

-0.19679

0.068281

7

1960m7

-0.03534

0.004865

-0.04021

-0.03031

0.014989

-0.0453

-0.03507

0.023387

-0.05846

8

1960m8

-0.05672

-0.02388

-0.03284

-0.02278

-0.07614

0.053362

-0.06324

-0.05961

-0.00363

9

1960m9

0.050374

0.002217

0.048157

0.00934

0.029376

-0.02004

0.022209

0.012115

0.010095

10

1960m10

-0.04879

-0.06443

0.01564

-0.01844

-0.07776

0.059322

-0.05396

-0.0038

-0.05017

 


 

11.2 The Missing Rows

In constructing formation period portfolios, we lose periods for which holding period returns cannot be obtained. In one period formation-holding portfolios, we lose the first period in forming the portfolio and hence the number of holding periods available for portfolio construction are N – (NF + NH) - 1, where N is the total number of periods available, NF refer to the number of formation periods, and NH refers to number of testing periods. In Table 1, we use a total of 10 periods, so for one period formation, we have a total of 9 holding periods available. The first period is lost in formation. Similarly, for one period formation and two periods holding (reported under WT2, LT2, WML2 columns), we have 8 periods available for holding, that is, first periods is lost in formation and the last period cannot be used for both formation and holding, hence period number 10 is also lost. The same goes for other combinations.

For any query or comments, please contact at attaullah.shah@imsciences.edu.pk

 

 

                                                 **************