Financial Econometrics

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Applied Financial Econometrics

Examples from Topic 1


Hurn, Martin, Phillips & Yu (2020) Chapters 1 & 2

Semester 2, 2023/24

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 1 / 21


Returns

Returns

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 2 / 21


Returns

Recap

Aggregation Simple Return Log Return


1-Period Return Rt = Pt /Pt−1 − 1 rt = log Pt − log Pt−1

−1
kY −1
kX
k-Period Return Rt (k) = (1 + Rt−i ) − 1 rt (k) = rt−i
i=0 i=0
Annualised Return Annu. Rt (12) = (1 + Rt )12 − 1 Annu. rt (12) = rt × 12
N
X XN 
Portfolio Return RPt = wi Rit rPt = log wi erit
i=1 i=1

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 3 / 21


Returns

Load data

. use "$data/capm.dta", clear


. // we use the capm data: monthly prices on US stocks, April 1990 to July 2004

. tsset datevec, monthly

Time variable: datevec, 1990m4 to 2004m7


Delta: 1 month

. list datevec msoft wmart in 1/5 // we focus on microsoft and walmart

+-------------------------+
| datevec msoft wmart |
|-------------------------|
1. | 1990m4 .8 5.26 |
2. | 1990m5 1 5.98 |
3. | 1990m6 1.04 6.68 |
4. | 1990m7 .91 6.71 |
5. | 1990m8 .84 6.13 |
+-------------------------+

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 4 / 21


Returns

Plot the price charts I

// Microsoft
twoway (tsline msoft), name(msoft, replace) title("Microsoft") xtitle("") ///
ytitle("Microsoft Prices") tlabel(#10,format(%tmCCYY)) ///
ylabel(, format(%9.0gc)) ylabel(,angle(0)) nodraw

// Walmart
twoway (tsline wmart), name(wmart, replace) title("Walmart") xtitle("") ///
ytitle("Walmart Prices") tlabel(#10,format(%tmCCYY)) ///
ylabel(, format(%9.0gc)) ylabel(,angle(0)) nodraw

// Combine graphs
graph combine msoft wmart, col(1) imargin(tiny)
graph export "demo_stockindices.png", replace

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 5 / 21


Returns

Plot the price charts II

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 6 / 21


Returns

Calculate simple and log returns

. local capmlst msoft wmart // must be run together with loop

. foreach v in ‘capmlst’ {
2. gen sret_‘v’ = ‘v’ / L1.‘v’ - 1.0 // Simple returns
3. gen lret_‘v’ = log(‘v’) - log(L1.‘v’) // Log returns
4. }
(1 missing value generated)
(1 missing value generated)
(1 missing value generated)
(1 missing value generated)

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 7 / 21


Returns

Plot the return charts I

// Microsoft
twoway (tsline sret_msoft), name(sret_msoft, replace) ///
title("Simple Returns Microsoft") xtitle("") ytitle("") ///
tlabel(#10,format(%tmCCYY)) ylabel(,angle(0)) nodraw

twoway (tsline lret_msoft), name(lret_msoft, replace) ///


title("Log Returns Microsoft") xtitle("") ytitle("") ///
tlabel(#10,format(%tmCCYY)) ylabel(,angle(0)) nodraw

// Walmart
twoway (tsline sret_wmart), name(sret_wmart, replace) ///
title("Simple Returns Walmart") xtitle("") ytitle("") ///
tlabel(#10,format(%tmCCYY)) ylabel(,angle(0)) nodraw

twoway (tsline lret_wmart), name(lret_wmart, replace) ///


title("Log Returns Walmart") xtitle("") ytitle("") ///
tlabel(#10,format(%tmCCYY)) ylabel(,angle(0)) nodraw

// Combine graphs
graph combine sret_msoft lret_msoft sret_wmart lret_wmart, ///
cols(2) xcommon ycommon
graph export "demo_gr_ret.png", replace

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 8 / 21


Returns

Plot the return charts II

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 9 / 21


Returns

Calculate portfolio returns I

. keep if tin(2004m1, 2004m7) // keep seven months


(0 observations deleted)

. scalar wi = 1.0/2.0 // portfolio weight - equal weights

. /* weighted one-period returns */


. local capmlst msoft wmart
. foreach v in ‘capmlst’ {
2. gen srets_‘v’ = wi * sret_‘v’
3. gen logrets_‘v’ = wi * exp(lret_‘v’)
4. }
(1 missing value generated)
(1 missing value generated)
(1 missing value generated)
(1 missing value generated)

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 10 / 21


Returns

Calculate portfolio returns II

. /* now aggregate to get one-period portfolio returns in each time period */

. egen prt_simple = rowtotal(srets*)

. egen prt_log = rowtotal(logrets*)

. replace prt_log = log(prt_log)


(7 real changes made, 1 to missing)

. list datevec srets* prt_simple in 1/5

+---------------------------------------------+
| datevec srets_m~t srets_w~t prt_sim~e |
|---------------------------------------------|
1. | 2004m1 .0051301 .007593 .0127231 |
2. | 2004m2 -.0203119 .0530105 .0326985 |
3. | 2004m3 -.0300567 .0021978 -.0278589 |
4. | 2004m4 .023934 -.0225551 .0013789 |
5. | 2004m5 .0019194 -.0099595 -.0080401 |
+---------------------------------------------+

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 11 / 21


Returns

Calculate portfolio returns III

. /* now compute the portfolio return over the 7-month period */


. // log return to portfolio over k periods - sum of one period returns
. qui sum prt_log

. disp as text "Log return to the portfolio = " as res r(sum)


Log return to the portfolio = .02888031

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 12 / 21


Returns

Calculate portfolio returns IV

. // simple return to portfolio over k periods - product of one period returns


. gen tmp = 1 + prt_simple[1]

. replace tmp = (1+prt_simple[_n]) * tmp[_n-1] in 2/l


(6 real changes made)

. disp as text "Simple return to the portfolio = " as res tmp[_N]-1


Simple return to the portfolio = .02930129

. list datevec tmp in l

+--------------------+
| datevec tmp |
|--------------------|
7. | 2004m7 1.029301 |
+--------------------+

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 13 / 21


Describing data

Describing data

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 14 / 21


Describing data

Load data

. use "$data/hour.dta", clear


. // we use the hour data: hourly data on GBP/USD, 0.00am 01/01/1986 to 11.00am 15/07/1986

. gen t = _n // set time


. tsset t

Time variable: t, 1 to 3190


Delta: 1 unit

. list t bp in 1/5

+------------+
| t bp |
|------------|
1. | 1 1.4515 |
2. | 2 1.452 |
3. | 3 1.4537 |
4. | 4 1.454 |
5. | 5 1.456 |
+------------+

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 15 / 21


Describing data

Plot the exchange rate

twoway tsline bp, name(gbp, replace) ytitle(" ") title("£/$ exchange rate") ///
tlabel(#10,) xtitle("") ylabel(,angle(0))

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 16 / 21


Describing data

Compute log returns of the exchange rate


. gen lrate = log(bp)
. gen rrate = lrate -L1.lrate
(1 missing value generated)
. // then use very similar command to plot the log returns

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 17 / 21


Describing data

Plot histogram of log returns

histogram rrate, name(histfxrets, replace) normal ///


xtitle("Exchange rate returns") ylabel(,angle(0)) fcolor(none)

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 18 / 21


Describing data

Compute autocorrelations I

. /* first we transform the log returns */


. gen ret2 = rrate^2
(1 missing value generated)

. gen arets = abs(rrate)


(1 missing value generated)

. gen sqarets = sqrt(arets)


(1 missing value generated)

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 19 / 21


Describing data

Plot autocorrelations I

/* then we plot the transformed returns */


// log returns
ac rrate, lags(10) ytitle("Returns") name(grets, replace) ///
ylabel(,angle(0)) nodraw

// squared log returns


ac ret2, lags(10) ytitle("Returns Squared") name(gret2, replace) ///
ylabel(,angle(0)) nodraw

// absolute value of log returns


ac arets, lag(10) ytitle("Absoulte Returns") name(garets, replace) ///
ylabel(,angle(0)) nodraw

// square root of the absolute value of log returns


ac sqarets, lag(10) ytitle("Square root of absoulte Returns") ///
ylabel(,angle(0)) name(gsqarets, replace) nodraw

graph combine grets gret2 garets gsqarets, cols(2)

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 20 / 21


Describing data

Plot autocorrelations II

Applied Financial Econometrics Topic 1 examples Semester 2, 2023/24 21 / 21

You might also like