Singapore Lecture3

42
Applied Financial Econometrics using Stata 3. Linear Factor Models Stan Hurn Queensland University of Technology Hurn (QUT) Applied Financial Econometrics using Stata 1 / 40

Transcript of Singapore Lecture3

Page 1: Singapore Lecture3

Applied Financial Econometrics using Stata3. Linear Factor Models

Stan Hurn

Queensland University of Technology

Hurn (QUT) Applied Financial Econometrics using Stata 1 / 40

Page 2: Singapore Lecture3

Introduction to .do Files

Hurn (QUT) Applied Financial Econometrics using Stata 2 / 40

Page 3: Singapore Lecture3

The Problem

One of the most common problems in empirical asset pricing concerns theestimation and evaluation of linear factor models. There is a largeliterature on the econometric techniques to estimate and evaluate thesemodels which deals with the following questions.

how to estimate parameters

how to calculate standard errors of the pricing errors

how to test the model

Hurn (QUT) Applied Financial Econometrics using Stata 3 / 40

Page 4: Singapore Lecture3

The Data

The data are monthly percentage returns for the period July 1926 toDecember 2013 (T = 1050) on 25 portfolios (r1 to r25) sorted in terms ofsize and book-to-market values together with the risk free (US Treasurybill rate) and the return on the market (S&P500 index). The data arefreely available from Ken French’s website:

http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html

The series in the file fama french.dta are:r1 · · · r25 = monthly returns to the portfoliosrm rf = excess market returnrf = riskfree rate of return

I will upload another file famafrench.dta which will contain someadditional series for you to play around with.

Hurn (QUT) Applied Financial Econometrics using Stata 4 / 40

Page 5: Singapore Lecture3

A First .do File

set more offversion 13clear *

// set up a log filecapture log close capmlog using capm, name(capm) replace

// set current working directorycd ~/Dropbox/Teaching/Singapore/do

// load the data and add a few labelsuse fama_french.dta, clearlabel variable rm "Market Return"label variable rf "Risk Free Rate"

// format date variable and set data set as time seriesformat %td dateid01tsset dateid01

Hurn (QUT) Applied Financial Econometrics using Stata 5 / 40

Page 6: Singapore Lecture3

When Run ...

. set more off

. version 13

. clear *

.

. // set up a log file

. capture log close capm

. log using capm, name(capm) replace

name: capmlog: /Users/stanhurn/Dropbox/TEACHING/SIngapore/do/capm.smcl

log type: smclopened on: 13 Mar 2014, 17:24:36

.

. // set current working directory

. cd ~/Dropbox/Teaching/Singapore/do/Users/stanhurn/Dropbox/TEACHING/SIngapore/do

.

. // load the data and add a few labels

. use fama_french.dta, clear

. label variable rm "Market Return"

. label variable rf "Risk Free Rate"

.

Hurn (QUT) Applied Financial Econometrics using Stata 6 / 40

Page 7: Singapore Lecture3

Some plots

// format date variable and set data set as time seriesformat %td dateid01tsset dateid01

// plot return on market and rf on same graph using same y-axestwoway (tsline rm) (tsline rf), name(factors0, replace) ///

tlabel(,angle(forty_five) format(%tdCCYY)) xtitle("")

graph export "../factors0.pdf", as(pdf) replace

// plot return on market and rf on same graph using different y-axestwoway (tsline rm, yaxis(1)) (tsline rf, yaxis(2)), name(factors, replace) ///

tlabel(,angle(forty_five) format(%tdCCYY)) xtitle("")

graph export "../factors.pdf", as(pdf) replace

Hurn (QUT) Applied Financial Econometrics using Stata 7 / 40

Page 8: Singapore Lecture3

Plot of the Market Return and Risk Free Rate-4

0-2

00

2040

1930

1940

1950

1960

1970

1980

1990

2000

2010

Market Return Risk Free Rate

Hurn (QUT) Applied Financial Econometrics using Stata 8 / 40

Page 9: Singapore Lecture3

Plot of the Market Return and Risk Free Rate

0.5

11.

5Ri

sk F

ree

Rate

-40

-20

020

40M

arke

t Ret

urn

1930

1940

1950

1960

1970

1980

1990

2000

2010

Market Return Risk Free Rate

Hurn (QUT) Applied Financial Econometrics using Stata 9 / 40

Page 10: Singapore Lecture3

Estimating a Simple CAPM

Hurn (QUT) Applied Financial Econometrics using Stata 10 / 40

Page 11: Singapore Lecture3

One Factor Pricing Model

Define the excess returns zit = rit − rf . If the pricing factor, ft is also anexcess return then the fundamental pricing model states that the excessreturns are linear in the betas

E(zit) = βE(ft) .

This model is usually evaluated in the form of a time-series linearregression

zit = αi + βi ft + uit .

Comparing the model and the expectation of the time-series regression, itfollows that all the regression intercepts αi should be zero. In other wordsthe regression intercepts are equal to the pricing errors.

Hurn (QUT) Applied Financial Econometrics using Stata 11 / 40

Page 12: Singapore Lecture3

When Run ...

. // estimate CAPM for first portfolio and test alpha = 0 and beta = 1

. reg z1 rm_rf

Source SS df MS Number of obs = 1021F( 1, 1019) = 1103.83

Model 79600.6792 1 79600.6792 Prob > F = 0.0000Residual 73483.5518 1019 72.1133973 R-squared = 0.5200

Adj R-squared = 0.5195Total 153084.231 1020 150.082579 Root MSE = 8.492

z1 Coef. Std. Err. t P>|t| [95% Conf. Interval]

rm_rf 1.63492 .0492092 33.22 0.000 1.538357 1.731483_cons -.5916513 .2676044 -2.21 0.027 -1.11677 -.0665325

.

. // test the model

. test _cons

( 1) _cons = 0

F( 1, 1019) = 4.89Prob > F = 0.0273

. test rm_rf=1

( 1) rm_rf = 1

F( 1, 1019) = 166.47Prob > F = 0.0000

. test (_cons=0) (rm_rf=1)

( 1) _cons = 0( 2) rm_rf = 1

F( 2, 1019) = 83.49Prob > F = 0.0000

Hurn (QUT) Applied Financial Econometrics using Stata 12 / 40

Page 13: Singapore Lecture3

Estimation of the CAPM

There are at least four ways to estimate the simple CAPM for all 25portfolios in Stata:

1 Equation-by-equation OLS. Loop over the excess returns and estimateeach equation.

2 Use the mveqn command. Performs equation-by-equation OLSautomatically.

3 Use the sureg command which performs seemingly unrelatedregressions.

4 Reshape the data as long format and use statsby prefix.

Hurn (QUT) Applied Financial Econometrics using Stata 13 / 40

Page 14: Singapore Lecture3

The Commands

// generate excess returnslocal N = 25forvalues i = 1/‘N’

qui gen z‘i’ = r‘i’ - rf

drop r1-r9 // note use of hyphen r10 comes right after r1

// at least four ways to do this estimation

forvalues i = 1/‘N’ qui regress z‘i’ rm_rf

qui mvreg z* = rm_rf

qui sureg z* = rm_rf

qui reshape long z, i(dateid01) j(portfolio)qui statsby _b _se, by(portfolio) saving(simplecapm, replace): reg z rm_rf

Hurn (QUT) Applied Financial Econometrics using Stata 14 / 40

Page 15: Singapore Lecture3

The Reshape Command

. reshape long z, i(dateid01) j(portfolio)(note: j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25)

Data wide -> long

Number of obs. 1021 -> 25525Number of variables 29 -> 6j variable (25 values) -> portfolioxij variables:

z1 z2 ... z25 -> z

Hurn (QUT) Applied Financial Econometrics using Stata 15 / 40

Page 16: Singapore Lecture3

The Data in Long Format

Hurn (QUT) Applied Financial Econometrics using Stata 16 / 40

Page 17: Singapore Lecture3

Testing Pricing Errors

Hurn (QUT) Applied Financial Econometrics using Stata 17 / 40

Page 18: Singapore Lecture3

Basic Results

Recall from the results of the classical two-variable regression model

α ∼ N

(α0,

s2

T

[1 +

f2

var(f )

])

where s2 is the variance of the residuals of the regression.The Wald test of the restriction that αi is zero (no pricing error in the i th

equation) is then given by dividing the coefficient estimate squared by itsvariance

J = T

[1 +

(f2

var(f )

)]−1α2i

s2∼ χ2

1

Hurn (QUT) Applied Financial Econometrics using Stata 18 / 40

Page 19: Singapore Lecture3

Joint Wald Test

We also want to know if all the pricing errors are jointly equal to zero. Wenow have to think of the time-series regressions as a panel regression withcorrelated errors, E(uitujt) 6= 0. The classic form of the test assumes noautocorrelation or heteroskedasticity so the the Wald test of the jointrestrictions is given by

J = T

[1 +

(f2

var(f )

)]−1ααα′ ΣΣΣ

−1ααα

a∼ χ2N

= aT ααα′ ΣΣΣ−1ααα.

with ααα = [α1 α2 · · · αN ]′ and ΣΣΣ is the residual covariance matrix. Forconvenience, the test is often written just with a positive scaling constantaT which depends on the sample size and the factor.

Hurn (QUT) Applied Financial Econometrics using Stata 19 / 40

Page 20: Singapore Lecture3

Gibbons, Ross, Shanken Test

The Wald test is asymptotical valid. A finite-sample F test is alsoavailable, known as the Gibbons, Ross, Shanken or GRS test, given by

GRS =T − N − 1

N

[1 +

(f2

var(f )

)]−1ααα′ ΣΣΣ

−1ααα ∼ FN,T−N−1

The F distribution recognises the sample variation in the estimation of ΣΣΣwhich is not accounted for the asymptotic Wald version. This distributionrequires that the errors are normally distributed as well as uncorrelated andhomoskedastic.

Hurn (QUT) Applied Financial Econometrics using Stata 20 / 40

Page 21: Singapore Lecture3

Multiple Factors

The test does generalise to the case of multiple factors. Assuming normaliid errors the test statistic is

GRS =T − N − K

N

[1 + fff

′ΩΩΩ−1fff]−1

ααα′ ΣΣΣ−1ααα ∼ FN,T−N−K

in which

N = number of assets

K = number of factors

fff = ET (fff )

ΩΩΩ =1

T

T∑t=1

(fff t − fff )(fff t − f i )′

Hurn (QUT) Applied Financial Econometrics using Stata 21 / 40

Page 22: Singapore Lecture3

GRS in Stata (Wald Version)

. // Gibbons Ross Shanken test (using seemingly unrelated regression estimator)

. qui sureg (z* = rm_rf)

.

. // Wald version

. qui test _cons

. qui sca grsW = r(chi2)

. qui sca pval = r(p)

.

. di as text "Degrees of freedom = " as res r(df)Degrees of freedom = 25

. di as text "Gibbons Ross Shanken test (Wald Version) = " as res grsWGibbons Ross Shanken test (Wald Version) = 96.631577

. di as text "p-value = " as res pvalp-value = 2.302e-10

Hurn (QUT) Applied Financial Econometrics using Stata 22 / 40

Page 23: Singapore Lecture3

GRS in Stata (F Version)

. // F version

. sca tmp0 = (`T´-`N´-1)/`N´

. sca tmp1 = grsW/`T´

. sca grsF = tmp0 * tmp1

. sca pvF = Ftail(`N´,`T´-`N´-1,grsF)

.

. di as text "Gibbons Ross Shanken test (F Version) = " as res grsFGibbons Ross Shanken test (F Version) = 3.7668333

. di as text "p-value = " as res pvFp-value = 1.958e-09

Hurn (QUT) Applied Financial Econometrics using Stata 23 / 40

Page 24: Singapore Lecture3

GRS in Mata (Wald Version)

. // Estimate seemingly unrelated regression model (cheating!)

. qui sureg (z* = rm_rf)

.

. // now call mata (e(b) is 1x50 so must reshape

. // reshape to have 25 rows using rowshape()

. mata:mata (type end to exit)

: aT = st_numscalar("aT")

: sigma = st_matrix("e(Sigma)")

: nf = strtoreal(st_local("N"))

: b = st_matrix("e(b)")

: bmat = (1::nf),rowshape(b,nf)

: st_matrix("suregb", bmat)

: end

Hurn (QUT) Applied Financial Econometrics using Stata 24 / 40

Page 25: Singapore Lecture3

GRS in Mata (Wald Version)

. // need to drop variables so matrix does not take dimensions of data set in memory

. drop *

.

. // stata view of the matrix has 3 columns (company # slope and constant)

. // name them and use the names to break the matrix into variables

. mat colnames suregb = company beta alpha

. qui svmat suregb, names(col)

. matamata (type end to exit)

: st_view(alpha=.,.,"alpha")

: J = aT * alpha´ * invsym(sigma) * alpha

: J96.6328742

: end

Value returned for the GRS test is 96.6328742 which is (almost) identicalto that obtained previously.

Hurn (QUT) Applied Financial Econometrics using Stata 25 / 40

Page 26: Singapore Lecture3

Cross Section Regressions

Hurn (QUT) Applied Financial Econometrics using Stata 26 / 40

Page 27: Singapore Lecture3

Price of Risk

The central question of interest is why average returns vary across assets.The answer is that the expected returns should be high if the asset has ahigh exposure to the factors that carry large risk premia. Recall thefundamental pricing model with a single factor in which the excess returnsare linear in the betas

E(zit) = βiE(ft) .

Since the factor, ft , is also an excess return, the model applies to thefactor as well

E(ft) = 1× λ

where λ is the price of risk (risk premium) associated with the factor sothat

E(zit) = βiλ .

Hurn (QUT) Applied Financial Econometrics using Stata 27 / 40

Page 28: Singapore Lecture3

Two-pass Regression

A natural idea is then to store estimates of βi from the time-seriesregressions and then estimate the factor risk premium λ from across-sectional regression of average returns on the βi

ET (zit) = λβi + εi .

The cross-sectional regression residuals εi are the pricing errors.

Hurn (QUT) Applied Financial Econometrics using Stata 28 / 40

Page 29: Singapore Lecture3

Using collapse

A powerful Stata command which can be used to implement the two-passestimator is

collapse clist [if] [in] [weight] [, options]

collapse converts the dataset in memory into a dataset of means, sums,medians, etc. or any summary statistic contained in clist which must referto numeric variables exclusively.

Hurn (QUT) Applied Financial Econometrics using Stata 29 / 40

Page 30: Singapore Lecture3

First Pass

. // reshape the data to long form

. reshape long z, i(dateid01) j(portfolio)(note: j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25)

Data wide -> long

Number of obs. 1021 -> 25525Number of variables 30 -> 7j variable (25 values) -> portfolioxij variables:

z1 z2 ... z25 -> z

. save "./working/famafrenchlong.dta", replacefile ./working/famafrenchlong.dta saved

.

. // first pass regression

. statsby _b, by(portfolio) saving("./working/firstpass",replace) nodots: reg z rm_rf

command: regress z rm_rfby: portfolio

.

. // keep estimated betas

. use "./working/firstpass.dta", clear(statsby: regress)

. ren _b_rm_rf betas

. drop _b_cons

. save "./working/coefs.dta", replacefile ./working/coefs.dta saved

Hurn (QUT) Applied Financial Econometrics using Stata 30 / 40

Page 31: Singapore Lecture3

Using Collapse

. // now collapse the data to a pure cross section

. use "./working/famafrenchlong.dta", clear

. collapse (mean) z, by(portfolio)

.

. merge 1:1 portfolio using "./working/coefs"

Result # of obs.

not matched 0matched 25 (_merge==3)

. drop _merge

.

. // second pass regression

. reg z betas, noconstant

Source SS df MS Number of obs = 25F( 1, 24) = 31.28

Model 4.82079646 1 4.82079646 Prob > F = 0.0000Residual 3.69828055 24 .154095023 R-squared = 0.5659

Adj R-squared = 0.5478Total 8.51907702 25 .340763081 Root MSE = .39255

z Coef. Std. Err. t P>|t| [95% Conf. Interval]

betas 1.555446 .2780928 5.59 0.000 .9814903 2.129401

Hurn (QUT) Applied Financial Econometrics using Stata 31 / 40

Page 32: Singapore Lecture3

Fama-MacBeth Regressions

The Fama-MacBeth (1973) approach estimates cross sectionregressions for each time period

zit = λtβi + uit

Having obtained these estimates, the Fama-MacBeth procedure thencomputes

λ =T∑i=1

λt ,

as the estimated price of risk.

The standard errors of these parameters are the sample standarddeviations from the cross-sectional regressions, defined as

σ2(λ) =

[1T

∑Tt=1(λt − λ)2

]T

=1

T 2

[T∑t=1

(λt − λ)2

],

Hurn (QUT) Applied Financial Econometrics using Stata 32 / 40

Page 33: Singapore Lecture3

Second Pass Regression

. // this time merge the estimated betas into the long data set

. merge m:1 portfolio using "./working/coefs.dta"

Result # of obs.

not matched 0matched 25,525 (_merge==3)

. drop _merge

. save "./working/famafrenchlong.dta", replacefile ./working/famafrenchlong.dta saved

.

. // run the regressions for each time period

. statsby _b, by(dateid01) saving("./working/famamacbeth",replace) nodots: reg z betas, noconstant

command: regress z betas, noconstantby: dateid01

.

. use "./working/famamacbeth.dta", replace(statsby: regress)

. sum _b_betas

Variable Obs Mean Std. Dev. Min Max

_b_betas 1021 1.555446 11.53178 -36.97755 143.2732

Hurn (QUT) Applied Financial Econometrics using Stata 33 / 40

Page 34: Singapore Lecture3

Interesting New Developments

Hurn (QUT) Applied Financial Econometrics using Stata 34 / 40

Page 35: Singapore Lecture3

Large Numbers of Assets

The general Wald form of the Gibbons, Ross, Shanken test for zero pricingerrors (ααα = 0) in a linear factor model is

J = aT ααα′ ΣΣΣ ααα ∼ χ2

N

in which, ΣΣΣ is the estimated covariance matrix of the errors, aT is apositive scaling constant and N is the number of assets being tested.

This test is applicable, however, only when the number of assets N ismuch smaller than the length of the time series T . When N > T thesample covariance ΣΣΣ becomes degenerate. In practise, one typically picks atesting period of T = 60 monthly data and does not increase the testingperiod any longer, because the factor pricing model is technically aone-period model whose factor loadings can be time-varying. If you arelooking at lots of assets this constitutes a problem.

Hurn (QUT) Applied Financial Econometrics using Stata 35 / 40

Page 36: Singapore Lecture3

Large Numbers of Assets

The general Wald form of the Gibbons, Ross, Shanken test for zero pricingerrors (ααα = 0) in a linear factor model is

J = aT ααα′ ΣΣΣ ααα ∼ χ2

N

in which, ΣΣΣ is the estimated covariance matrix of the errors, aT is apositive scaling constant and N is the number of assets being tested.

This test is applicable, however, only when the number of assets N ismuch smaller than the length of the time series T . When N > T thesample covariance ΣΣΣ becomes degenerate. In practise, one typically picks atesting period of T = 60 monthly data and does not increase the testingperiod any longer, because the factor pricing model is technically aone-period model whose factor loadings can be time-varying. If you arelooking at lots of assets this constitutes a problem.

Hurn (QUT) Applied Financial Econometrics using Stata 35 / 40

Page 37: Singapore Lecture3

Pesaran and Yamagata (2012)

To overcome the difficulty, Pesaran and Yamagata (2012, PY test) suggestignoring the correlations among assets and constructing a test statisticunder working independence by setting V = diag(ΣΣΣ)−1. They derive thefollowing result for the distribution of the standardised quadratic form

Js =aT ααα

′V ααα− N√2N(1 + eT )

∼ N(0, 1)

with

et =1

N

∑i 6=j

ρ2ijI(ρ2ij > cT )

cT =1

TΦ−1(1− c/N)

c ∈ (0, 0.5).

Hurn (QUT) Applied Financial Econometrics using Stata 36 / 40

Page 38: Singapore Lecture3

PY (Basic Version)

. // basic version of Pesaran Yamagata test with sqrt(2*N) as the scaling factor

. mata:mata (type end to exit)

: st_view(s2=.,.,"s2")

: st_view(alpha=.,.,"alpha")

: N = strtoreal(st_local("N"))

: aT = st_numscalar("aT")

: Jnum = aT :* alpha´ * invsym(diag(s2)) * alpha - N

: Jden = sqrt(2 * N)

: J = Jnum :/ Jden

: pval = 1 - normal(abs(J))

: Jnum, Jden, J, pval1 2 3 4

1 -6.500208749 7.071067812 -.9192683372 .1789776174

: end

. // Notes:

. // 1. the test strongly rejects for whole sample

. // 2. this value is calculated using T = N so it works when GRS would fail

. // 3. now we have a problem with low power

Hurn (QUT) Applied Financial Econometrics using Stata 37 / 40

Page 39: Singapore Lecture3

PY (Basic Version)

. // more advanced implementation of the test

. // uses sqrt(2*N*(1+eT)) as the scaling factor in the denominator

. mata:mata (type end to exit)

: //Janum = aT :* alpha´ * invsym(diag(s2)) * alpha - N: Jaden = sqrt(2 * N * (1 + eT))

: Ja = Jnum :/ Jaden

: pval1 = 1 - normal(abs(Ja))

:: Jnum, Jaden, Ja, pval1

1 2 3 4

1 -6.500208749 8.712846629 -.7460487974 .227818969

: end

. // Notes:

. // 1. the numerator of the test is identical to the previous one

. // 2. eT=0.5 so denominator is only slightly affected

. // 3. value of this adjustment is questionable (need some MC evidence)

Hurn (QUT) Applied Financial Econometrics using Stata 38 / 40

Page 40: Singapore Lecture3

Power Enhancements

The PY test, or any other genuine quadratic statistic, is powerful onlywhen a non-negligible fraction of assets are mispriced. Indeed, the factorN above reflects the noise accumulation in estimating N parameters in thevector ααα.

A new working paper by Fan, Liao and Yao (2013) proposes an interestingmethod which uses “power enhancements” (PEM) to improve the powerof the asset pricing test statistic as follows:

1 Compute J1, a test statistic that has the correct asymptotic size (e.g.,GRS, PY) but which may suffer from small power.

2 Compute a PEM component test J0 that has two properties:

1 J0p−→ 0 under H0.

2 J0 does not converge to 0 but even diverges when the true parametersfall into a subset of the alternative hypothesis.

3 Compute the PEM test J = J0 + J1.

Hurn (QUT) Applied Financial Econometrics using Stata 39 / 40

Page 41: Singapore Lecture3

Suggestion: Screened Wald Test

Of course the trick here is to find a statistic J0 which has these niceproperties. Fan, Liao and Yao (2013) propose a “screened” Wald test

J0 =√NaT ααα

′s ΣΣΣs αααs

in which αααs is a subset of the original vector of estimated ααα whose valueexceeds some threshold value δT and ΣΣΣu is the corresponding submatrix ofthe original weight matrix ΣΣΣ.

Screening procedure

δT = log(logT )

√logN

T

Choose αi if|αi |σj

> δT

Hurn (QUT) Applied Financial Econometrics using Stata 40 / 40

Page 42: Singapore Lecture3

Suggestion: Screened Wald Test

Of course the trick here is to find a statistic J0 which has these niceproperties. Fan, Liao and Yao (2013) propose a “screened” Wald test

J0 =√NaT ααα

′s ΣΣΣs αααs

in which αααs is a subset of the original vector of estimated ααα whose valueexceeds some threshold value δT and ΣΣΣu is the corresponding submatrix ofthe original weight matrix ΣΣΣ.

Screening procedure

δT = log(logT )

√logN

T

Choose αi if|αi |σj

> δT

Hurn (QUT) Applied Financial Econometrics using Stata 40 / 40