Stationary Time Series
Q. Use NSE Nifty Index (Feb 6, 2012 to Feb 6, 2013)
a. Create log of the return data.
b. Calculate Historical volatility.
c. Analyse Stationarity by-
1. Create Auto Correlation Function Plot.
2. Augmented Dickey Fuller Test.
Solution:
>
nse1yr<-read.csv(file.choose(),header=T)
>
closingprice<-nse1yr$Close
>
closingprice.ts<-ts(closingprice,frequency=252)
>
laggingtable<-cbind(closingprice.ts,lag(closingprice.ts,k=-1)
+
,closingprice.ts-lag(closingprice.ts,k=-1))
>
Return<-(closingprice.ts-lag(closingprice.ts,k=-1))/lag(closingprice.ts,k=-1)
>
head(Return)
[1]
-0.004942508 0.006185393 0.008233749 -0.005681451 0.001598038
[6] 0.004795740
>
Return.Std<-scale(Return)+10
>
logreturn<-log(Return.Std)
>
acf(logreturn)
From the
figure it implies that the all the standard errors are within the 95%
confidence interval and hence we can say that the time series is stationary.
>
T<-252^.5
>
Historicalvolatility<-sd(Return)*T
>
Historicalvolatility
[1]
0.1424954
>
adf.test(logreturn)
Augmented Dickey-Fuller Test
data: logreturn
Dickey-Fuller
= -6.2635, Lag order = 6, p-value = 0.01
alternative
hypothesis: stationary
Warning
message:
In
adf.test(logreturn) : p-value smaller than printed p-value
Since
p-value is less than 0.05 ,therefore we can say null hypothesis is rejected
and unit root is not 1 hence the time series is stationary so data analysis can be done.

No comments:
Post a Comment