Wednesday, 13 February 2013

IT and Business Applications Lab - Day6 Assignments



Assignment 1: Create a log of returns data and calculate its historical volatility. Create ACF plot for log returns, do ADF test and analyse it.


We have the formula, (log St - log St-1 )/ log St-1


Commands:

data<-read.csv(file.choose(),header=T)
close<-data$Close
close.ts<-ts(close,frequency=252)
closeshift.ts<-lag(close.ts,k=-1)
numerator<-log(close.ts)-log(closeshift.ts)
numerator
returns<-numerator/log(closeshift.ts)
plot(returns,main="Log Returns;NIFTY 1 Jan 2012 to 31 Jan 2013")
acf(returns,main="Auto Correlation Function on log returns")
adf.test(returns)
T<-252^0.5
histvol<-sd(returns)/T
histvol

Plots :

1. Values




2. log returns:

3. ACF plot of log returns



Autocorrelation computes the correlation between different time steps(lags) within the same variable. Since the correlation measurements lie within the confidence interval of 95% (the 2 dotted lines) and pattern exists in the correlation, time series is stationary.


Asgmt 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)

ADF test and Historical Volatility:


Confidence interval = 95%
implies, Alpha = 0.05
p-value obtained after ADF test = 0.01 which is < alpha
Hence, we reject the null hypothesis.



No comments:

Post a Comment