Create log of returns for NIFTY data from 01 Jan 2012 to 31 Jan 2013 and calculate the historical volatility
The command for determining the log of returns and historical volatility is as follows:
z<-read.csv(file.choose(), header =T)
head(z)
closingprice<-z[,5]
closingprice.ts<-ts(closingprice, frequency =252)
st<-log(closingprice.ts)
stlag<-log(lag(closingprice.ts,k=-1))
log.returns<-(st-stlag)/stlag
plot(log.returns)
T =(252) ^ 0.5
historicalvolatility<-sd(returns) * T
historicalvolatility
The plot for log of returns is as follows:
Assignment 2:
Create ACF plot for the above log of returns data and perform the adf test and comment on it
The ACF plot can be done using the below formula :
acf(log.returns)
The Plot is as follows:
The ADF test is performed using the below formula:
adf.test(returns)
The output is as follows:
It shows that the P value is less than the significant value(0.05) and we can reject the null hypothesis.
Since the alternate hypothesis is stated as data being stationary we can conclude that data is stationary and analysis can be done.



No comments:
Post a Comment