Showing posts with label How to capture fat tails and volatility clustering. Show all posts
Showing posts with label How to capture fat tails and volatility clustering. Show all posts

## How to  capture fat tails and volatility clustering

getSymbols("FB", from="2004-01-01", to=Sys.Date(2019-08-08))
[1] "FB"
> chartSeries(Cl(FB))

> ret <- dailyReturn(Cl(FB), 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")

### How to draw histogram FB.

> 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")

#### How to draw histogram FB.

> 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))
> 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")

How to density plotson log scale
> #density plots on log-scale
> 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")

> # QQ-plot
> qqnorm(ret);qqline(ret);
How to check volatility
> #GARCH
> ret.fb <- dailyReturn(Cl(FB), type='log')
> chartSeries(ret.fb)

> garch11.spec = ugarchspec(variance.model = list(model="sGARCH",
+ garchOrder=c(1,1)), mean.model = list(armaOrder=c(0,0)))
> fb.garch11.fit = ugarchfit(spec=garch11.spec, data=ret.fb)

#### #Estimated Coefficients

> coef(fb.garch11.fit)
mu        omega       alpha1
9.722065e-04 8.722771e-07 1.335286e-02
beta1
9.850393e-01
> coef(fb.garch11.fit)
mu        omega       alpha1
9.722065e-04 8.722771e-07 1.335286e-02
beta1
9.850393e-01