Wednesday, 13 February 2013

Session#6 - Feb 12, 2013


Assignment 1: 
To create log returns data and calculate its historical volatility

Data Set: NSE Nifty Indices Data from 1st Jan 2012 to 31st Jan 2013
Working Column : Closing Price named Close
Used Formula: (logSt - logS(t-1))/logS(t-1)

Commands:
> stockprice <- read.csv(file.choose(),header=T)
> closingprice <- stockprice$Close
> closingprice.ts <- ts(closingprice , frequency=252)
> log.returns1 <- log(closingprice.ts , base=exp(1)) - log(lag(closingprice.ts,k=-1), base = exp(1))
> log.returns <- log.returns1/log(lag(closingprice.ts,k=-1), base = exp(1))
> log.returns
> T = (252)^0.5
> historical.volatility <- sd(log.returns) *T
> historical.volatility



Commands and Result

Assignment 2:

 To create acf plot and interpret the result for log returns data and do ADF test and interpret it. 

Command:
> acf(log.returns)

Graph Interpretation: The two dotted lines represent the confidence interval of 95%. This is a visual tool to interpret the stationarity of time series. Auto-correlation calculates the correlation between different time steps/lags within the same variable. Since the correlation measurements lie within the confidence interval and there is an apparent pattern in the correlation we can say that time series is stationary. 

ACF graph

Augmented Dickey-Fuller(ADF) Test
Command:
>adf.test(log.returns)

Interpretation: The p value obtained in ADF test is 0.01 which is less than alpha . The default value of alpha is 0.05. So we will reject the null hypothesis and accept the alternate hypothesis. Here the alternate hypothesis is that the time series is stationary. Hence by looking at p value it can be said that time series is stationary.


ADF Test Result





Thursday, 7 February 2013

BA Lab, Assignment for Feb 5,2013


R Statistical Tool Assignment-4

Assignment 1: 

Reading a particular data set and then converting it  into a time series format and then calculating the returns from it.Data set- CNX Mid-cap Index downloaded from NSE from August, 2012-January, 2013-10th reading to 95th reading. 

Commands:-
> z<-read.csv(file.choose(),header=T)
> Close<-z$Close
> Close
> Close.ts<-ts(Close)
> Close.ts<-ts(Close,deltat= 1/252)
z1<-ts(data=Close.ts[10:95],frequency=1,deltat=1/252) 
> z1.ts<-ts(z1)
> z1.ts
> z1.diff<-diff(z1)
> z2<-lag(Close.ts,K=-1)
> Returns<-z1.diff/z2
> plot(Returns,main=" Returns from 10 th to 95th day of NSE Mid-cap Index ")
z3<-cbind(z1.ts,z1.diff,Returns)
> plot(z3,main=" Data from 10th-95th day ; Difference ; Returns")




Assignment:-2

Question: 1-700 data is available, Predict the data from 701-850, use the GLM estimation using LOGIT Analysis for the same

commands:

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