Showing posts with label statistics NASDAQ Composite. Show all posts
Showing posts with label statistics NASDAQ Composite. Show all posts

Thursday, September 19, 2019

Get statistics NASDAQ Composite

 How to get statistics NASDAQ Composite (^IXIC)

> getSymbols("^IXIC", from="2004-01-01", to=Sys.Date())
[1] "^IXIC"
> chartSeries(Cl(IXIC))
nasdaq composite,nasdaq,finance,s&p 500 index,stock market,dow jones&company,learning by listening,position limits,investing,s&p dow jones indices,conspiracy,how to trade

> addRSI()
> addMACD()
> addBBands()
> ret <- dailyReturn(Cl(IXIC), 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")
nasdaq composite,nasdaq,finance,s&p 500 index,stock market,dow jones&company,learning by listening,position limits,investing,s&p dow jones indices,conspiracy,how to trade
nasdaq composite,nasdaq,finance,s&p 500 index,stock market,dow jones&company,learning by listening,position limits,investing,s&p dow jones indices,conspiracy,how to trade

> 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")
nasdaq composite,nasdaq,finance,s&p 500 index,stock market,dow jones&company,learning by listening,position limits,investing,s&p dow jones indices,conspiracy,how to trade

> plot(density(ret), main='Return empirical distribution');curve(dnorm(x,mean=m,sd=s), from = -0.3, to = 0.2, add=TRUE, col="red")
nasdaq composite,nasdaq,finance,s&p 500 index,stock market,dow jones&company,learning by listening,position limits,investing,s&p dow jones indices,conspiracy,how to trade

> 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
     10.25008
> plot(density(ret), main='Return EDF - upper tail', xlim = c(0.1, 0.2),
+      ylim=c(0,2));
nasdaq composite,nasdaq,finance,s&p 500 index,stock market,dow jones&company,learning by listening,position limits,investing,s&p dow jones indices,conspiracy,how to trade

> 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")
> qqnorm(ret);qqline(ret);
nasdaq composite,nasdaq,finance,s&p 500 index,stock market,dow jones&company,learning by listening,position limits,investing,s&p dow jones indices,conspiracy,how to trade

> library("rugarch", lib.loc="~/R/win-library/3.6")
Loading required package: parallel

Attaching package: ‘rugarch’

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

    sigma

> chartSeries(ret)
nasdaq composite,nasdaq,finance,s&p 500 index,stock market,dow jones&company,learning by listening,position limits,investing,s&p dow jones indices,conspiracy,how to trade

> garch11.spec = ugarchspec(variance.model = list(model="sGARCH",garchOrder=c(1,1)), mean.model = list(armaOrder=c(0,0)))
> ixic.garch11.fit = ugarchfit(spec=garch11.spec, data=ret)
> coef(ixic.garch11.fit)
          mu        omega       alpha1        beta1
7.437932e-04 3.473346e-06 9.976260e-02 8.737787e-01
> coef(ixic.garch11.fit)
          mu        omega       alpha1        beta1
7.437932e-04 3.473346e-06 9.976260e-02 8.737787e-01
> vcov(ixic.garch11.fit)
              [,1]          [,2]          [,3]          [,4]
[1,]  2.231885e-08  3.793626e-11  1.205145e-07 -3.237873e-07
[2,]  3.793626e-11  1.806952e-12  2.458478e-09 -1.265085e-08
[3,]  1.205145e-07  2.458478e-09  7.668355e-05 -7.432305e-05
[4,] -3.237873e-07 -1.265085e-08 -7.432305e-05  1.398529e-04
> infocriteria(ixic.garch11.fit)
                   
Akaike       -6.274916
Bayes        -6.268560
Shibata      -6.274918
Hannan-Quinn -6.272662
 newsimpact(ixic.garch11.fit)
$zy
  [1] 0.0090968121 0.0087377033 0.0083859234 0.0080414722
  [5] 0.0077043497 0.0073745560 0.0070520910 0.0067369548
  [9] 0.0064291473 0.0061286686 0.0058355186 0.0055496974
 [13] 0.0052712050 0.0050000412 0.0047362063 0.0044797000
 [17] 0.0042305226 0.0039886738 0.0037541539 0.0035269626
 [21] 0.0033071002 0.0030945664 0.0028893615 0.0026914852
 [25] 0.0025009377 0.0023177190 0.0021418290 0.0019732678
 [29] 0.0018120353 0.0016581316 0.0015115566 0.0013723104
 [33] 0.0012403929 0.0011158041 0.0009985442 0.0008886129
 [37] 0.0007860104 0.0006907367 0.0006027917 0.0005221755
 [41] 0.0004488880 0.0003829292 0.0003242992 0.0002729980
 [45] 0.0002290255 0.0001923817 0.0001630667 0.0001410805
 [49] 0.0001264230 0.0001190942 0.0001190942 0.0001264230
 [53] 0.0001410805 0.0001630667 0.0001923817 0.0002290255
 [57] 0.0002729980 0.0003242992 0.0003829292 0.0004488880
 [61] 0.0005221755 0.0006027917 0.0006907367 0.0007860104
 [65] 0.0008886129 0.0009985442 0.0011158041 0.0012403929
 [69] 0.0013723104 0.0015115566 0.0016581316 0.0018120353
 [73] 0.0019732678 0.0021418290 0.0023177190 0.0025009377
 [77] 0.0026914852 0.0028893615 0.0030945664 0.0033071002
 [81] 0.0035269626 0.0037541539 0.0039886738 0.0042305226
 [85] 0.0044797000 0.0047362063 0.0050000412 0.0052712050
 [89] 0.0055496974 0.0058355186 0.0061286686 0.0064291473
 [93] 0.0067369548 0.0070520910 0.0073745560 0.0077043497
 [97] 0.0080414722 0.0083859234 0.0087377033 0.0090968121

$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])
signbias(ixic.garch11.fit)
                              t-value         prob sig
Sign Bias             2.5814648      9.873929e-03 ***
Negative Sign Bias  0.3395914  7.341823e-01 
Positive Sign Bias  2.1695032    3.010396e-02  **
Joint Effect       27.2806127        5.141403e-06 ***
fitted(ixic.garch11.fit)
 #obtain the fitted data series
residuals(ixic.garch11.fit)
uncvariance(ixic.garch11.fit)
[1] 0.0001312744
> uncmean(ixic.garch11.fit)
[1] 0.0007437932
> ni.garch11 <- newsimpact(ixic.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)
nasdaq composite,nasdaq,finance,s&p 500 index,stock market,dow jones&company,learning by listening,position limits,investing,s&p dow jones indices,conspiracy,how to trade

Error: unexpected symbol in:
"     main="GARCH(1,1) - News Impact", ylab=ni.garch11$yexpr, xlab=ni.
     garch11"
> 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)
> egarch11.spec = ugarchspec(variance.model = list(model="eGARCH",garchOrder=c(1,1)), mean.model = list(armaOrder=c(0,0)))
> ixic.egarch11.fit = ugarchfit(spec=egarch11.spec, data=ret)
> coef(icix.egarch11.fit)
Error in coef(icix.egarch11.fit) : object 'icix.egarch11.fit' not found
Conclusion
> coef(ixic.egarch11.fit)
           mu         omega        alpha1         beta1
 0.0002909353 -0.3032487994 -0.1508370561  0.9663933466
       gamma1
 0.1204588466 

Black-Scholes formula-R

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