Thursday, 14 February 2013

IT Lab - 6


Stationary Time Series
#Assignment-1 Create log of the return data( way 1- log (st-st-1)/(st-1)
> #Historical volatility calculate.
> #Create acf plot for log(returns ) data and adf and interpret. NSE nifty index(from jan2012 to 31 jan 2013)
Program:
> z<-read.csv(file.choose(),header=T)
> closingprice<-z$Close
> closingprice.ts<-ts(closingprice,frequency=252)
> laggingtable<-cbind(closingprice.ts,lag(closingprice.ts,k=-1),closingprice.ts-lag(closingprice.ts,k=-1))
> Return<-(closingprice.ts-lag(closingprice.ts,k=-1))/lag(closingprice.ts,k=-1)
> Manipulate<-scale(Return)+10
> logreturn<-log(Manipulate)

> acf(logreturn)




From the figure it implies that the all the standard errors are within the 95% confidence interval and hence we can
say that the time series is stationary.
>T<-252^.5
>Historicalvolatility<-sd(Return)*T
> Historicalvolatility
[1] 0.1475815
> adf.test(logreturn)

        Augmented Dickey-Fuller Test

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

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

Since p-value is less than (1-.95) ,therefore we can say null hypothesis is rejected and hence the time series is stationary so data analysis can be done.

Thursday, 7 February 2013

IT lab Session 5


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.

Commands:


  z<-read.csv(file.choose(),header=T)
 Close<-z$Close
 Close
 Close.ts<-ts(Close)
 Close.ts<-ts(Close,deltat= 1/252)
 Interval<-ts(data=Close.ts[10:95],frequency=1,deltat=1/252)
 z1.ts<-ts(Interval)
 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

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

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