Wednesday, 13 February 2013

IT LAB: Assignment 6

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.











Thursday, 7 February 2013

IT LAB : ASSIGNMENT 5


Assignment 1:


 The Data set is downloaded from  CNX Mid-cap Index downloaded from NSE from August 2012-January 2013. The data should be read in such a manner that start data is the 10th reading and the end data is the 95th reading. 

Syntax:

> z<-read.csv(file.choose(),header=T)
> close.ts<-z$Close
> close.ts
> close.time<-ts(close.ts)
> close.time<-ts(Close.ts[10:95],deltat= 1/252)
> z.diff<- diff(close.time) 
> returns<- cbind(close.time,z.diff,lag(close.time,k= -1))
> returns<- cbind(close.time,z.diff,lag(close.time,k= -1), z.diff/lag(close.time,k= -1))
> returns
> plot(returns)

>returns<- z.diff/lag(close.time,k= -1)
>plot(returns)




Assignment 2:


Predicting the new data by doing an estimation(regression) with already available data from 1-700.

Syntax:


> z<-read.csv(file.choose(),header=T)
> z1<-z[1:700,1:9]
> head(z1)
> z1$ed<-factor(z1$ed)
> z1.est<-glm(default ~ age + ed + employ + address + income, data=z1, family ="binomial")
> summary(z1.est)
> forecast<-z[701:850,1:8]
> forecast$ed<-factor(forecast$ed)
> forecast$probability<-predict(z1.est,newdata=forecast,type="response")
> head(forecast)