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

Friday, August 9, 2019

How to capture fat tails and volatility clustering

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))
volatility,volatility clustering,volatility modeling,volatility clustering eviews,volatility eviews,constant volatility,trading,stochastic volatility models,historical volatility,constant volatility eviews,time-varying volatility,time-varying volatility eviews,options,financial models with long-tailed distributions and volatility clustering,statistics,stocks,futures,forex,finance,learn forex,fibonacci cluster trading,trade



> 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")
www.r-languagestatistics.co

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")
www.r-languagestatistics.co

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")
www.r-languagestatistics.co

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")
www.r-languagestatistics.co

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

> 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


Black-Scholes formula-R

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