assign_6.docx

#HW6, R output

> getSymbols("AMZN",from="2004-01-05",to="2012-05-18")

[1] "AMZN"

> amzn=diff(log(as.numeric(AMZN$AMZN.Adjusted)))

> source("Igarch.R")

> dim(AMZN)

[1] 2110 6

> length(amzn)

[1] 2109

> plot(amzn,type='l')

#Problem 1

> m1=Igarch(amzn)

Estimates: 0.999999

Maximized log-likehood: -4504.73

Coefficient(s):

Estimate Std. Error t value Pr(>|t|)

beta 0.999999 NA NA NA

Warning message:

In sqrt(diag(solve(Hessian))) : NaNs produced

> v1=m1$volatility

> v=.999999*v1[2109]^2+(1-.999999)*amzn[2109]^2

> v

[1] 0.0008170621

> vo=sqrt(v)

> vo

[1] 0.0285843

> source("RMeasure.R")

> RMeasure(0,vo)

Risk Measures for selected probabilities:

prob VaR ES

[1,] 0.950 0.04701699 0.05896120

[2,] 0.990 0.06649702 0.07618328

[3,] 0.999 0.08833212 0.09624591

> require(fGarch)

> t.test(amzn)

One Sample t-test

data: amzn

t = 1.0588, df = 2108, p-value = 0.2898

alternative hypothesis: true mean is not equal to 0

95 percent confidence interval:

-0.0005615692 0.0018796360

sample estimates:

mean of x

0.0006590334

> m2=garchFit(~garch(1,1),data=amzn,include.mean=F,trace=F)

> summary(m2)

Title:

GARCH Modelling

Call:

garchFit(formula = ~garch(1, 1), data = amzn, include.mean = F,

trace = F)

Mean and Variance Equation:

data ~ garch(1, 1)

[data = amzn]

Conditional Distribution:

norm

Coefficient(s):

omega alpha1 beta1

8.1295e-05 4.4142e-02 8.5634e-01

Std. Errors:

based on Hessian

Error Analysis:

Estimate Std. Error t value Pr(>|t|)

omega 8.130e-05 2.587e-05 3.142 0.00168 **

alpha1 4.414e-02 1.458e-02 3.028 0.00246 **

beta1 8.563e-01 4.334e-02 19.759 < 2e-16 ***

---

Standardised Residuals Tests:

Statistic p-Value

Jarque-Bera Test R Chi^2 22801.82 0

Shapiro-Wilk Test R W 0.877114 0

Ljung-Box Test R Q(10) 6.174051 0.8004343

Ljung-Box Test R Q(15) 11.60764 0.7084517

Ljung-Box Test R Q(20) 18.48538 0.555467

Ljung-Box Test R^2 Q(10) 1.863959 0.9972804

Ljung-Box Test R^2 Q(15) 2.104383 0.9999585

Ljung-Box Test R^2 Q(20) 2.546816 0.999999

LM Arch Test R TR^2 1.858131 0.9995944

> predict(m2,1)

meanForecast meanError standardDeviation

1 0 0.02708331 0.02708331

> RMeasure(0,.027083)

Risk Measures for selected probabilities:

prob VaR ES

[1,] 0.950 0.04454757 0.05586445

[2,] 0.990 0.06300448 0.07218200

[3,] 0.999 0.08369276 0.09119090

> m3=garchFit(~garch(1,1),data=amzn,include.mean=F,trace=F,cond.dist="std")

> summary(m3)

Title:

GARCH Modelling

Call:

garchFit(formula = ~garch(1, 1), data = amzn, cond.dist = "std",

include.mean = F, trace = F)

Mean and Variance Equation:

data ~ garch(1, 1)

[data = amzn]

Conditional Distribution:

std

Coefficient(s):

omega alpha1 beta1 shape

5.4010e-06 2.0039e-02 9.7171e-01 3.6910e+00

Std. Errors:

based on Hessian

Error Analysis:

Estimate Std. Error t value Pr(>|t|)

omega 5.401e-06 2.351e-06 2.297 0.0216 *

alpha1 2.004e-02 4.550e-03 4.404 1.06e-05 ***

beta1 9.717e-01 6.252e-03 155.428 < 2e-16 ***

shape 3.691e+00 2.805e-01 13.158 < 2e-16 ***

---

Standardised Residuals Tests:

Statistic p-Value

Jarque-Bera Test R Chi^2 44179.67 0

Shapiro-Wilk Test R W 0.8497441 0

Ljung-Box Test R Q(10) 6.935119 0.7315556

Ljung-Box Test R Q(15) 11.39435 0.7241714

Ljung-Box Test R Q(20) 17.60512 0.6134033

Ljung-Box Test R^2 Q(10) 2.171012 0.9948534

Ljung-Box Test R^2 Q(15) 2.921834 0.9996587

Ljung-Box Test R^2 Q(20) 3.835627 0.9999671

LM Arch Test R TR^2 2.402731 0.9984912

> predict(m3,1)

meanForecast meanError standardDeviation

1 0 0.02602888 0.02602888

> RMeasure(0,0.02603,cond.dist="std",df=3.691)

Risk Measures for selected probabilities:

prob VaR ES

[1,] 0.950 0.05685405 0.08725013

[2,] 0.990 0.10220280 0.14580552

[3,] 0.999 0.20346447 0.28199876

>

#Problem 2

> require(evir)

> namzn=-amzn #Long position

> m4=gev(namzn,21)

> m4

$n.all

[1] 2109

$n

[1] 101

$data

[1] 0.07148198 0.03824780 0.04663128 0.05770617 0.02916481 0.03440878

...

[97] 0.08017129 0.03635603 0.02880931 0.02581640 0.02576880

$block

[1] 21

$par.ests

xi sigma mu

0.37144211 0.01645415 0.03269744

$par.ses

xi sigma mu

0.096305320 0.001609465 0.001883217

$varcov

[,1] [,2] [,3]

[1,] 9.274715e-03 4.039022e-06 -5.420633e-05

[2,] 4.039022e-06 2.590378e-06 2.064383e-06

[3,] -5.420633e-05 2.064383e-06 3.546507e-06

$converged

[1] 0

$nllh.final

[1] -233.9451

attr(,"class")

[1] "gev"

>

#

> source("evtVaR.R")

> evtVaR(0.37144211,0.01645415, 0.03269744)

[1] 0.06734551

> 0.06734551*10^(.37144)

[1] 0.1583976

#Problem 3

> m5=gpd(namzn,thres=0.03)

> m5

$n

[1] 2109

$data

[1] 0.03250727 0.07022383 0.05417415 0.04318093 0.07148198 0.03824780

.....

[169] 0.03549203 0.03011677 0.04870838 0.04579498 0.08017129 0.03635603

$threshold

[1] 0.03

$p.less.thresh

[1] 0.9174964

$n.exceed

[1] 174

$method

[1] "ml"

$par.ests

xi beta

0.34313804 0.01443334

$par.ses

xi beta

0.105037392 0.001811058

$varcov

[,1] [,2]

[1,] 0.0110328538 -1.194869e-04

[2,] -0.0001194869 3.279929e-06

$information

[1] "observed"

$converged

[1] 0

$nllh.final

[1] -503.7101

attr(,"class")

[1] "gpd"

> riskmeasures(m5,c(0.99))

p quantile sfall

[1,] 0.99 0.07470822 0.1200365

> m6=gpd(namzn,thres=0.045)

> m6

$n

[1] 2109

$data

[1] 0.07022383 0.05417415 0.07148198 0.04663128 0.05403311 0.05770617

....

[73] 0.04579498 0.08017129

$threshold

[1] 0.045

$p.less.thresh

[1] 0.9649123

$n.exceed

[1] 74

$method

[1] "ml"

$par.ests

xi beta

0.45764955 0.01647918

$par.ses

xi beta

0.20579974 0.00376538

$varcov

[,1] [,2]

[1,] 0.042353533 -5.446820e-04

[2,] -0.000544682 1.417809e-05

$information

[1] "observed"

$converged

[1] 0

$nllh.final

[1] -195.9504

attr(,"class")

[1] "gpd"

> riskmeasures(m6,c(0.99))

p quantile sfall

[1,] 0.99 0.07294936 0.1269185

>

#Problem 4

> getSymbols("KO",from="2004-01-05",to="2012-05-18")

[1] "KO"

> ko=diff(log(as.numeric(KO$KO.Adjusted)))

> mm1=Igarch(ko)

Estimates: 0.9462869

Maximized log-likehood: -6669.622

Coefficient(s):

Estimate Std. Error t value Pr(>|t|)

beta 0.94628692 0.00850725 111.233 < 2.22e-16 ***

---

> v2=mm1$volatility

> length(ko)

[1] 2109

> vo=0.9463*v2[2109]^2+(1-.9463)*ko[2109]^2

> vo=sqrt(vo)

> vo

[1] 0.007926053

> RMeasure(0,vo)

Risk Measures for selected probabilities:

prob VaR ES

[1,] 0.950 0.01303720 0.01634917

[2,] 0.990 0.01843876 0.02112463

[3,] 0.999 0.02449335 0.02668773

> nko=-ko

> cor(namzn,nko)

[1] 0.3433976

>

> nko=-ko

> cor(namzn,nko)

[1] 0.3433976

>

> r1=amzn+ko

> r2=amzn-ko

> n1=Igarch(r1)

Estimates: 0.999999

Maximized log-likehood: -4098.254

Coefficient(s):

Estimate Std. Error t value Pr(>|t|)

beta 0.999999 NA NA NA

Warning message:

In sqrt(diag(solve(Hessian))) : NaNs produced

> vn1=n1$volatility

> n2=Igarch(r2)

Estimates: 0.999999

Maximized log-likehood: -4629.792

Coefficient(s):

Estimate Std. Error t value Pr(>|t|)

beta 0.999999 NA NA NA

Warning message:

In sqrt(diag(solve(Hessian))) : NaNs produced

> vn2=n2$volatility

> m1=Igarch(amzn)

Estimates: 0.999999

Maximized log-likehood: -4504.73

Coefficient(s):

Estimate Std. Error t value Pr(>|t|)

beta 0.999999 NA NA NA

Warning message:

In sqrt(diag(solve(Hessian))) : NaNs produced

> v1=m1$volatility

> cov1=(vn1[2109]^2-vn2[2109]^2)/4

> cov1

[1] 0.0001189115

> corr1=cov1/(v1[2109]*v2[2109])

> corr1

[1] 0.5624339

>

#Problem 5

> cor(amzn,nko)

[1] -0.3433976

>

> t.test(ko)

One Sample t-test

data: ko

t = 1.1073, df = 2108, p-value = 0.2683

alternative hypothesis: true mean is not equal to 0

95 percent confidence interval:

-0.0002249640 0.0008085214

sample estimates:

mean of x

0.0002917787

> k1=garchFit(~garch(1,1),data=nko,trace=F,include.mean=F,cond.dist="std")

> summary(k1)

Title:

GARCH Modelling

Call:

garchFit(formula = ~garch(1, 1), data = nko, cond.dist = "std",

include.mean = F, trace = F)

Mean and Variance Equation:

data ~ garch(1, 1)

[data = nko]

Conditional Distribution:

std

Coefficient(s):

omega alpha1 beta1 shape

1.7747e-06 6.8873e-02 9.1784e-01 5.2960e+00

Std. Errors:

based on Hessian

Error Analysis:

Estimate Std. Error t value Pr(>|t|)

omega 1.775e-06 6.549e-07 2.710 0.00673 **

alpha1 6.887e-02 1.454e-02 4.738 2.16e-06 ***

beta1 9.178e-01 1.680e-02 54.640 < 2e-16 ***

shape 5.296e+00 5.937e-01 8.920 < 2e-16 ***

---

Standardised Residuals Tests:

Statistic p-Value

Jarque-Bera Test R Chi^2 2505.346 0

Shapiro-Wilk Test R W 0.9658619 0

Ljung-Box Test R Q(10) 9.347308 0.4994903

Ljung-Box Test R Q(15) 17.2665 0.3031844

Ljung-Box Test R Q(20) 19.89797 0.4643285

Ljung-Box Test R^2 Q(10) 7.080028 0.7178688

Ljung-Box Test R^2 Q(15) 7.736915 0.9338964

Ljung-Box Test R^2 Q(20) 10.5478 0.9571176

LM Arch Test R TR^2 7.44726 0.8266984

> predict(k1,1)

meanForecast meanError standardDeviation

1 0 0.008945565 0.008945565

> RMeasure(0,.008945565,cond.dist="std",df=5.296)

Risk Measures for selected probabilities:

prob VaR ES

[1,] 0.950 0.01780556 0.02529450

[2,] 0.990 0.02941036 0.03850407

[3,] 0.999 0.05054351 0.06368452

> k2=garchFit(~garch(1,1),data=amzn,cond.dist="std",include.mean=F,trace=F)

> summary(k2)

Title:

GARCH Modelling

Call:

garchFit(formula = ~garch(1, 1), data = amzn, cond.dist = "std",

include.mean = F, trace = F)

Mean and Variance Equation:

data ~ garch(1, 1)

[data = amzn]

Conditional Distribution:

std

Error Analysis:

Estimate Std. Error t value Pr(>|t|)

omega 5.401e-06 2.351e-06 2.297 0.0216 *

alpha1 2.004e-02 4.550e-03 4.404 1.06e-05 ***

beta1 9.717e-01 6.252e-03 155.428 < 2e-16 ***

shape 3.691e+00 2.805e-01 13.158 < 2e-16 ***

---

Standardised Residuals Tests:

Statistic p-Value

Jarque-Bera Test R Chi^2 44179.67 0

Shapiro-Wilk Test R W 0.8497441 0

Ljung-Box Test R Q(10) 6.935119 0.7315556

Ljung-Box Test R Q(15) 11.39435 0.7241714

Ljung-Box Test R Q(20) 17.60512 0.6134033

Ljung-Box Test R^2 Q(10) 2.171012 0.9948534

Ljung-Box Test R^2 Q(15) 2.921834 0.9996587

Ljung-Box Test R^2 Q(20) 3.835627 0.9999671

LM Arch Test R TR^2 2.402731 0.9984912

> predict(k2,1)

meanForecast meanError standardDeviation

1 0 0.02602888 0.02602888

> RMeasure(0,0.02602888,cond.dist="std",df=3.691)

Risk Measures for selected probabilities:

prob VaR ES

[1,] 0.950 0.0568516 0.08724638

[2,] 0.990 0.1021984 0.14579925

[3,] 0.999 0.2034557 0.28198662

>