#this post is created as a solution for assignments given on 13/02/2013 in IT & Business Applications Lab, Spring Semester, VGSoM, IIT Kharagpur Class of 2014.
Assignment #1: 1) create log of returns data (use Closing Price Nifty data, from 01.01.2012 to 01.01.2013) and calculate historical volatility.
Solution: Commands used are:
readData<-read.csv(file.choose() , header=T)
closePrice<-readData[,5] // Reading Closing Price Column
closePrice.ts<-ts(closePrice , frequenxy=252) // making a time series
varLag<- lag(closePrice.ts , k=-1) // calculating stock price for time (t-1)
logNum<- log(closePrice.ts , base=exp(1)) - log(varLag , base=exp(1)) // Calculating log
LogReturns<-logNum/log(varLag , base=exp(1)) // calculating log for returns data
closePrice<-readData[,5] // Reading Closing Price Column
closePrice.ts<-ts(closePrice , frequenxy=252) // making a time series
varLag<- lag(closePrice.ts , k=-1) // calculating stock price for time (t-1)
logNum<- log(closePrice.ts , base=exp(1)) - log(varLag , base=exp(1)) // Calculating log
LogReturns<-logNum/log(varLag , base=exp(1)) // calculating log for returns data
Snapshot of commands and result is given below:
Now, we calculate Historical volatility as follows:
sqrt<-(252)^0.5
histVolaitility<-sd(logreturns)*sqrt
sqrt<-(252)^0.5
histVolaitility<-sd(logreturns)*sqrt
Snapshot of commands and result is given below:
Assignment #2 :create an ACF plot for the log returns data calculated previously and interpret the findings. Also do ADF test and interpret the findings.
Soln -:
// The following command is used to create ACF plot
acf(logReturns)
// The following command is used to create ACF plot
acf(logReturns)
Snapshot of commands and result is given below:
Grahical Interpreation
- the two horizontal dotted lines represent confidence interval for the hypothesis (95% in default case)
- As all the co-relations plots(vertical lines) lie inside those two blue dotted lines , it can be suggested that the returns data is "Stationary" in nature.
using ADF test
Command used
adf.test(logReturns)
we get the following result:
To interpret the result , we construct the Null Hypothesis,
Null Hypothesis -: The returns data is not Stationary
Alternative Hypothesis -: Returns Data is stationary
As from the test results p-value = 0.01 which is less than 0.05 value as stated for 95%confidence interval, Null Hypothesis is rejected.
Results -: given data is stationary in nature






