Learn statistical analysis in stock
I am going to discuss SNP stock's price analysis. Here I have
taken a data till 31 July 2020. I have used most of the
statistical tools with R language. Anyone can check data
is correct from American stock exchange listed snp.
"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")
> hist(ret, nclass=10, freq=FALSE, main='Return histogram');curve(dnorm(x,mean=m,sd=s), from = -0.3, to = 0.2, add=TRUE, col="red")
> hist(ret, nclass=100, 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)
> kurtosis(ret)
daily.returns
9.168088
> skewness(ret)
daily.returns
0.2028404
> 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")
> plot(density(ret), xlim=c(-5*s,5*s),log='y', main='Density on log-scale')
> curve(dnorm(x, mean=m,sd=s), from=-5*s, to=5*s, log="y", add=TRUE,col="red")chartSeries(ret)
> garch11.spec = ugarchspec(variance.model = list(model="sGARCH",garchOrder=c(1,1)), mean.model = list(armaOrder=c(0,0)))
> snp.garch11.fit = ugarchfit(spec=garch11.spec, data=ret)
> coef(snp.garch11.fit)
mu omega alpha1
1.062331e-04 5.984410e-06 5.864131e-02
beta1
9.278945e-01
> vcov(snp.garch11.fit)
[,1] [,2] [,3]
[1,] 7.738308e-08 5.616040e-11 2.073833e-08
[2,] 5.616040e-11 1.049284e-11 4.857391e-10
[3,] 2.073833e-08 4.857391e-10 3.296697e-05
[4,] -1.519588e-07 -2.514487e-08 -2.876245e-05
[,4]
[1,] -1.519588e-07
[2,] -2.514487e-08
[3,] -2.876245e-05
[4,] 8.556896e-05
> infocriteria(snp.garch11.fit)
Akaike -4.989038
Bayes -4.982966
Shibata -4.989040
Hannan-Quinn -4.986890
> uncvariance(snp.garch11.fit)
[1] 0.0004444674
> uncmean(snp.garch11.fit)
[1] 0.0001062331
> newsimpact(snp.garch11.fit)
$zy
[1] 0.0056961210 0.0054850339 0.0052782546
[4] 0.0050757832 0.0048776197 0.0046837642
[7] 0.0044942165 0.0043089767 0.0041280449
[10] 0.0039514209 0.0037791049 0.0036110967
[13] 0.0034473964 0.0032880041 0.0031329196
[16] 0.0029821431 0.0028356744 0.0026935137
[19] 0.0025556608 0.0024221159 0.0022928788
[22] 0.0021679497 0.0020473285 0.0019310151
[25] 0.0018190097 0.0017113121 0.0016079225
[28] 0.0015088408 0.0014140669 0.0013236010
[31] 0.0012374430 0.0011555929 0.0010780506
[34] 0.0010048163 0.0009358899 0.0008712714
[37] 0.0008109607 0.0007549580 0.0007032632
[40] 0.0006558763 0.0006127973 0.0005740262
[43] 0.0005395629 0.0005094076 0.0004835602
[46] 0.0004620207 0.0004447891 0.0004318654
[49] 0.0004232496 0.0004189417 0.0004189417
[52] 0.0004232496 0.0004318654 0.0004447891
[55] 0.0004620207 0.0004835602 0.0005094076
[58] 0.0005395629 0.0005740262 0.0006127973
[61] 0.0006558763 0.0007032632 0.0007549580
[64] 0.0008109607 0.0008712714 0.0009358899
[67] 0.0010048163 0.0010780506 0.0011555929
[70] 0.0012374430 0.0013236010 0.0014140669
[73] 0.0015088408 0.0016079225 0.0017113121
[76] 0.0018190097 0.0019310151 0.0020473285
[79] 0.0021679497 0.0022928788 0.0024221159
[82] 0.0025556608 0.0026935137 0.0028356744
[85] 0.0029821431 0.0031329196 0.0032880041
[88] 0.0034473964 0.0036110967 0.0037791049
[91] 0.0039514209 0.0041280449 0.0043089767
[94] 0.0044942165 0.0046837642 0.0048776197
[97] 0.0050757832 0.0052782546 0.0054850339
[100] 0.0056961210
$zx
[1] -0.300000000 -0.293939394 -0.287878788
[4] -0.281818182 -0.275757576 -0.269696970
[7] -0.263636364 -0.257575758 -0.251515152
[10] -0.245454545 -0.239393939 -0.233333333
[13] -0.227272727 -0.221212121 -0.215151515
[16] -0.209090909 -0.203030303 -0.196969697
[19] -0.190909091 -0.184848485 -0.178787879
[22] -0.172727273 -0.166666667 -0.160606061
[25] -0.154545455 -0.148484848 -0.142424242
[28] -0.136363636 -0.130303030 -0.124242424
[31] -0.118181818 -0.112121212 -0.106060606
[34] -0.100000000 -0.093939394 -0.087878788
[37] -0.081818182 -0.075757576 -0.069696970
[40] -0.063636364 -0.057575758 -0.051515152
[43] -0.045454545 -0.039393939 -0.033333333
[46] -0.027272727 -0.021212121 -0.015151515
[49] -0.009090909 -0.003030303 0.003030303
[52] 0.009090909 0.015151515 0.021212121
[55] 0.027272727 0.033333333 0.039393939
[58] 0.045454545 0.051515152 0.057575758
[61] 0.063636364 0.069696970 0.075757576
[64] 0.081818182 0.087878788 0.093939394
[67] 0.100000000 0.106060606 0.112121212
[70] 0.118181818 0.124242424 0.130303030
[73] 0.136363636 0.142424242 0.148484848
[76] 0.154545455 0.160606061 0.166666667
[79] 0.172727273 0.178787879 0.184848485
[82] 0.190909091 0.196969697 0.203030303
[85] 0.209090909 0.215151515 0.221212121
[88] 0.227272727 0.233333333 0.239393939
[91] 0.245454545 0.251515152 0.257575758
[94] 0.263636364 0.269696970 0.275757576
[97] 0.281818182 0.287878788 0.293939394
[100] 0.300000000
$yexpr
expression(sigma[t]^2)
$xexpr
expression(epsilon[t - 1])fitted(snp.garch11.fit)
residuals(snp.garch11.fit)
signbias(snp.garch11.fit)
t-value prob sig
Sign Bias 0.65764074 0.5108053
Negative Sign Bias 0.80510086 0.4208074
Positive Sign Bias 0.02804464 0.9776279
Joint Effect 2.82505192 0.4193925 ni.garch11 <- newsimpact(snp.garch11.fit)
> plot(ni.garch11$zx, ni.garch11$zy, type="l", lwd=2, col="blue",main="GARCH(1,1)-News
Impact", ylab=ni.garch11$yexpr, xlab=ni.garch11$xexpr)
How to use Egarch model?
Exponential GARCH model approches the logarithms of conditional volatility.
more
https://rstudio.cloud/project/1500532
0 Comments