Wednesday, 13 February 2013

IT and Business Application lab : Assignment 6



Problem 1


1) Create log of returns data (from 01.01.2012 to 01.01.2013) and calculate historical volatility

2) Create ACF plot for the log returns data ,perform adf test and interpret.
Commands:

> stockprice<-read.csv(file.choose(),header=T)
> head(stockprice)
> closingprice<-stockprice[,5]
> closingprice.ts<-ts(closingprice,frequency=252)
> returns<-(closingprice.ts-lag(closingprice.ts,k=-1))/lag(closingprice.ts,k=-1)
> z<-scale(returns)+10
> logreturns<-log(z)
> logreturns

> acf(logreturns)
 
 


From the above graph, we can see that the measurements lie with in the 95% confidence interval. Therefore, the time series is stationary.

> T=252^0.5
> historicalvolatility<-sd(logreturns)*T
> historicalvolatility
> adf.test(logreturns)

 

From the test results, we can see that p-value=0.01 (<0.05).
Therefore, we reject the null hypothesis and accept the alternate hypothesis which states that the time series is stationary.


 

 
 

 

Thursday, 7 February 2013

IT and Business Application lab : Assignment 5


Problem I:
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

Solutions:
Commands:

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



Problem II
Do logit analysis for 700 data points and predict the probability for the next 150 data points.

Solutions:
Commands


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