Assignment 6
Assignment 1:
Create log(returndata). There are two ways to do
a>[Log St -Log S(t-1)]/Log S(t-1)
b>Log[(St-S(t-1))/S(t-1)]
Take the log returns and calculate the historical data
Commands:
> stockprice=read.csv(file.choose(), header=T)
> head(stockprice)
> closingprice<-stockprice[,5]
> closingprice<-ts(closingprice,frequency=252)
> closingprice.ts<-ts(closingprice,frequency=252)
> lagtable<-cbind(closingprice.ts,lag(closingprice.ts,k=-1),(closingprice.ts-lag(closingprice.ts,k=-1)))
> head(lagtable)
> returns<-(closingprice.ts-lag(closingprice.ts,k=-1))/lag(closingprice.ts,k=-1)
> returns
> LogReturn1<-log(closingprice.ts)-log(lag(closingprice.ts,k=-1))
> LogReturn<-LogReturn1/log(lag(closingprice.ts,k=-1))
> LogReturn
> T<-252^0.5
> historicalvolatility<-sd(returns)*T
> historicalvolatility
> acf(LogReturn)
> adf.test(returns)
Augmented Dickey-Fuller Test
data: returns
Dickey-Fuller = -5.6265, Lag order = 6, p-value = 0.01
alternative hypothesis: stationary
Warning message:
In adf.test(returns) : p-value smaller than printed p-value
PIC 1:
Assignment 2:
Create Acf plot and interpret the output of above log returns data. Do ADF test and interpret.
Commands:
> acf(LogReturn)
> adf.test(LogReturn)
Augmented Dickey-Fuller Test
data: LogReturn
Dickey-Fuller = -5.6217, Lag order = 6, p-value = 0.01
alternative hypothesis: stationary
Warning message:
In adf.test(LogReturn) : p-value smaller than printed p-value
> adf.test(LogReturn)
Augmented Dickey-Fuller Test
data: LogReturn
Dickey-Fuller = -5.6217, Lag order = 6, p-value = 0.01
alternative hypothesis: stationary
Warning message:
In adf.test(LogReturn) : p-value smaller than printed p-value
PLOT
Conclusion:
From ADF test, P-value< alpha i.e 0.01<0.05. We reject the null hypothesis and accept the alternate hypothesis. ACF plots the data within the confidence interval. The above test justifies the stationary property of time series.
From ADF test, P-value< alpha i.e 0.01<0.05. We reject the null hypothesis and accept the alternate hypothesis. ACF plots the data within the confidence interval. The above test justifies the stationary property of time series.



No comments:
Post a Comment