library(quantmod) 
library(fBasics)
library(sn)
library(PerformanceAnalytics)
library(car)
library(tseries)
library(forecast)

getSymbols("GOOG",from="2004-08-19",to="2021-01-01")
dim(GOOG)   
head(GOOG) 
tail(GOOG)
da=GOOG
chartSeries(GOOG,theme="white") 
price=da[,6]
plot(price,type='l')
logprice=log(price)
plot(logprice,type='l')
logreturn=diff(log(price))

#a)
par(mfrow=c(2,1))
plot(logreturn,type='l')
plot(price,type='l')

#b)
newlogreturn <- logreturn[2:nrow(logreturn),]
table.Stats(newlogreturn)

#c)
jarque.bera.test(newlogreturn)
par(mfrow=c(1,1))
hist(newlogreturn, breaks=100, col="slateblue")
chart.Histogram(newlogreturn,methods = c("add.normal"))

#d)
t.test(newlogreturn,mu=0.08)

#e)
#95 percent confidence interval:
#  0.0002787253 0.0014474425

#f)
T=length(newlogreturn)
m3=skewness(newlogreturn)
tst=m3/sqrt(6/T)
tst
pv = 2*(1-pnorm(tst))
pv

#g)
T=length(newlogreturn)
k4 = kurtosis(newlogreturn)
tst = k4/sqrt(24/T)  
tst
pv = 2*(1-pnorm(tst))
pv

