Wednesday, 13 February 2013

Interpreting the Historical Volatility of Market

#this post is created as a solution for assignments given on 13/02/2013 in IT & Business Applications Lab, Spring Semester, VGSoM, IIT Kharagpur Class of 2014.

Assignment #1: 1) create log of returns data (use Closing Price Nifty data, from 01.01.2012 to 01.01.2013) and calculate historical volatility.

 

 

Solution: Commands used are:
 readData<-read.csv(file.choose() , header=T)
closePrice<-readData[,5] // Reading Closing Price Column
closePrice.ts<-ts(closePrice , frequenxy=252)  // making a time series
varLag<- lag(closePrice.ts , k=-1) // calculating stock price for time (t-1)
logNum<- log(closePrice.ts , base=exp(1)) - log(varLag , base=exp(1)) // Calculating log
LogReturns<-logNum/log(varLag , base=exp(1)) // calculating log for returns data

Snapshot of commands and result is given below:



Now, we calculate Historical volatility as follows:
sqrt<-(252)^0.5
histVolaitility<-sd(logreturns)*sqrt

Snapshot of commands and result is given below:



Assignment #2 :create an ACF plot for the log returns data calculated previously and interpret the findings. Also do ADF test and interpret the findings.

Soln -:

// The following command is used to create ACF plot

acf(logReturns)

Snapshot of commands and result is given below:




Grahical Interpreation
-  the two horizontal dotted lines represent confidence interval for the hypothesis (95% in default case)
- As all the co-relations plots(vertical lines) lie inside those two blue dotted lines , it can be suggested that the returns data is "Stationary" in nature.

using ADF test

Command used
adf.test(logReturns)
we get the following result:


 
To interpret the result , we construct the Null Hypothesis,
Null Hypothesis -: The returns data is not Stationary
Alternative Hypothesis -: Returns Data is stationary

As from the test results p-value = 0.01 which is less than 0.05 value as stated for 95%confidence interval, Null Hypothesis is rejected.

Results -: given data is stationary in nature

Thursday, 7 February 2013

Exploring Returns and Logit

#this post is created as a solution for assignments given on 05/02/2013 in IT & Business Applications Lab, Spring Semester, VGSoM, IIT Kharagpur Class of 2014.

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.

Solution: 

Steps:

1. Extract the data (from 5/7/2011 to 7/2/2013) in a separate .csv file.
2. Find the Returns applying Time series and Lag
3. Draw the plot.

Commands used:
z<-read.csv(file.choose(),header=T)
Closedata<-z$Close
Close.ts<-ts(Closedata)
Close.ts<-ts(Closedata,deltat= 1/252)
znew<-ts(data=Close.ts[10:95],frequency=1,deltat=1/252)
znew.ts<-ts(znew)
znew.diff<-diff(znew)
zdenominator<-lag(znew.ts,K=-1)
Returndata<-znew.diff/zdenominator
plot(Returndata,main=" Returndata for 10 th to 95th day of NSE data downloaded ")


Snapshot of Result


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:

  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)