Question :
(a) Create and plot the log of returns data for a 13 month period and interpret the stationarity.
(b) Calculate historical volatility of the same returns.
(c) Carry out adf test for returns and interpret the results.
> z<-read.csv(file.choose(),header=T)
> head(z)
Date Open High Low Close Shares.Traded Turnover..Rs..Cr.
1 01-Dec-2011 1937.80 1973.40 1930.25 1945.50 91246016 791.90
2 02-Dec-2011 1947.90 1981.05 1936.55 1977.85 90348679 781.31
3 05-Dec-2011 1975.55 1986.40 1968.60 1975.85 88981133 691.75
4 07-Dec-2011 1978.10 2001.85 1973.50 1978.45 99171329 872.43
5 08-Dec-2011 1976.25 1976.25 1928.65 1934.50 104371626 820.01
6 09-Dec-2011 1920.80 1932.10 1901.90 1919.00 90902176 659.08
> closeprice<-z$Close
> closeprice.ts<-ts(closeprice, frequency=252)
> returns<-(closeprice.ts-lag(closeprice.ts,k=-1))/lag(closeprice.ts,k=-1)
> manipulate<-scale(returns)+10
> logreturns<-log(manipulate)
> logreturns
> acf(logreturns)
We can see from the graph that almost all the errors lie between the two dotted lines i.e. between 95% confidence interval. Thus, we can conclude that the time interval is stationary.
> T=(252)^0.5
> historicalvolatility<-sd(logreturns)*T
Warning message:
sd(<matrix>) is deprecated.
Use apply(*, 2, sd) instead.
> historicalvolatility
[1] 1.620009
(a) Create and plot the log of returns data for a 13 month period and interpret the stationarity.
(b) Calculate historical volatility of the same returns.
(c) Carry out adf test for returns and interpret the results.
> z<-read.csv(file.choose(),header=T)
> head(z)
Date Open High Low Close Shares.Traded Turnover..Rs..Cr.
1 01-Dec-2011 1937.80 1973.40 1930.25 1945.50 91246016 791.90
2 02-Dec-2011 1947.90 1981.05 1936.55 1977.85 90348679 781.31
3 05-Dec-2011 1975.55 1986.40 1968.60 1975.85 88981133 691.75
4 07-Dec-2011 1978.10 2001.85 1973.50 1978.45 99171329 872.43
5 08-Dec-2011 1976.25 1976.25 1928.65 1934.50 104371626 820.01
6 09-Dec-2011 1920.80 1932.10 1901.90 1919.00 90902176 659.08
> closeprice<-z$Close
> closeprice.ts<-ts(closeprice, frequency=252)
> returns<-(closeprice.ts-lag(closeprice.ts,k=-1))/lag(closeprice.ts,k=-1)
> manipulate<-scale(returns)+10
> logreturns<-log(manipulate)
> logreturns
> acf(logreturns)
We can see from the graph that almost all the errors lie between the two dotted lines i.e. between 95% confidence interval. Thus, we can conclude that the time interval is stationary.
> T=(252)^0.5
> historicalvolatility<-sd(logreturns)*T
Warning message:
sd(<matrix>) is deprecated.
Use apply(*, 2, sd) instead.
> historicalvolatility
[1] 1.620009
> adf.test(logreturns)
Augmented Dickey-Fuller Test
data: logreturns
Dickey-Fuller = -5.2022, Lag order = 6, p-value = 0.01
alternative hypothesis: stationary
Warning message:
In adf.test(logreturns) : p-value smaller than printed p-value
Since p value is less that 0.5, we cannot accept the null hypothesis and so can conclude with 95% confidence that the time series is stationary and further analysis can be done


