Analysis of CO stock

China Corp Blood Corporation

setwd("\\\\vrisi01/users$/oadesanya/Documents")
install.packages("tseries", repos ="http://cran.rstudio.com/") #installing tseries package
## package 'tseries' successfully unpacked and MD5 sums checked
## 
## The downloaded binary packages are in
##  C:\Users\oadesanya\AppData\Local\Temp\Rtmp8aEhMp\downloaded_packages
library(tseries)
## Warning: package 'tseries' was built under R version 3.3.1

Import Data

COdata <- get.hist.quote('co',quote="Close")
## time series starts 2007-05-09
head(COdata)
##            Close
## 2007-05-09  5.50
## 2007-05-10  5.50
## 2007-05-11  5.50
## 2007-05-14  5.46
## 2007-05-15  5.46
## 2007-05-16  5.50

Calculating volatility using the number of work days multiply by 100 to get the percentage. 250 is the total number of days stock market is opened.

COret <- log(lag(COdata)) - log(COdata)
COvol <- sd(COret) * sqrt(250) * 100

Volatility

COvol
## [1] 49.78543

Function to calculate volatitlity with weight

Vol <- function(d, logrets)
{
  
  var = 0
  
  lam = 0
  
  varlist <- c()
  
  for (r in logrets) {
    
    lam = lam*(1 - 1/d) + 1
    
    var = (1 - 1/lam)*var + (1/lam)*r^2
    
    varlist <- c(varlist, var)
    
  }
  
  sqrt(varlist)
}

Decay Factor of .9

volest <- Vol(10,COret)

Decay Factor of .6

volest2 <- Vol(40,COret)

Decay Factor of .6

volest3 <- Vol(80,COret)

Plots including all three decay factors estimating the volatility.

There is a high volatility estimate change around the 600 index point .The estimate for the .2 decay factor (blue line) is smoother compared to the other two, the spike is not as sharp as the other decay factors.The plot shows that the volatility is fairly stable majority of the time except for some small spikes.

plot(volest,type="l") 
lines(volest2,type="l",col="red")  

lines(volest3, type = "l", col="blue")

legend("topright",legend = c(".9 decay factor", ".6 decay factor", ".2 decay factor"), 
       col = c( "black","red", "blue"), lty =1.2,cex =0.8)