Wednesday, 13 February 2013

Session 6


Assignment 1 - 

Download data for NIFTY index from 1st Jan , 2012 to 31st Jan 2013.. 
Calculate the log of returns data and find out the historical volatility.

Commands Used:

data<-read.csv(file.choose() , header=T)
closePrice<-data$Close
closePrice.ts<-ts(closePrice , frequenxy=252)
varLag<- lag(closePrice.ts , k=-1)
logClosePrice<- log(closePrice.ts , base=exp(1)) - log(varLag , base=exp(1))
LogReturns<-logClosePrice/log(varLag , base=exp(1)) 


To Calculate Historical Volatility:

> sqrt<-252^0.5
> historicalVol<-sd(LogReturns)*sqrt
> historicalVol
[1] 0.01719952

Assignment 2 :


To create an acf plot for the log returns data calculated previously. Also do and adf test and interpret the result

acf(LogReturns)

Grahical Interpretation
- As all the co-relations plots(vertical lines) lie inside confidence interval for the hypothesis (95% in default case)represented by two blue dotted lines , we can interpret that the returns data is "Stationary" in nature. This is visual inspection method for determining stationarity.




ADF Test


Command Used:
adf.test(LogReturns)

Output
     Augmented Dickey-Fuller Test

data:  LogReturns
Dickey-Fuller = -5.6217, Lag order = 6, p-value = 0.01
alternative hypothesis: stationary

Warning message:
In adf.test(LogReturns) : p-value smaller than printed p-value



Interpretation from ADF test
Null Hypothesis -: The returns data is not Stationary
Alternative Hypothesis -: Returns Data is stationary

As from the test results p-value = 0.01 which is less than 0.05 value as stated for 95%confidence interval.
Hence Null Hypothesis is rejected.

Results -: given data is stationary in nature


Thursday, 7 February 2013

Session5




ASSIGNMENT 1:
Find returns of NSE data of greater than 6 months having selected the 10th data point as start and 95th data point as end and plot  that return


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




ASSIGNMENT 2:
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)
> z.data<-z[1:700,1:9]
> z.data$ed<-factor(z.data$ed)
>logit.est<glm(default~age+employ+address+income+debtinc+creddebt+othdebt,data=z.data,family="binomial")
> summary(logit.est)
> confint.default(logit.est)
>logit.eg2<with(z[701:850,1:8],data.frame(age=age,employ=employ,address=address,income=income,debtinc=debtinc,creddebt=creddebt,othdebt=othdebt,ed=factor(1:3))
> logit.eg2$prob<-predict(logit.est,newdata=logit.eg2,type="response")
> head(logit.eg2)