#Mini test 1
#6104640138 Jidapa C.
setwd("C:/R")
#install.packages("quantmod")  
#install.packages("fBasics") 
#install.packages("sn")  
#install.packages("PerformanceAnalytics") 
#install.packages("car") 
#install.packages("tseries")  
#install.packages("forecast") 
library(quantmod) 
library(fBasics)
library(sn)
library(PerformanceAnalytics)
library(car)
library(tseries)
library(forecast)

getSymbols("GOOG",from="2004-08-19",to="2021-01-01")
price = GOOG[,6]
logprice = log(price)
logreturn = diff(logprice)
simplereturn <- exp(logreturn)-1

#a) plot log return and simple return
par(mfrow=c(2,1))
plot(logreturn, type='l')
plot(simplereturn, type='l')

#b) 
table.Stats(logreturn)

#c)
newlogreturn = logreturn[2:nrow(logreturn)]
newsimplereturn = simplereturn[2:nrow(simplereturn)]
jarque.bera.test(newlogreturn)
#We reject the null hypothesis
## The log return does not have normal distribution according to JB test.


#d) Test mean =0.08
tstat = (mean(newlogreturn)-0.08)/var(newlogreturn)
pv_mean = pnorm(tstat)

#e) 95 percent CI of daily log return
t.test(newlogreturn)
# 95% CI is between 0.0002787253 and 0.0014474425

#f)
T=length(newlogreturn)
m3 = skewness(newlogreturn)
tst = m3/sqrt(6/T)
tst
pv=1-pnorm(tst)
pv
# We reject the null.
#the skewness of the log return is more than zero since the p-value falls in rejection region

#g)
K=kurtosis(newlogreturn)
K
tst_K = K/sqrt(24/T)
tst_K
# We reject the null.
# the excess kurtosis of the logreturn is not equal to zero since the calculated K* is higher than 1.96.

