Wednesday, 13 February 2013

ITBAL-6 on Feb 12

Question 1:
Create a log of returns data and calculate its historical volatility. Create ACF plot for log returns, do ADF test and analyse it.

Formula used:
(log St - log St-1 )/ log St-1

Data set used:
NSE Nifty Indices from Jan 1 2012 to Jan 31 2013.

Commands:

data<-read.csv(file.choose(),header=T)
close<-data$Close
close.ts<-ts(close,frequency=252)
closeshift.ts<-lag(close.ts,k=-1)
numerator<-log(close.ts)-log(closeshift.ts)
numerator
returns<-numerator/log(closeshift.ts)
plot(returns,main="Log Returns;NIFTY 1 Jan 2012 to 31 Jan 2013")
acf(returns,main="Auto Correlation Function on log returns")
adf.test(returns)
T<-252^0.5
histvol<-sd(returns)/T
histvol


Return values:



Plot of log returns:


ACF Plot of log returns:

Autocorrelation calculates the correlation between different time steps/lags within the same variable. Since the correlation measurements lie within the confidence interval of 95% (the 2 dotted lines) and pattern exists in the correlation, time series is stationary.


ADF test and Historical Volatility:


Confidence interval = 95%
implies, Alpha = 0.05
After ADF test, obtained p-value = 0.01 which is < alpha
Hence, we REJECT the null hypothesis.

Thursday, 7 February 2013

ITBAL-5 on Jan 25

Question 1:

Command:

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(z1.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")





Question 2:

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

Command:

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 + debtinc + creddebt + othedebt, 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)