# Import the data (Chipotle Mexican Grill (CMG) stock)
data <- read.table(file = "C:/Users/ssiamina/Videos/CMGdata.txt", header=T)
plot(data)

library (fBasics)
## Warning: package 'fBasics' was built under R version 3.3.3
## Loading required package: timeDate
## Loading required package: timeSeries
## Warning: package 'timeSeries' was built under R version 3.3.3
# Log (base = e) transform close price (i.e. the 2nd column of cmgdata.txt)
x <- log(data[,2])
# Generate differences of close prices between 't (today)' and 'the day before (t-1)'
d <- diff(x)
# fit d into Normal Inverse Gaussian (NIG) model
fit <- nigFit(d)
##
## Objective Function Value: -300.4013
## Parameter Estimates: 1 0 1 0
##
## Objective Function Value: -300.4013
## Parameter Estimates: 1 0 1 0
##
## Objective Function Value: -300.4013
## Parameter Estimates: 1 1.490116e-08 1 0
##
## Objective Function Value: -300.4013
## Parameter Estimates: 1 0 1 0
##
## Objective Function Value: -300.4013
## Parameter Estimates: 1 0 1 1.490116e-08
##
## Objective Function Value: -484.5116
## Parameter Estimates: 1.296535 0.2853266 0.1407919 0.3040019
##
## Objective Function Value: -295.4626
## Parameter Estimates: 1.033106 0.03185424 0.9040769 0.03393918
##
## Objective Function Value: -295.4628
## Parameter Estimates: 1.033089 0.03185424 0.9040769 0.03393918
##
## Objective Function Value: -295.4626
## Parameter Estimates: 1.033106 0.03183804 0.9040769 0.03393918
##
## Objective Function Value: -295.4633
## Parameter Estimates: 1.033106 0.03185424 0.9040931 0.03393918
##
## Objective Function Value: -295.4625
## Parameter Estimates: 1.033106 0.03185424 0.9040769 0.03392298
##
## Objective Function Value: -291.572
## Parameter Estimates: 1.056905 0.03072131 0.7958593 0.02033585
##
## Objective Function Value: -291.886
## Parameter Estimates: 1.112632 0.02806854 0.5424672 -0.01151642
##
## Objective Function Value: -291.572
## Parameter Estimates: 1.056902 0.03072131 0.7958593 0.02033585
##
## Objective Function Value: -291.572
## Parameter Estimates: 1.056905 0.03072277 0.7958593 0.02033585
##
## Objective Function Value: -291.5721
## Parameter Estimates: 1.056905 0.03072131 0.7958632 0.02033585
##
## Objective Function Value: -291.572
## Parameter Estimates: 1.056905 0.03072131 0.7958593 0.02033693
##
## Objective Function Value: -296.7061
## Parameter Estimates: 1.066007 0.08349719 0.4301787 0.07109053
##
## Objective Function Value: -288.9948
## Parameter Estimates: 1.060012 0.04873459 0.6710465 0.03765926
##
## Objective Function Value: -288.9947
## Parameter Estimates: 1.060009 0.04873459 0.6710465 0.03765926
##
## Objective Function Value: -288.9948
## Parameter Estimates: 1.060012 0.04873104 0.6710465 0.03765926
##
## Objective Function Value: -288.9948
## Parameter Estimates: 1.060012 0.04873459 0.6710483 0.03765926
##
## Objective Function Value: -288.9948
## Parameter Estimates: 1.060012 0.04873459 0.6710465 0.03765728
##
## Objective Function Value: -289.2103
## Parameter Estimates: 0.9916075 0.03146608 0.5832676 -0.02175481
##
## Objective Function Value: -288.5201
## Parameter Estimates: 1.029176 0.04095012 0.6314767 0.010876
##
## Objective Function Value: -288.5201
## Parameter Estimates: 1.029179 0.04095012 0.6314767 0.010876
##
## Objective Function Value: -288.5201
## Parameter Estimates: 1.029176 0.04095341 0.6314767 0.010876
##
## Objective Function Value: -288.5201
## Parameter Estimates: 1.029176 0.04095012 0.6314781 0.010876
##
## Objective Function Value: -288.5201
## Parameter Estimates: 1.029176 0.04095012 0.6314767 0.01087797
##
## Objective Function Value: -288.0104
## Parameter Estimates: 0.9878727 0.05371428 0.6162694 0.04543663
##
## Objective Function Value: -288.0104
## Parameter Estimates: 0.9878754 0.05371428 0.6162694 0.04543663
##
## Objective Function Value: -288.0104
## Parameter Estimates: 0.9878727 0.05371268 0.6162694 0.04543663
##
## Objective Function Value: -288.0104
## Parameter Estimates: 0.9878727 0.05371428 0.6162706 0.04543663
##
## Objective Function Value: -288.0104
## Parameter Estimates: 0.9878727 0.05371428 0.6162694 0.04543596
##
## Objective Function Value: -286.9109
## Parameter Estimates: 0.8877494 0.03237934 0.5687317 0.02449516
##
## Objective Function Value: -286.9109
## Parameter Estimates: 0.8877521 0.03237934 0.5687317 0.02449516
##
## Objective Function Value: -286.9109
## Parameter Estimates: 0.8877494 0.03238081 0.5687317 0.02449516
##
## Objective Function Value: -286.9109
## Parameter Estimates: 0.8877494 0.03237934 0.568733 0.02449516
##
## Objective Function Value: -286.9109
## Parameter Estimates: 0.8877494 0.03237934 0.5687317 0.02449579
##
## Objective Function Value: -285.7979
## Parameter Estimates: 0.6824473 0.01091866 0.483752 0.07817851
##
## Objective Function Value: -285.7979
## Parameter Estimates: 0.68245 0.01091866 0.483752 0.07817851
##
## Objective Function Value: -285.7979
## Parameter Estimates: 0.6824473 0.01091692 0.483752 0.07817851
##
## Objective Function Value: -285.7979
## Parameter Estimates: 0.6824473 0.01091866 0.4837508 0.07817851
##
## Objective Function Value: -285.7979
## Parameter Estimates: 0.6824473 0.01091866 0.483752 0.07817782
##
## Objective Function Value: -287.2965
## Parameter Estimates: 0.59149 0.1966023 0.49412 -0.02108801
##
## Objective Function Value: -285.2951
## Parameter Estimates: 0.6555089 0.03127846 0.5034544 0.0314321
##
## Objective Function Value: -285.2951
## Parameter Estimates: 0.6555117 0.03127846 0.5034544 0.0314321
##
## Objective Function Value: -285.2951
## Parameter Estimates: 0.6555089 0.03128035 0.5034544 0.0314321
##
## Objective Function Value: -285.2951
## Parameter Estimates: 0.6555089 0.03127846 0.5034532 0.0314321
##
## Objective Function Value: -285.2951
## Parameter Estimates: 0.6555089 0.03127846 0.5034544 0.03143281
##
## Objective Function Value: -285.1094
## Parameter Estimates: 0.6104137 -0.003343048 0.4964297 0.05221766
##
## Objective Function Value: -285.1094
## Parameter Estimates: 0.6104163 -0.003343048 0.4964297 0.05221766
##
## Objective Function Value: -285.1094
## Parameter Estimates: 0.6104137 -0.003345478 0.4964297 0.05221766
##
## Objective Function Value: -285.1094
## Parameter Estimates: 0.6104137 -0.003343048 0.4964284 0.05221766
##
## Objective Function Value: -285.1094
## Parameter Estimates: 0.6104137 -0.003343048 0.4964297 0.05221701
##
## Objective Function Value: -285.1888
## Parameter Estimates: 0.5664489 0.0351421 0.4821455 0.06199355
##
## Objective Function Value: -285.121
## Parameter Estimates: 0.5991426 0.01065102 0.4883985 0.06381709
##
## Objective Function Value: -285.0891
## Parameter Estimates: 0.6059244 0.002767344 0.4926629 0.05801976
##
## Objective Function Value: -285.0891
## Parameter Estimates: 0.6059267 0.002767344 0.4926629 0.05801976
##
## Objective Function Value: -285.0891
## Parameter Estimates: 0.6059244 0.002764818 0.4926629 0.05801976
##
## Objective Function Value: -285.0891
## Parameter Estimates: 0.6059244 0.002767344 0.492664 0.05801976
##
## Objective Function Value: -285.0891
## Parameter Estimates: 0.6059244 0.002767344 0.4926629 0.05801902
##
## Objective Function Value: -285.0722
## Parameter Estimates: 0.5994258 0.003560272 0.4907978 0.05033835
##
## Objective Function Value: -285.0722
## Parameter Estimates: 0.5994286 0.003560272 0.4907978 0.05033835
##
## Objective Function Value: -285.0722
## Parameter Estimates: 0.5994258 0.003562666 0.4907978 0.05033835
##
## Objective Function Value: -285.0722
## Parameter Estimates: 0.5994258 0.003557877 0.4907978 0.05033835
##
## Objective Function Value: -285.0722
## Parameter Estimates: 0.5994258 0.003560272 0.490799 0.05033835
##
## Objective Function Value: -285.0722
## Parameter Estimates: 0.5994258 0.003560272 0.4907978 0.05033897
##
## Objective Function Value: -285.0452
## Parameter Estimates: 0.5828702 0.01530932 0.4892436 0.05295173
##
## Objective Function Value: -285.0452
## Parameter Estimates: 0.582873 0.01530932 0.4892436 0.05295173
##
## Objective Function Value: -285.0452
## Parameter Estimates: 0.5828702 0.01530786 0.4892436 0.05295173
##
## Objective Function Value: -285.0452
## Parameter Estimates: 0.5828702 0.01530932 0.4892448 0.05295173
##
## Objective Function Value: -285.0452
## Parameter Estimates: 0.5828702 0.01530932 0.4892436 0.05295113
##
## Objective Function Value: -285.0248
## Parameter Estimates: 0.5646188 0.01561074 0.4814847 0.04766323
##
## Objective Function Value: -285.0248
## Parameter Estimates: 0.5646211 0.01561074 0.4814847 0.04766323
##
## Objective Function Value: -285.0248
## Parameter Estimates: 0.5646188 0.01561186 0.4814847 0.04766323
##
## Objective Function Value: -285.0248
## Parameter Estimates: 0.5646188 0.01561074 0.4814858 0.04766323
##
## Objective Function Value: -285.0248
## Parameter Estimates: 0.5646188 0.01561074 0.4814847 0.04766403
##
## Objective Function Value: -285.0302
## Parameter Estimates: 0.5553835 0.003094527 0.4712321 0.05628355
##
## Objective Function Value: -285.0188
## Parameter Estimates: 0.5609575 0.01126437 0.4781187 0.05291812
##
## Objective Function Value: -285.0188
## Parameter Estimates: 0.5609597 0.01126437 0.4781187 0.05291812
##
## Objective Function Value: -285.0188
## Parameter Estimates: 0.5609575 0.01126563 0.4781187 0.05291812
##
## Objective Function Value: -285.0188
## Parameter Estimates: 0.5609575 0.01126437 0.4781254 0.05291812
##
## Objective Function Value: -285.0188
## Parameter Estimates: 0.5609575 0.01126437 0.478112 0.05291812
##
## Objective Function Value: -285.0188
## Parameter Estimates: 0.5609575 0.01126437 0.4781187 0.05291747
##
## Objective Function Value: -285.0149
## Parameter Estimates: 0.55272 0.009543356 0.4783007 0.05354181
##
## Objective Function Value: -285.0149
## Parameter Estimates: 0.5527223 0.009543356 0.4783007 0.05354181
##
## Objective Function Value: -285.0149
## Parameter Estimates: 0.55272 0.009544774 0.4783007 0.05354181
##
## Objective Function Value: -285.0149
## Parameter Estimates: 0.55272 0.009543356 0.4782997 0.05354181
##
## Objective Function Value: -285.0149
## Parameter Estimates: 0.55272 0.009543356 0.4783007 0.05354248
##
## Objective Function Value: -285.0161
## Parameter Estimates: 0.5466873 0.0046274 0.4750511 0.05319602
##
## Objective Function Value: -285.0145
## Parameter Estimates: 0.5507271 0.007583788 0.4770664 0.05279766
##
## Objective Function Value: -285.0145
## Parameter Estimates: 0.550729 0.007583788 0.4770664 0.05279766
##
## Objective Function Value: -285.0145
## Parameter Estimates: 0.5507271 0.007585379 0.4770664 0.05279766
##
## Objective Function Value: -285.0145
## Parameter Estimates: 0.5507271 0.007583788 0.4770672 0.05279766
##
## Objective Function Value: -285.0145
## Parameter Estimates: 0.5507271 0.007583788 0.4770664 0.05279835
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5491307 0.007858598 0.4769614 0.0533762
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5491325 0.007858598 0.4769614 0.0533762
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5491307 0.007857474 0.4769614 0.0533762
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5491307 0.007858598 0.4769606 0.0533762
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5491307 0.007858598 0.4769614 0.0533756
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493534 0.007825858 0.4770748 0.05336085
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493735 0.007825858 0.4770748 0.05336085
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493333 0.007825858 0.4770748 0.05336085
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493534 0.007832091 0.4770748 0.05336085
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493534 0.007819626 0.4770748 0.05336085
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493534 0.007825858 0.4770777 0.05336085
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493534 0.007825858 0.477072 0.05336085
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493534 0.007825858 0.4770748 0.05336476
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493534 0.007825858 0.4770748 0.05335694
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.549323 0.007842421 0.4770554 0.0533536
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493625 0.007842421 0.4770554 0.0533536
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5492835 0.007842421 0.4770554 0.0533536
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.549323 0.007860394 0.4770554 0.0533536
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.549323 0.007824448 0.4770554 0.0533536
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.549323 0.007842421 0.477063 0.0533536
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.549323 0.007842421 0.4770477 0.0533536
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.549323 0.007842421 0.4770554 0.05336473
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.549323 0.007842421 0.4770554 0.05334247
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493229 0.007839368 0.4770548 0.05335546
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493642 0.007839368 0.4770548 0.05335546
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5492816 0.007839368 0.4770548 0.05335546
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493229 0.007862987 0.4770548 0.05335546
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493229 0.007815749 0.4770548 0.05335546
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493229 0.007839368 0.4770709 0.05335546
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493229 0.007839368 0.4770387 0.05335546
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493229 0.007839368 0.4770548 0.05336815
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493229 0.007839368 0.4770548 0.05334277
##
## Objective Function Value: -285.0142
## Parameter Estimates: 0.5493229 0.007839368 0.4770548 0.05335546
##
## Objective Function Value: 629.6254
## Parameter Estimates: 21.00822 0.2998076 0.01247403 0.001395138
## Warning in sqrt(diag(fit$cvar)): NaNs produced

fit
##
## Title:
## Normal Inverse Gaussian Parameter Estimation
##
## Call:
## .nigFit.mle(x = x, alpha = alpha, beta = beta, delta = delta,
## mu = mu, scale = scale, doplot = doplot, span = span, trace = trace,
## title = title, description = description)
##
## Model:
## Normal Inverse Gaussian Distribution
##
## Estimated Parameter(s):
## alpha beta delta mu
## 21.008221585 0.299807615 0.012474026 0.001395138
##
## Description:
## Thu Dec 13 12:34:24 2018 by user: ssiamina
# Output from fit
alpha <- 21.00822
beta <- 0.29981
delta <- 0.01247
mu <- 0.001395
# Calculate mean, variance, skewness, and kurtosis of d
mean <- mu + (delta * (beta / alpha)) / ((1 - (beta/alpha)^2)^(1/2))
var <- (delta^2 * alpha^(-1) )/((1 -(beta/alpha)^2 )^(3/2))
skew <- (3 * alpha ^(-1/4) *beta )/ (alpha * (1-(beta/alpha)^2 )^(1/4))
kurt <- (3 * alpha ^(-1/2) * (1 + 4 * (beta/alpha)^2) ) / ((1 - (beta/alpha)^2)^(1/2))
# calculate value at risk at 99 percentile (1%), and t=1,5, and 10 days
VaR <- qnorm (0.99)*sqrt(var)*sqrt(1)
VaR
## [1] 0.006330133
VaR <- qnorm (0.99)*sqrt(var)*sqrt(5)
VaR
## [1] 0.01415461
VaR <- qnorm (0.99)*sqrt(var)*sqrt(10)
VaR
## [1] 0.02001764