quantitative finance i - avcr.czstaff.utia.cas.cz/barunik/files/qfi/qf_i_lecture11.pdf ·...

19
Quantitative Finance I High-frequency financial models II - Realized Measures (Lecture 11) Winter Semester 2012/2013 by Jozef Baruník * If viewed in .pdf format - for full functionality use Mathematica 7 notebook (.nb) version of this .pdf Introduction Today, we will go through an empirical example of modeling Crude Oil, Gold and S&P 500 futures from 2.1.2008 - 29.11.2011 We will estimate their volatility using Realized Volatilities We will estimate their correlations using Realized Covariance and finally try to forecast teh dependence Daily returns dateplot@data_, label_D := DateListPlot@data, 882008, 01, 02<, 82011, 11, 29<<, Frame Ø True, Joined Ø True, PlotRange Ø All, PlotStyle Ø Black, ImageSize Ø 400, FrameLabel Ø 8"", "", Style@label, 14D<D dateplot1@data_, label_D := DateListPlot@data, 882008, 01, 02<, 82011, 11, 29<<, Frame Ø True, Joined Ø True, PlotRange Ø All, PlotStyle Ø 8Black, Red<, ImageSize Ø 800, AspectRatio Ø 0.4, FrameLabel Ø 8"", "", Style@label, 14D<D UScatter@data1_, data2_, label_D := ListPlot@Transpose@8CDF@EmpiricalDistribution@data1D, data1D, CDF@EmpiricalDistribution@data2D, data2D<D, Frame Ø True, AspectRatio Ø 1, ImageSize Ø 300, PlotStyle Ø 8Black<, FrameLabel Ø 8"", "", Style@label, 14D<D plot@data_D := ListLinePlot@8data, m@"PredictedResponse"D<, PlotRange Ø All, AspectRatio Ø 0.4, ImageSize Ø 800, Frame Ø True, PlotStyle Ø 8Black, Red<D plotres@data_D := ListLinePlot@data, PlotRange Ø All, AspectRatio Ø 0.4, ImageSize Ø 800, Frame Ø True, PlotStyle Ø BlackD Directory@D êUsersêbarunik data = Import@"commodity.csv"D; split = Split@data, Ò1P1T === Ò2P1T &D; gc = split@@All, All, 2DD; cl = split@@All, All, 3DD; sp = split@@All, All, 4DD; dailyretsgc = Total@Transpose@gcDD; dailyretscl = Total@Transpose@clDD; dailyretssp = Total@Transpose@spDD;

Upload: truongtram

Post on 13-Sep-2018

225 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

Quantitative Finance IHigh-frequency financial models II - Realized Measures

(Lecture 11)

Winter Semester 2012/2013 by Jozef Baruník* If viewed in .pdf format - for full functionality use Mathematica 7 notebook (.nb) version of this .pdf

IntroductionToday, we will go through an empirical example of modeling Crude Oil, Gold and S&P 500 futures from2.1.2008 - 29.11.2011

We will estimate their volatility using Realized VolatilitiesWe will estimate their correlations using Realized Covariance

and finally try to forecast teh dependence

Daily returnsdateplot@data_, label_D := DateListPlot@data, 882008, 01, 02<, 82011, 11, 29<<,

Frame Ø True, Joined Ø True, PlotRange Ø All, PlotStyle Ø Black,ImageSize Ø 400, FrameLabel Ø 8"", "", Style@label, 14D<D

dateplot1@data_, label_D := DateListPlot@data, 882008, 01, 02<, 82011, 11, 29<<,Frame Ø True, Joined Ø True, PlotRange Ø All, PlotStyle Ø 8Black, Red<,ImageSize Ø 800, AspectRatio Ø 0.4, FrameLabel Ø 8"", "", Style@label, 14D<D

UScatter@data1_, data2_, label_D :=ListPlot@Transpose@8CDF@EmpiricalDistribution@data1D, data1D,

CDF@EmpiricalDistribution@data2D, data2D<D, Frame Ø True, AspectRatio Ø 1,ImageSize Ø 300, PlotStyle Ø 8Black<, FrameLabel Ø 8"", "", Style@label, 14D<D

plot@data_D := ListLinePlot@8data, m@"PredictedResponse"D<, PlotRange Ø All,AspectRatio Ø 0.4, ImageSize Ø 800, Frame Ø True, PlotStyle Ø 8Black, Red<D

plotres@data_D := ListLinePlot@data, PlotRange Ø All,AspectRatio Ø 0.4, ImageSize Ø 800, Frame Ø True, PlotStyle Ø BlackD

Directory@D

êUsersêbarunik

data = Import@"commodity.csv"D;

split = Split@data, Ò1P1T === Ò2P1T &D;

gc = split@@All, All, 2DD;cl = split@@All, All, 3DD;sp = split@@All, All, 4DD;

dailyretsgc = Total@Transpose@gcDD;dailyretscl = Total@Transpose@clDD;dailyretssp = Total@Transpose@spDD;

Page 2: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

dateplot@dailyretsgc, "Gold HGCL"Ddateplot@dailyretscl, "Crude Oil HCLL"Ddateplot@dailyretssp, "S&P 500 HSPL"D

2008 2009 2010 2011

-0.05

0.00

0.05

0.10

Gold HGCL

2008 2009 2010 2011

-0.10

-0.05

0.00

0.05

0.10

Crude Oil HCLL

2008 2009 2010 2011

-0.05

0.00

0.05

S&P 500 HSPL

2 QF_I_Lecture11.nb

Page 3: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

Export@"daily_gold.csv", dailyretsgcDExport@"daily_crude.csv", dailyretsclDExport@"daily_sp.csv", dailyretsspD

daily_gold.csv

daily_crude.csv

daily_sp.csv

Realized Volatility (Realized Variance) ConstructionRVSPgc = Table@Total@gcPiT^2D, 8i, 1, Length@gcD<D;dateplot@Sqrt@RVSPgcD, "Volatility of Gold HGCL"DRVSPcl = Table@Total@clPiT^2D, 8i, 1, Length@gcD<D;dateplot@Sqrt@RVSPclD, "Volatility of Crude Oil HCLL"DRVSPsp = Table@Total@spPiT^2D, 8i, 1, Length@gcD<D;dateplot@Sqrt@RVSPspD, "Volatility of S&P 500 HSPL"D

2008 2009 2010 2011

0.01

0.02

0.03

0.04

Volatility of Gold HGCL

2008 2009 2010 2011

0.01

0.02

0.03

0.04

0.05

0.06

Volatility of Crude Oil HCLL

QF_I_Lecture11.nb 3

Page 4: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

2008 2009 2010 20110.00

0.01

0.02

0.03

0.04

0.05

0.06

0.07

Volatility of S&P 500 HSPL

Export@"RV_gold.csv", RVSPgcDExport@"RV_crude.csv", RVSPclDExport@"RV_sp.csv", RVSPspD

RV_gold.csv

RV_crude.csv

RV_sp.csv

4 QF_I_Lecture11.nb

Page 5: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

Standardized Daily Returns DistributionStandardized Plotsdateplot@dailyretsgc ê Sqrt@RVSPgcD, "Gold HGCL"Ddateplot@dailyretscl ê Sqrt@RVSPclD, "Crude Oil HCLL"Ddateplot@dailyretssp ê Sqrt@RVSPspD, "S&P 500 HSPL"D

2008 2009 2010 2011

-2

-1

0

1

2

3

Gold HGCL

2008 2009 2010 2011

-2

-1

0

1

2

Crude Oil HCLL

QF_I_Lecture11.nb 5

Page 6: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

2008 2009 2010 2011

-2

-1

0

1

2

3

S&P 500 HSPL

6 QF_I_Lecture11.nb

Page 7: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

DistributionsShow@8Histogram@dailyretsgc ê Sqrt@RVSPgcD, 33, "PDF", ChartStyle Ø Gray,

PlotLabel Ø "Standardized Daily Reurns of Gold", Frame Ø TrueD,Plot@PDF@NormalDistribution@0, 1D, xD, 8x, -3, 3<, PlotStyle Ø RedD<D

Show@8Histogram@dailyretscl ê Sqrt@RVSPclD, 33, "PDF", ChartStyle Ø Gray,PlotLabel Ø "Standardized Daily Reurns of Crude Oil", Frame Ø TrueD,

Plot@PDF@NormalDistribution@0, 1D, xD, 8x, -3, 3<, PlotStyle Ø RedD<DShow@8Histogram@dailyretssp ê Sqrt@RVSPspD, 33, "PDF", ChartStyle Ø Gray,

PlotLabel Ø "Standardized Daily Reurns of S&P 500", Frame Ø TrueD,Plot@PDF@NormalDistribution@0, 1D, xD, 8x, -3, 3<, PlotStyle Ø RedD<D

QF_I_Lecture11.nb 7

Page 8: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

Scattered Plots to N(0,1) DistributionsUScatter@dailyretsgc ê Sqrt@RVSPgcD,RandomReal@NormalDistribution@0, 1D, Length@gcDD,"Standardized Daily Reurns of Gold"D

UScatter@dailyretsgc ê Sqrt@RVSPclD,RandomReal@NormalDistribution@0, 1D, Length@gcDD,"Standardized Daily Reurns of Crude Oil"D

UScatter@dailyretsgc ê Sqrt@RVSPspD,RandomReal@NormalDistribution@0, 1D, Length@gcDD,"Standardized Daily Reurns of S&P 500"D

0.0 0.2 0.4 0.6 0.8 1.00.0

0.2

0.4

0.6

0.8

1.0

Standardized Daily Reurns of Gold

0.0 0.2 0.4 0.6 0.8 1.00.0

0.2

0.4

0.6

0.8

1.0

Standardized Daily Reurns of Crude Oil

8 QF_I_Lecture11.nb

Page 9: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

0.0 0.2 0.4 0.6 0.8 1.00.0

0.2

0.4

0.6

0.8

1.0

Standardized Daily Reurns of S&P 500

Realized Covariance & CorrelationLet’s consider generalization realized covariance estimation of the two assets a andb:

RCovt =⁄j=1m ra,t-1+ j n rb,t-1+ j n

for t=1,...,Tdays.

Again, with n ö 0, (m ö ¶), this estimator will converge in probability to the covariance matrix of twoassets a and b: Ÿ0

1⁄a,b„s

Realized Correlation can then be estimated as:

RCt =RCovt,a,b

RVt,a RVt,b

corr1 = Table@Total@gc@@iDD cl@@iDDD êHSqrt@Total@gc@@iDD^2DD Sqrt@Total@cl@@iDD^2DDL, 8i, 1, Length@gcD<D;

corr2 = Table@Total@gc@@iDD sp@@iDDD êHSqrt@Total@gc@@iDD^2DD Sqrt@Total@sp@@iDD^2DDL, 8i, 1, Length@gcD<D; corr3 =

Table@Total@sp@@iDD cl@@iDDD ê HSqrt@Total@sp@@iDD^2DD Sqrt@Total@cl@@iDD^2DDL,8i, 1, Length@clD<D;

QF_I_Lecture11.nb 9

Page 10: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

dateplot@corr1, "Gold HGCL - Crude Oil HCLL"Ddateplot@corr2, "Crude Oil HCLL - S&P 500 HSPL"Ddateplot@corr3, "S&P 500 HSPL - Gold HGCL"D

2008 2009 2010 2011-0.6

-0.4

-0.2

0.0

0.2

0.4

0.6

0.8

Gold HGCL - Crude Oil HCLL

2008 2009 2010 2011

-0.6

-0.4

-0.2

0.0

0.2

0.4

0.6

0.8

Crude Oil HCLL - S&P 500 HSPL

2008 2009 2010 2011-0.6

-0.4

-0.2

0.0

0.2

0.4

0.6

0.8

S&P 500 HSPL - Gold HGCL

10 QF_I_Lecture11.nb

Page 11: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

Export@"corr1.csv", corr1DExport@"corr2.csv", corr2DExport@"corr3.csv", corr3D

corr1.csv

corr2.csv

corr3.csv

Forecasting of Realized Volatility (HAR model)Basic model for forecasting can be used:

RVt = a0 + b1 RVt-1 + b2 RVt-1H5L + b3 RVt-1

H22L + ut,

where RVt-1HhL is h-period realized variance, i.e. RVt-1

H5L corresponding to 1 week and RVt-1H22L corresponding to

1 monthRV = Sqrt@RVSPgcD;

avg5 = Table@Mean@RVP1 + i ;; 5 + iTD, 8i, 0, Length@RVD - 5<D;avg22 = Table@Mean@RVP1 + i ;; 22 + iTD, 8i, 0, Length@RVD - 22<D;m = LinearModelFit@

8Transpose@8RVP22 ;; Length@RVD - 1T, avg5P23 - 5 ;; Length@avg5D - 1T,avg5P1 ;; Length@avg22D - 1T<D, RVP23 ;; Length@RVDT<D;

m@8"ParameterTable", "RSquared"<D

:

Estimate Standard Error t-Statistic P-ValueÒ1 0.262139 0.0427458 6.13251 1.36524µ10-9

Ò2 0.612753 0.0572591 10.7014 4.71696µ10-25

Ò3 0.107086 0.0363347 2.94721 0.00330087

, 0.893843>

QF_I_Lecture11.nb 11

Page 12: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

plot@RVP23 ;; Length@RVDTDplotres@m@8"FitResiduals"<DD

0 200 400 600

0.00

0.01

0.02

0.03

0.04

0 200 400 600

-0.01

0.00

0.01

0.02

0.03

Comparison of HAR and GARCH(1,1) fitsgarch = Import@"garch.txt", "Table"D;garch = Rest@garchD;

12 QF_I_Lecture11.nb

Page 13: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

plot@RVP23 ;; Length@RVDTDdateplot1@8Sqrt@RVSPgcD, Rest@garchPAll, 2TD<, "GARCHH1,1L"D

0 200 400 600

0.00

0.01

0.02

0.03

0.04

2008 2009 2010 2011

0.01

0.02

0.03

0.04

GARCHH1,1L

RV = RVSPcl;

avg5 = Table@Mean@RVP1 + i ;; 5 + iTD, 8i, 0, Length@RVD - 5<D;avg22 = Table@Mean@RVP1 + i ;; 22 + iTD, 8i, 0, Length@RVD - 22<D;m = LinearModelFit@

8Transpose@8RVP22 ;; Length@RVD - 1T, avg5P23 - 5 ;; Length@avg5D - 1T,avg5P1 ;; Length@avg22D - 1T<D, RVP23 ;; Length@RVDT<D;

m@8"ParameterTable", "RSquared"<D

:

Estimate Standard Error t-Statistic P-ValueÒ1 0.0284883 0.0434849 0.655131 0.512574Ò2 0.788704 0.0618194 12.7582 4.92672µ10-34

Ò3 0.157653 0.04279 3.68435 0.000244909

, 0.809911>

QF_I_Lecture11.nb 13

Page 14: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

plot@RVP23 ;; Length@RVDTDplotres@m@8"FitResiduals"<DD

0 200 400 600

0.000

0.001

0.002

0.003

0.004

0 200 400 600

-0.001

0.000

0.001

0.002

0.003

RV = RVSPsp;

avg5 = Table@Mean@RVP1 + i ;; 5 + iTD, 8i, 0, Length@RVD - 5<D;avg22 = Table@Mean@RVP1 + i ;; 22 + iTD, 8i, 0, Length@RVD - 22<D;m = LinearModelFit@

8Transpose@8RVP22 ;; Length@RVD - 1T, avg5P23 - 5 ;; Length@avg5D - 1T,avg5P1 ;; Length@avg22D - 1T<D, RVP23 ;; Length@RVDT<D;

m@8"ParameterTable", "RSquared"<D

:

Estimate Standard Error t-Statistic P-ValueÒ1 0.227964 0.0430766 5.29205 1.56763µ10-7

Ò2 0.637661 0.0536875 11.8773 4.6956µ10-30

Ò3 0.0550125 0.0314145 1.75118 0.0803017

, 0.632036>

14 QF_I_Lecture11.nb

Page 15: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

plot@RVP23 ;; Length@RVDTDplotres@m@8"FitResiduals"<DD

0 200 400 600

0.000

0.001

0.002

0.003

0.004

0.005

0.006

0 200 400 600

-0.002

-0.001

0.000

0.001

0.002

0.003

0.004

Forecasting of Realized Volatility (HAR model)Basic model for forecasting can be used:

RCt = a0 + b1 RCt-1 + b2 RCt-1H5L + b3 RCt-1

H22L + ut,

where RCt-1HhL is h-period realized variance, i.e. RCt-1

H5L corresponding to 1 week and RCt-1H22L corresponding to

1 month

QF_I_Lecture11.nb 15

Page 16: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

RV = corr1;

avg5 = Table@Mean@RVP1 + i ;; 5 + iTD, 8i, 0, Length@RVD - 5<D;avg22 = Table@Mean@RVP1 + i ;; 22 + iTD, 8i, 0, Length@RVD - 22<D;m = LinearModelFit@

8Transpose@8RVP22 ;; Length@RVD - 1T, avg5P23 - 5 ;; Length@avg5D - 1T,avg5P1 ;; Length@avg22D - 1T<D, RVP23 ;; Length@RVDT<D;

m@8"ParameterTable", "RSquared"<D

:

Estimate Standard Error t-Statistic P-ValueÒ1 0.261203 0.0441455 5.91686 4.88421µ10-9

Ò2 0.66981 0.0522036 12.8307 2.27321µ10-34

Ò3 0.0493733 0.0262225 1.88286 0.0600859

, 0.881742>

plot@RVP23 ;; Length@RVDTDplotres@m@8"FitResiduals"<DD

0 200 400 600

-0.6

-0.4

-0.2

0.0

0.2

0.4

0.6

0.8

0 200 400 600

-0.4

-0.2

0.0

0.2

0.4

0.6

16 QF_I_Lecture11.nb

Page 17: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

RV = corr2;

avg5 = Table@Mean@RVP1 + i ;; 5 + iTD, 8i, 0, Length@RVD - 5<D;avg22 = Table@Mean@RVP1 + i ;; 22 + iTD, 8i, 0, Length@RVD - 22<D;m = LinearModelFit@

8Transpose@8RVP22 ;; Length@RVD - 1T, avg5P23 - 5 ;; Length@avg5D - 1T,avg5P1 ;; Length@avg22D - 1T<D, RVP23 ;; Length@RVDT<D;

m@8"ParameterTable", "RSquared"<D

:

Estimate Standard Error t-Statistic P-ValueÒ1 0.269437 0.0440132 6.12174 1.45626µ10-9

Ò2 0.674937 0.0522142 12.9263 8.16686µ10-35

Ò3 0.00986126 0.0259359 0.380217 0.703886

, 0.799034>

plot@RVP23 ;; Length@RVDTDplotres@m@8"FitResiduals"<DD

0 200 400 600

-0.6

-0.4

-0.2

0.0

0.2

0.4

0.6

0.8

0 200 400 600

-0.5

0.0

0.5

QF_I_Lecture11.nb 17

Page 18: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

RV = corr3;

avg5 = Table@Mean@RVP1 + i ;; 5 + iTD, 8i, 0, Length@RVD - 5<D;avg22 = Table@Mean@RVP1 + i ;; 22 + iTD, 8i, 0, Length@RVD - 22<D;m = LinearModelFit@

8Transpose@8RVP22 ;; Length@RVD - 1T, avg5P23 - 5 ;; Length@avg5D - 1T,avg5P1 ;; Length@avg22D - 1T<D, RVP23 ;; Length@RVDT<D;

m@8"ParameterTable", "RSquared"<D

:

Estimate Standard Error t-Statistic P-ValueÒ1 0.273126 0.0434359 6.28804 5.31309µ10-10

Ò2 0.681634 0.0514108 13.2586 2.24059µ10-36

Ò3 0.0325847 0.025316 1.28712 0.198429

, 0.923943>

plot@RVP23 ;; Length@RVDTDplotres@m@8"FitResiduals"<DD

0 200 400 600

-0.6

-0.4

-0.2

0.0

0.2

0.4

0.6

0.8

0 200 400 600-0.6

-0.4

-0.2

0.0

0.2

0.4

0.6

Excercise

18 QF_I_Lecture11.nb

Page 19: Quantitative Finance I - avcr.czstaff.utia.cas.cz/barunik/files/QFI/QF_I_Lecture11.pdf · Quantitative Finance I High-frequency financial models II - Realized Measures ... Crude Oil

ExcerciseWe will estimate HAR model for volatility and correlation

QF_I_Lecture11.nb 19