Wednesday, 13 February 2013

ITBAL Assignment 6


Assignment 1: Create the log return series and calculate historical voltility


> stockprice <- read.csv(file.choose(),header=T)
> closingprice <- stockprice[,5]
> closingprice.ts <- ts(closingprice , deltat=1/252)
> log.diff <- log(closingprice.ts , base=exp(1)) - log(lag(closingprice.ts,k=-1), base = exp(1))
> log.returns <- log.diff/log(lag(closingprice.ts,k=-1), base = exp(1))
> log.returns

Time Series:
Start = c(1, 2) 
End = c(2, 22) 
Frequency = 252 
  [1]  3.239464e-03 -3.884187e-04  7.460649e-06  1.031566e-04 -1.790094e-04 -1.020756e-04  2.629635e-03  2.766672e-04 -7.219539e-04  8.448814e-04  1.910705e-04
 [12]  2.235372e-03 -2.723447e-04  1.475328e-03  7.041325e-04 -5.460200e-05  1.869905e-03  7.045035e-04  1.047569e-03 -2.666119e-03  2.550488e-03  8.164967e-04
 [23]  7.603225e-04  1.232348e-03  7.807907e-04 -5.770056e-04  7.185143e-04  9.547984e-04 -6.627921e-04  1.858701e-04  5.568074e-04  2.462872e-03 -2.099390e-04
 [34]  8.866876e-04  8.895253e-04 -2.122643e-03 -4.659254e-04 -1.149537e-03 -3.216077e-03  2.064680e-03  2.098882e-04 -9.865220e-04  4.268778e-04  1.086513e-06
 [45] -1.730561e-03 -1.287406e-03 -4.362502e-05  2.503809e-03  5.666613e-04  1.510141e-03  7.344260e-04 -1.787318e-03 -1.362292e-03 -1.341494e-03  3.945467e-04
 [56]  1.976128e-03 -3.001079e-03  1.106098e-03 -2.095349e-03  1.320797e-03 -1.082815e-03 -3.583088e-04  2.605582e-03  4.911754e-04  8.865537e-04 -7.763192e-04
 [67] -1.954136e-03  2.050752e-04 -3.735635e-04  1.112008e-03 -1.544616e-03  4.199823e-04  1.410639e-03  2.268949e-04  7.107020e-04 -9.115485e-04 -2.006700e-03
 [78]  4.944683e-04 -4.627824e-04 -2.924186e-04  3.604002e-05  4.136487e-04  8.749252e-04 -2.003778e-04 -1.136619e-03 -2.310752e-03  6.271584e-04 -2.644486e-03
 [89] -5.920671e-04 -2.150921e-04 -8.740499e-04 -5.045429e-04  8.361626e-04 -2.028488e-03  2.894189e-04  5.127588e-04  3.508262e-04 -1.097620e-03 -6.038190e-04
[100]  2.071895e-03 -2.390384e-05  1.549669e-03  1.047839e-04 -9.297326e-04 -6.308823e-04 -1.990929e-03  1.593334e-04  3.676528e-04  3.196962e-03  1.228327e-03
[111]  4.334883e-04 -3.300435e-04  1.425141e-03  1.269615e-04 -1.534822e-03  1.939456e-03 -1.715955e-03  9.131466e-04  3.826181e-04  1.011969e-03 -4.299203e-04
[122] -7.161795e-04  1.407172e-04  4.814369e-04  1.648873e-04  2.911816e-03 -6.630323e-06  2.064695e-04  3.216062e-04  5.429964e-04 -2.266406e-04 -9.200411e-04
[133]  1.542443e-03 -8.541758e-04 -1.571732e-03 -1.785871e-04 -6.722646e-04 -9.899153e-05  5.266673e-04  5.897855e-04 -8.404042e-04 -1.973141e-03  2.342661e-04
[144] -4.253547e-04 -1.536500e-03  1.314838e-03  2.273528e-03  6.544701e-04  2.565831e-04 -2.844336e-04 -2.695327e-04  1.487906e-03  1.189729e-03  2.837990e-05
[155] -3.289665e-04 -5.584902e-05  6.009196e-04  7.046999e-04 -3.770709e-04  7.271941e-05  1.180923e-03 -1.749869e-04  5.371437e-05 -6.170252e-04 -7.902596e-04
[166] -3.412252e-04 -1.026760e-03  5.995619e-04 -1.246938e-03 -1.054797e-04  4.490623e-04 -1.073482e-03  2.835242e-04  2.289030e-03  3.614632e-04  1.031874e-04
[177]  5.750264e-04  8.819401e-04  9.309863e-05  3.004835e-03  6.703951e-04 -2.056453e-04 -9.515204e-04  2.823943e-03 -4.387549e-04  8.771891e-05 -2.132743e-04
[188] -2.853809e-04  1.097066e-03  3.138052e-04  2.513622e-04  1.130621e-03 -8.135789e-04 -1.435064e-03  5.814561e-04 -1.067965e-03  1.139085e-03 -6.499572e-04
[199]  2.280491e-04 -8.009879e-04  2.507867e-04  1.188888e-03 -6.984126e-04  6.675458e-04 -5.217950e-04  2.821077e-04 -8.338676e-04  2.655438e-05 -1.391002e-03
[210]  4.503694e-04  5.212828e-04  1.074665e-03  1.318438e-04  4.087192e-04  7.185322e-04 -4.288652e-04 -1.061865e-03 -5.188074e-05 -3.413826e-04 -7.363699e-04
[221] -1.177061e-03 -5.512835e-05  3.121345e-06  8.964977e-04  2.668488e-04 -2.366583e-05  1.912506e-04  1.865662e-03  1.951756e-03  1.081009e-03 -1.745294e-04
[232]  3.586398e-04  2.198437e-04  5.918464e-04 -4.569753e-04  2.923626e-05 -1.969952e-04 -2.110634e-04 -7.163435e-04  5.522762e-04 -4.260227e-04  7.629091e-04
[243]  6.388874e-04 -2.565234e-04 -1.344742e-03  1.585997e-04  9.771520e-04 -6.943370e-04  7.484690e-04 -6.335935e-05  8.887682e-04  8.168833e-04  3.112892e-04
[254]  1.271069e-04 -5.312741e-04  2.550707e-04 -5.798537e-04 -5.490448e-05 -3.348281e-04  1.397952e-03  6.191517e-04 -1.042707e-03  7.130947e-04  4.782958e-04
[265]  3.383743e-04 -6.395637e-04  1.100716e-04 -6.648065e-04  1.050830e-03  2.834345e-06 -4.714611e-04  1.109914e-04 -3.988862e-04

> T = (252)^0.5
> historical.volatility <- sd(log.returns) *T
> historical.volatility
[1] 0.01719952


Assignment 2: Create acf plot and interpret the results for log returns data and do an adf test





The two dotted lines represent the confidence interval of 95%. This is a visual tool to interpret the stationarity of time series. Autocorrelation calculates the correlation between different time steps/lags within the same variable. Since the correlation measurements lie within the confidence interval and there is apparent pattern in the correlation we can say that time series is stationary. 


> adf.test(log.returns)

        Augmented Dickey-Fuller Test

data:  log.returns 
Dickey-Fuller = -5.6217, Lag order = 6, p-value = 0.01
alternative hypothesis: stationary 

Interpretation: Since the p value obtained in ADF test is 0.01 which is less than alpha . The default value of alpha is 0.05. So we are going to reject the null hypothesis and accept the alternate hypothesis. Here the alternate hypothesis is that the time series is stationary. Hence by looking at p value we can say that time series is stationary.



No comments:

Post a Comment