Showing posts with label newsimpact. Show all posts
Showing posts with label newsimpact. Show all posts

## How to find kurtosis, newsimpact,cov,Bayes Shibata and Hannan-Quinn

> getSymbols("SNP", from="2004-01-01", to=Sys.Date())
[1] "SNP"
> chartSeries(Cl(SNP))
> ret <- dailyReturn(Cl(SNP), type='log')
> par(mfrow=c(2,2))
> acf(ret, main="Return ACF");
> pacf(ret, main="Return PACF");
> acf(ret^2, main="Squared return ACF");
> pacf(ret^2, main="Squared return PACF")
> par(mfrow=c(1,1))
> m=mean(ret);s=sd(ret);
> par(mfrow=c(1,2))
> hist(ret, nclass=40, freq=FALSE, main='Return histogram');curve(dnorm(x,mean=m,sd=s), from = -0.3, to = 0.2, add=TRUE, col="red")
> plot(density(ret), main='Return empirical distribution');curve(dnorm(x,mean=m,sd=s), from = -0.3, to = 0.2, add=TRUE, col="red")
> par(mfrow=c(1,1))
> library("moments", lib.loc="~/R/win-library/3.6")

Attaching package: ‘moments’

The following objects are masked from ‘package:timeDate’:

## kurtosis, skewness

> kurtosis(ret)
daily.returns
9.311107
> kurtosis(ret.aapl)
daily.returns
9.517664
> kurtosis(ret.msft)
daily.returns
12.79562
> plot(density(ret), main='Return EDF - upper tail', xlim = c(0.1, 0.2),
+      ylim=c(0,2));
> curve(dnorm(x, mean=m,sd=s), from = -0.3, to = 0.2, add=TRUE, col="red")
> qqnorm(ret);qqline(ret);
> library("rugarch", lib.loc="~/R/win-library/3.6")

Attaching package: ‘rugarch’

The following object is masked from ‘package:stats’:

sigma

> getSymbols("AAPL", from="2006-01-01", to=Sys.Date())
[1] "AAPL"
> ret.aapl <- dailyReturn(Cl(AAPL), type='log')
> chartSeries(ret.aapl)
> getSymbols("MSFT", from="2006-01-01", to=Sys.Date())
[1] "MSFT"
> garch11.spec = ugarchspec(variance.model = list(model="sGARCH",garchOrder=c(1,1)), mean.model = list(armaOrder=c(0,0)))
> aapl.garch11.fit = ugarchfit(spec=garch11.spec, data=ret.aapl)
> ret.msft <- dailyReturn(Cl(MSFT), type='log')
> msft.garch11.fit = ugarchfit(spec=garch11.spec, data=ret.msft)
> coef(aapl.garch11.fit,msft.garch11.fit)
> coef(aapl.garch11.fit,msft)
> coef(aapl.garch11.fit)
mu        omega       alpha1        beta1
1.700167e-03 1.176985e-05 9.475834e-02 8.766407e-01
> coef(msft.garch11.fit)
mu        omega       alpha1        beta1
7.734746e-04 1.433521e-05 8.504512e-02 8.621305e-01
> snp.garch11.fit = ugarchfit(spec=garch11.spec, data=ret)
> coef(snp.garch11.fit)
mu        omega       alpha1        beta1
1.706789e-04 5.644230e-06 5.546570e-02 9.315732e-01
> coef(msft.garch11.fit)
mu        omega       alpha1        beta1
7.734746e-04 1.433521e-05 8.504512e-02 8.621305e-01
> vcov(msft.garch11.fit)
[,1]          [,2]          [,3]          [,4]
[1,]  5.786814e-08  3.498251e-12  2.856297e-08 -5.415457e-08
[2,]  3.498251e-12 -4.961851e-13  4.724491e-09  3.658413e-10
[3,]  2.856297e-08  4.724491e-09  3.722196e-05 -6.588370e-05
[4,] -5.415457e-08  3.658413e-10 -6.588370e-05  5.696962e-05
> vcov(snp.garch11.fit)
[,1]          [,2]          [,3]          [,4]
[1,]  8.177927e-08  3.404229e-11  2.462362e-08 -9.878701e-08
[2,]  3.404229e-11  8.049606e-12  3.231152e-09 -2.080416e-08
[3,]  2.462362e-08  3.231152e-09  3.340823e-05 -3.542667e-05
[4,] -9.878701e-08 -2.080416e-08 -3.542667e-05  7.867925e-05
> vcov(aapl.garch11.fit)
[,1]          [,2]          [,3]          [,4]
[1,]  7.611219e-08  3.620399e-11 -1.120577e-07 -1.376671e-07
[2,]  3.620399e-11 -5.414818e-13  6.852512e-09 -2.395640e-09
[3,] -1.120577e-07  6.852512e-09  1.975231e-05 -5.243911e-05
[4,] -1.376671e-07 -2.395640e-09 -5.243911e-05  6.129306e-05

### > infocriteria(msft.garch11.fit)

Akaike       -5.525036
Bayes        -5.517915
Shibata      -5.525039
Hannan-Quinn -5.522493
> infocriteria(snp.garch11.fit)

Akaike       -4.987933
Bayes        -4.981582
Shibata      -4.987935
Hannan-Quinn -4.985681
> infocriteria(aapl.garch11.fit)

Akaike       -5.184153
Bayes        -5.177033
Shibata      -5.184156
Hannan-Quinn -5.181610
> newsimpact(msft.garch11.fit)
\$zy
[1] 0.0079023565 0.0075962253 0.0072963417 0.0070027056
[5] 0.0067153172 0.0064341763 0.0061592830 0.0058906372
[9] 0.0056282391 0.0053720885 0.0051221855 0.0048785300
[13] 0.0046411222 0.0044099619 0.0041850492 0.0039663840
[17] 0.0037539665 0.0035477965 0.0033478741 0.0031541992
[21] 0.0029667720 0.0027855923 0.0026106602 0.0024419757
[25] 0.0022795387 0.0021233493 0.0019734075 0.0018297133
[29] 0.0016922666 0.0015610675 0.0014361160 0.0013174121
[33] 0.0012049558 0.0010987470 0.0009987858 0.0009050721
[37] 0.0008176061 0.0007363876 0.0006614167 0.0005926934
[41] 0.0005302176 0.0004739894 0.0004240088 0.0003802758
[45] 0.0003427904 0.0003115525 0.0002865622 0.0002678195
[49] 0.0002553243 0.0002490767 0.0002490767 0.0002553243
[53] 0.0002678195 0.0002865622 0.0003115525 0.0003427904
[57] 0.0003802758 0.0004240088 0.0004739894 0.0005302176
[61] 0.0005926934 0.0006614167 0.0007363876 0.0008176061
[65] 0.0009050721 0.0009987858 0.0010987470 0.0012049558
[69] 0.0013174121 0.0014361160 0.0015610675 0.0016922666
[73] 0.0018297133 0.0019734075 0.0021233493 0.0022795387
[77] 0.0024419757 0.0026106602 0.0027855923 0.0029667720
[81] 0.0031541992 0.0033478741 0.0035477965 0.0037539665
[85] 0.0039663840 0.0041850492 0.0044099619 0.0046411222
[89] 0.0048785300 0.0051221855 0.0053720885 0.0056282391
[93] 0.0058906372 0.0061592830 0.0064341763 0.0067153172
[97] 0.0070027056 0.0072963417 0.0075962253 0.0079023565

\$zx
[1] -0.300000000 -0.293939394 -0.287878788 -0.281818182
[5] -0.275757576 -0.269696970 -0.263636364 -0.257575758
[9] -0.251515152 -0.245454545 -0.239393939 -0.233333333
[13] -0.227272727 -0.221212121 -0.215151515 -0.209090909
[17] -0.203030303 -0.196969697 -0.190909091 -0.184848485
[21] -0.178787879 -0.172727273 -0.166666667 -0.160606061
[25] -0.154545455 -0.148484848 -0.142424242 -0.136363636
[29] -0.130303030 -0.124242424 -0.118181818 -0.112121212
[33] -0.106060606 -0.100000000 -0.093939394 -0.087878788
[37] -0.081818182 -0.075757576 -0.069696970 -0.063636364
[41] -0.057575758 -0.051515152 -0.045454545 -0.039393939
[45] -0.033333333 -0.027272727 -0.021212121 -0.015151515
[49] -0.009090909 -0.003030303  0.003030303  0.009090909
[53]  0.015151515  0.021212121  0.027272727  0.033333333
[57]  0.039393939  0.045454545  0.051515152  0.057575758
[61]  0.063636364  0.069696970  0.075757576  0.081818182
[65]  0.087878788  0.093939394  0.100000000  0.106060606
[69]  0.112121212  0.118181818  0.124242424  0.130303030
[73]  0.136363636  0.142424242  0.148484848  0.154545455
[77]  0.160606061  0.166666667  0.172727273  0.178787879
[81]  0.184848485  0.190909091  0.196969697  0.203030303
[85]  0.209090909  0.215151515  0.221212121  0.227272727
[89]  0.233333333  0.239393939  0.245454545  0.251515152
[93]  0.257575758  0.263636364  0.269696970  0.275757576
[97]  0.281818182  0.287878788  0.293939394  0.300000000

\$yexpr
expression(sigma[t]^2)

\$xexpr
expression(epsilon[t - 1])
> newsimpact(snp.garch11.fit)
\$zy
[1] 0.0054032323 0.0052035762 0.0050079947 0.0048164878
[5] 0.0046290555 0.0044456978 0.0042664147 0.0040912063
[9] 0.0039200725 0.0037530132 0.0035900286 0.0034311186
[13] 0.0032762833 0.0031255225 0.0029788364 0.0028362248
[17] 0.0026976879 0.0025632256 0.0024328380 0.0023065249
[21] 0.0021842864 0.0020661226 0.0019520334 0.0018420188
[25] 0.0017360788 0.0016342134 0.0015364226 0.0014427065
[29] 0.0013530650 0.0012674981 0.0011860058 0.0011085881
[33] 0.0010352450 0.0009659765 0.0009007827 0.0008396635
[37] 0.0007826189 0.0007296489 0.0006807535 0.0006359327
[41] 0.0005951866 0.0005585150 0.0005259181 0.0004973958
[45] 0.0004729481 0.0004525750 0.0004362766 0.0004240527
[49] 0.0004159035 0.0004118289 0.0004118289 0.0004159035
[53] 0.0004240527 0.0004362766 0.0004525750 0.0004729481
[57] 0.0004973958 0.0005259181 0.0005585150 0.0005951866
[61] 0.0006359327 0.0006807535 0.0007296489 0.0007826189
[65] 0.0008396635 0.0009007827 0.0009659765 0.0010352450
[69] 0.0011085881 0.0011860058 0.0012674981 0.0013530650
[73] 0.0014427065 0.0015364226 0.0016342134 0.0017360788
[77] 0.0018420188 0.0019520334 0.0020661226 0.0021842864
[81] 0.0023065249 0.0024328380 0.0025632256 0.0026976879
[85] 0.0028362248 0.0029788364 0.0031255225 0.0032762833
[89] 0.0034311186 0.0035900286 0.0037530132 0.0039200725
[93] 0.0040912063 0.0042664147 0.0044456978 0.0046290555
[97] 0.0048164878 0.0050079947 0.0052035762 0.0054032323

\$zx
[1] -0.300000000 -0.293939394 -0.287878788 -0.281818182
[5] -0.275757576 -0.269696970 -0.263636364 -0.257575758
[9] -0.251515152 -0.245454545 -0.239393939 -0.233333333
[13] -0.227272727 -0.221212121 -0.215151515 -0.209090909
[17] -0.203030303 -0.196969697 -0.190909091 -0.184848485
[21] -0.178787879 -0.172727273 -0.166666667 -0.160606061
[25] -0.154545455 -0.148484848 -0.142424242 -0.136363636
[29] -0.130303030 -0.124242424 -0.118181818 -0.112121212
[33] -0.106060606 -0.100000000 -0.093939394 -0.087878788
[37] -0.081818182 -0.075757576 -0.069696970 -0.063636364
[41] -0.057575758 -0.051515152 -0.045454545 -0.039393939
[45] -0.033333333 -0.027272727 -0.021212121 -0.015151515
[49] -0.009090909 -0.003030303  0.003030303  0.009090909
[53]  0.015151515  0.021212121  0.027272727  0.033333333
[57]  0.039393939  0.045454545  0.051515152  0.057575758
[61]  0.063636364  0.069696970  0.075757576  0.081818182
[65]  0.087878788  0.093939394  0.100000000  0.106060606
[69]  0.112121212  0.118181818  0.124242424  0.130303030
[73]  0.136363636  0.142424242  0.148484848  0.154545455
[77]  0.160606061  0.166666667  0.172727273  0.178787879
[81]  0.184848485  0.190909091  0.196969697  0.203030303
[85]  0.209090909  0.215151515  0.221212121  0.227272727
[89]  0.233333333  0.239393939  0.245454545  0.251515152
[93]  0.257575758  0.263636364  0.269696970  0.275757576
[97]  0.281818182  0.287878788  0.293939394  0.300000000

\$yexpr
expression(sigma[t]^2)

\$xexpr
expression(epsilon[t - 1])
> newsimpact(aapl.garch11.fit)
\$zy
[1] 0.0089007751 0.0085596799 0.0082255459 0.0078983729
[5] 0.0075781611 0.0072649104 0.0069586208 0.0066592924
[9] 0.0063669250 0.0060815188 0.0058030738 0.0055315898
[13] 0.0052670670 0.0050095053 0.0047589048 0.0045152653
[17] 0.0042785870 0.0040488698 0.0038261138 0.0036103189
[21] 0.0034014851 0.0031996124 0.0030047008 0.0028167504
[25] 0.0026357611 0.0024617330 0.0022946659 0.0021345600
[29] 0.0019814152 0.0018352316 0.0016960090 0.0015637476
[33] 0.0014384473 0.0013201082 0.0012087302 0.0011043133
[37] 0.0010068575 0.0009163628 0.0008328293 0.0007562569
[41] 0.0006866457 0.0006239955 0.0005683065 0.0005195786
[45] 0.0004778119 0.0004430062 0.0004151617 0.0003942783
[49] 0.0003803561 0.0003733950 0.0003733950 0.0003803561
[53] 0.0003942783 0.0004151617 0.0004430062 0.0004778119
[57] 0.0005195786 0.0005683065 0.0006239955 0.0006866457
[61] 0.0007562569 0.0008328293 0.0009163628 0.0010068575
[65] 0.0011043133 0.0012087302 0.0013201082 0.0014384473
[69] 0.0015637476 0.0016960090 0.0018352316 0.0019814152
[73] 0.0021345600 0.0022946659 0.0024617330 0.0026357611
[77] 0.0028167504 0.0030047008 0.0031996124 0.0034014851
[81] 0.0036103189 0.0038261138 0.0040488698 0.0042785870
[85] 0.0045152653 0.0047589048 0.0050095053 0.0052670670
[89] 0.0055315898 0.0058030738 0.0060815188 0.0063669250
[93] 0.0066592924 0.0069586208 0.0072649104 0.0075781611
[97] 0.0078983729 0.0082255459 0.0085596799 0.0089007751

\$zx
[1] -0.300000000 -0.293939394 -0.287878788 -0.281818182
[5] -0.275757576 -0.269696970 -0.263636364 -0.257575758
[9] -0.251515152 -0.245454545 -0.239393939 -0.233333333
[13] -0.227272727 -0.221212121 -0.215151515 -0.209090909
[17] -0.203030303 -0.196969697 -0.190909091 -0.184848485
[21] -0.178787879 -0.172727273 -0.166666667 -0.160606061
[25] -0.154545455 -0.148484848 -0.142424242 -0.136363636
[29] -0.130303030 -0.124242424 -0.118181818 -0.112121212
[33] -0.106060606 -0.100000000 -0.093939394 -0.087878788
[37] -0.081818182 -0.075757576 -0.069696970 -0.063636364
[41] -0.057575758 -0.051515152 -0.045454545 -0.039393939
[45] -0.033333333 -0.027272727 -0.021212121 -0.015151515
[49] -0.009090909 -0.003030303  0.003030303  0.009090909
[53]  0.015151515  0.021212121  0.027272727  0.033333333
[57]  0.039393939  0.045454545  0.051515152  0.057575758
[61]  0.063636364  0.069696970  0.075757576  0.081818182
[65]  0.087878788  0.093939394  0.100000000  0.106060606
[69]  0.112121212  0.118181818  0.124242424  0.130303030
[73]  0.136363636  0.142424242  0.148484848  0.154545455
[77]  0.160606061  0.166666667  0.172727273  0.178787879
[81]  0.184848485  0.190909091  0.196969697  0.203030303
[85]  0.209090909  0.215151515  0.221212121  0.227272727
[89]  0.233333333  0.239393939  0.245454545  0.251515152
[93]  0.257575758  0.263636364  0.269696970  0.275757576
[97]  0.281818182  0.287878788  0.293939394  0.300000000

\$yexpr
expression(sigma[t]^2)

\$xexpr
expression(epsilon[t - 1])

### Black-Scholes formula-R

Black-Scholes formula-R > BlackScholes <- function(TypeFlag = c("c", "p"), S, X, Time, r, b, sigma) { TypeFla...