The class on 12-February focussed on how to create historical volatility of a data and the Auto Correlated plot (ACF) of the data.
Assignment 1: create log of returns data (from 01.01.2012 to 01.01.2013) and calculate historical volatility
Syntax:
> stockprice<-read.csv(file.choose(),header=T)
> head(stockprice)
> closingprice<-stockprice[,5]
> closingprice.ts<-ts(closingprice,frequency=252)
> returns<-(closingprice.ts-lag(closingprice.ts,k=-1))/lag(closingprice.ts,k=-1)
> z<-scale(returns)+10
> logreturns<-log(z)
> logreturns
> acf(logreturns)
From the above graph, we can see that the measurements lie with in the 95% confidence interval. Therefore, the time series is stationary.
Assignment 2: Create ACF plot for the log returns data ,perform adf test and interpret.
Syntax:
T=252^0.5
> historicalvolatility<-sd(logreturns)*T
> historicalvolatility
> adf.test(logreturns)
From the test results, we can see that p-value=0.01 (<0.05).
Therefore, we reject the null hypothesis and accept the alternate hypothesis which states that the time series is stationary.
Assignment 1: create log of returns data (from 01.01.2012 to 01.01.2013) and calculate historical volatility
Syntax:
> stockprice<-read.csv(file.choose(),header=T)
> head(stockprice)
> closingprice<-stockprice[,5]
> closingprice.ts<-ts(closingprice,frequency=252)
> returns<-(closingprice.ts-lag(closingprice.ts,k=-1))/lag(closingprice.ts,k=-1)
> z<-scale(returns)+10
> logreturns<-log(z)
> logreturns
> acf(logreturns)
From the above graph, we can see that the measurements lie with in the 95% confidence interval. Therefore, the time series is stationary.
Assignment 2: Create ACF plot for the log returns data ,perform adf test and interpret.
Syntax:
T=252^0.5
> historicalvolatility<-sd(logreturns)*T
> historicalvolatility
> adf.test(logreturns)
From the test results, we can see that p-value=0.01 (<0.05).
Therefore, we reject the null hypothesis and accept the alternate hypothesis which states that the time series is stationary.
No comments:
Post a Comment