Wednesday, 13 February 2013

ITBAL Session 6

Assignment 1:
Create log(returndata). There are two ways to do
a>[Log St -Log S(t-1)]/Log S(t-1)
b>Log[(St-S(t-1))/S(t-1)]

Take the log returns and calculate the historical data

Commands:
> stockprice=read.csv(file.choose(), header=T)
> head(stockprice)
> closingprice<-stockprice[,5]
> closingprice<-ts(closingprice,frequency=252)
> closingprice.ts<-ts(closingprice,frequency=252)
> lagtable<-cbind(closingprice.ts,lag(closingprice.ts,k=-1),(closingprice.ts-lag(closingprice.ts,k=-1)))
> head(lagtable)
> returns<-(closingprice.ts-lag(closingprice.ts,k=-1))/lag(closingprice.ts,k=-1)
> returns
> LogReturn1<-log(closingprice.ts)-log(lag(closingprice.ts,k=-1))
> LogReturn<-LogReturn1/log(lag(closingprice.ts,k=-1))
> LogReturn
> T<-252^0.5
> historicalvolatility<-sd(returns)*T
>  historicalvolatility
> acf(LogReturn)
> adf.test(returns)

        Augmented Dickey-Fuller Test

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

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


PIC 1:


PIC 2:



Assignment 2:
Create Acf plot and interpret the output of above log returns data. Do ADF test and interpret.

Commands:
> acf(LogReturn)
> adf.test(LogReturn)

        Augmented Dickey-Fuller Test

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

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

Conclusion:
From ADF test, P-value< alpha i.e 0.01<0.05. We reject the null hypothesis & accept the alternate hypothesis.  The above test justifies the stationary property of  time series. 


Thursday, 7 February 2013

ITBAL Session 4

ASSIGNMENT 1:

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

SOLUTION:
commands:
z<-read.csv(file.choose(),header=T)         
close<-z$Close                                       
close
close.ts<-ts(close)                                 
close.ts
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)
z1.diff
zlag<-lag(close.ts,k=-1)
returns<-cbind(z1.ts,z1.diff)
returns
returns<-z1.diff
plot(returns,main="returns from 10th to 95th data")
Pic1:
Pic2:


Pic3:
GRAPH PLOT:




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



SOLUTION:

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


PIC2