Wednesday, 13 February 2013

ITBAL: SESSION 6

Assignment 1:
Create log of returns for NIFTY data from 01 Jan 2012 to 31 Jan 2013 and calculate the historical volatility


Solution:

z<-read.csv(file.choose(), header =T)
head(z)
closingprice<-z[,5]
closingprice.ts<-ts(closingprice, frequency =252)
st<-log(closingprice.ts)
stlag<-log(lag(closingprice.ts,k=-1))
log.returns<-(st-stlag)/stlag
plot(log.returns)
T =(252) ^ 0.5
historicalvolatility<-sd(returns) * T
historicalvolatility






Assignment 2:

Create ACF plot for the above log of returns data and perform the adf test and comment on it

The ACF plot can be done using the below formula

acf(log.returns)








  It can be seen from the plot that the data lies within the 95% confidence interval and there is maximum possibility of data being stationary.
The ADF test is done using :

adf.test(returns)
As the P value is less than the significant value(0.05) and we can reject the null hypothesis.

Hence as per the  alternate hypothesis data being stationary, analysis can be done.

Thursday, 7 February 2013

IT Lab Day5 Assignment


Assignment1

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.

2. Find plot of that return.




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 10th 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")

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