Stocks getSymbols("^N225", from="2004-01-01", to=Sys.Date()
getSymbols for details.[1] "^N225"
^N225 contains missing values. Some functions will not work if objects contain missing values in the middle of the series. Consider using na.omit(), na.approx(), na.fill(), etc to remove or replace them.
> chartSeries(Cl(N225))
> addMACD()
> addBBands()
> addRSI()
> ret <- dailyReturn(Cl(N225), 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
> library("tseries", lib.loc="~/R/win-library/3.6")
‘tseries’ version: 0.10-47
‘tseries’ is a package for time series analysis
and computational finance.
See ‘library(help="tseries")’ for details.
> kurtosis(ret)
daily.returns
11.26807
> 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')
Warning message:
In xy.coords(x, y, xlabel, ylabel, log) :
1 y value <= 0 omitted from logarithmic plot
> curve(dnorm(x, mean=m,sd=s), from=-5*s, to=5*s, log="y", add=TRUE,
+ col="red")
> qqnorm(ret);qqline(ret);
> 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)
> garch11.spec = ugarchspec(variance.model = list(model="sGARCH",garchOrder=c(1,1)), mean.model = list(armaOrder=c(0,0)))
> n225.garch11.fit = ugarchfit(spec=garch11.spec, data=ret)
> coef(n225.garch11.fit)
mu omega alpha1 beta1
6.427360e-04 4.823071e-06 1.222063e-01 8.565826e-01
> vcov(n225.garch11.fit)
[,1] [,2] [,3] [,4]
[1,] 3.159808e-08 5.055371e-11 1.524294e-07 -3.848717e-07
[2,] 5.055371e-11 8.016214e-12 5.234306e-09 -4.579360e-08
[3,] 1.524294e-07 5.234306e-09 1.154107e-04 -1.135709e-04
[4,] -3.848717e-07 -4.579360e-08 -1.135709e-04 3.328539e-04
> infocriteria(n225.garch11.fit)
Akaike -5.929148
Bayes -5.922650
Shibata -5.929150
Hannan-Quinn -5.926840
> newsimpact(n225.garch11.fit)
$zy
[1] 0.0111981608 0.0107582631 0.0103273429 0.0099054003
[5] 0.0094924351 0.0090884474 0.0086934372 0.0083074046
[9] 0.0079303494 0.0075622717 0.0072031716 0.0068530489
[13] 0.0065119038 0.0061797361 0.0058565460 0.0055423333
[17] 0.0052370982 0.0049408406 0.0046535604 0.0043752578
[21] 0.0041059327 0.0038455851 0.0035942150 0.0033518224
[25] 0.0031184073 0.0028939697 0.0026785096 0.0024720270
[29] 0.0022745219 0.0020859943 0.0019064442 0.0017358717
[33] 0.0015742766 0.0014216590 0.0012780190 0.0011433564
[37] 0.0010176713 0.0009009638 0.0007932337 0.0006944812
[41] 0.0006047062 0.0005239086 0.0004520886 0.0003892461
[45] 0.0003353810 0.0002904935 0.0002545835 0.0002276510
[49] 0.0002096960 0.0002007185 0.0002007185 0.0002096960
[53] 0.0002276510 0.0002545835 0.0002904935 0.0003353810
[57] 0.0003892461 0.0004520886 0.0005239086 0.0006047062
[61] 0.0006944812 0.0007932337 0.0009009638 0.0010176713
[65] 0.0011433564 0.0012780190 0.0014216590 0.0015742766
[69] 0.0017358717 0.0019064442 0.0020859943 0.0022745219
[73] 0.0024720270 0.0026785096 0.0028939697 0.0031184073
[77] 0.0033518224 0.0035942150 0.0038455851 0.0041059327
[81] 0.0043752578 0.0046535604 0.0049408406 0.0052370982
[85] 0.0055423333 0.0058565460 0.0061797361 0.0065119038
[89] 0.0068530489 0.0072031716 0.0075622717 0.0079303494
[93] 0.0083074046 0.0086934372 0.0090884474 0.0094924351
[97] 0.0099054003 0.0103273429 0.0107582631 0.0111981608
$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(n225.garch11.fit)
t-value prob sig
Sign Bias 0.2689697 7.879674e-01
Negative Sign Bias 1.8897085 5.887209e-02 *
Positive Sign Bias 3.0714138 2.145370e-03 ***
Joint Effect 27.3890944 4.878989e-06 ***
> uncvariance(n225.garch11.fit)
[1] 0.000227384
> uncmean(n225.garch11.fit)
[1] 0.000642736
> ni.garch11 <- newsimpact(n225.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)
> egarch11.spec = ugarchspec(variance.model = list(model="eGARCH",garchOrder=c(1,1)), mean.model = list(armaOrder=c(0,0)))
> n225.egarch11.fit = ugarchfit(spec=egarch11.spec, data=ret)
> coef(n225.egarch11.fit)
mu omega alpha1 beta1
0.0002244642 -0.3560238964 -0.1102183933 0.9587525507
gamma1
0.2100511983
> ni.egarch11 <- newsimpact(n225.egarch11.fit)
> plot(ni.egarch11$zx, ni.egarch11$zy, type="l", lwd=2, col="blue",
+ main="EGARCH(1,1) - News Impact",
+ ylab=ni.egarch11$yexpr, xlab=ni.egarch11$xexpr)
> ni.tgarch11 <- newsimpact(n225.tgarch11.fit)
Error in newsimpact(n225.tgarch11.fit) :
object 'n225.tgarch11.fit' not found
> tgarch11.spec = ugarchspec(variance.model = list(model="fGARCH",
+ submodel="TGARCH", garchOrder=c(1,1)),
+ mean.model = list(armaOrder=c(0,0))
+
+
+
+
+ )
> n225.tgarch11.fit = ugarchfit(spec=tgarch11.spec, data=ret)
> coef(n225.tgarch11.fit)
mu omega alpha1 beta1
0.0002020664 0.0005435875 0.1148669161 0.8704087819
eta11
0.5881172013
> ni.tgarch11 <- newsimpact(n225.tgarch11.fit)
> plot(ni.tgarch11$zx, ni.tgarch11$zy, type="l", lwd=2, col="blue",
+ main="TGARCH(1,1) - News Impact",
+ ylab=ni.tgarch11$yexpr, xlab=ni.tgarch11$xexpr)
> garch11.spec = ugarchspec(variance.model = list(garchOrder=c(1,1)),mean.model = list(armaOrder=c(0,0)),fixed.pars=list(mu = 0, omega=0.1, alpha1=0.1,beta1 = 0.7))
> garch11.sim = ugarchpath(garch11.spec, n.sim=1000)
> n225.garch11.fit = ugarchfit(spec=garch11.spec, data=ret, out.sample=20)
Conclusion
In .sgarchfit(spec = spec, data = data, out.sample = out.sample, :
ugarchfit-->warning: all parameters fixed...returning ugarchfilter object instead
> n225.garch11.fcst = ugarchforecast(n225.garch11.fit, n.ahead=10,n.roll=10)









0 Comments