Purpse Empirically Check Tails
> library(xts)
> nifty <- read.csv("C:/Cauldron/Benchmark/Interns/nifty.csv",
+ header = T, stringsAsFactors = F)
> nifty$trade.date <- as.Date(nifty[, 1], format = "%d-%b-%y")
> nifty <- xts(nifty[, 2], nifty$trade.date)
> plot(nifty) |
![Tails-001.jpg](images/tails-001.jpg)
> library(fPortfolio)
> nifty.ret <- returns(nifty)
> hist(nifty.ret) |
![Tails-002.jpg](images/tails-002.jpg)
> nifty.ret <- as.xts(nifty.ret[-1, 1])
> nifty.mean <- mean(nifty.ret)
> nifty.sd <- sd(nifty.ret)
> onesd.lim <- nifty.mean + c(-1, 1) * nifty.sd
> twosd.lim <- nifty.mean + c(-1, 1) * 2 * nifty.sd
> threesd.lim <- nifty.mean + c(-1, 1) * 3 * nifty.sd
> counter <- c(0, 0, 0)
> for (i in seq_along(nifty.ret[, 1])) {
+ if (nifty.ret[i, 1] < onesd.lim[1] | nifty.ret[i, 1] > onesd.lim[2]) {
+ counter[1] <- counter[1] + 1
+ }
+ if (nifty.ret[i, 1] < twosd.lim[1] | nifty.ret[i, 1] > twosd.lim[2]) {
+ counter[2] <- counter[2] + 1
+ }
+ if (nifty.ret[i, 1] < threesd.lim[1] | nifty.ret[i, 1] >
+ threesd.lim[2]) {
+ counter[3] <- counter[3] + 1
+ }
+ } |
If I sample from 2096 days, how many obs will be more than 1 sig, 2 sig, 3 sig
> th1 <- 2096 - (pnorm(1) - pnorm(-1)) * 2096
> th2 <- 2096 - (pnorm(2) - pnorm(-2)) * 2096
> th3 <- 2096 - (pnorm(3) - pnorm(-3)) * 2096
> th <- c(th1, th2, th3) |
> library(ggplot2)
> y <- data.frame(data = rbind(round(c(counter, th)), rep(1:6,
+ 1)))
> z <- data.frame(t(y))
> colnames(z) <- c("days", "sig")
> z$sig <- factor(z$sig)
> p <- ggplot(z, aes(y = days, x = sig, fill = sig))
> q <- p + geom_bar(stat = "Identity")
> print(q) |
![Tails-005.jpg](images/tails-005.jpg)
The second three bars are theoretical number of days for 1 sig, 2 sig, 2 sig
> print(counter)
[1] 457 112 34
> print(round(th))
[1] 665 95 6 |
![Tails-006.jpg](images/tails-006.jpg)
> min(nifty.ret)
[1] -0.1305515 |
there has been a maximum decline of 13 percent in day .Look at the theoretical prob and you can get an idea of how the theoretical model is totally flawed
> pnorm(-0.13, nifty.mean, nifty.sd)
[1] 2.230451e-14 |