
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")
priceGOOG=da[,6]
#answer A
par(mfrow=c(2,1))
plot(priceGOOG,type="l")
logpriceGOOG=log(priceGOOG)
logreturnGOOG=diff(log(priceGOOG))
plot(logreturnGOOG,type="l")
#answer B
table.Stats(logreturnGOOG)
#answer C
newlogreturnGOOG <-logreturnGOOG[2:nrow(logreturnGOOG),]
qqnorm(newlogreturnGOOG)
qqline(newlogreturnGOOG, col= 2)
jarque.bera.test(newlogreturnGOOG)
#since calculated p-value is less than an alpha, so the daily log return of GOOG is not normally distributed
#answer D
#test GOOG newlogreturn mean = 0.08
t.test(newlogreturnGOOG)
#since t = 2.8957 > 1.96 we reject that the mean is 0.08 with 95% CI
#answer E
table.Stats(newlogreturnGOOG)
t.test(logreturnGOOG, conf.level=0.95)
#answer F
TGOOG=length(newlogreturnGOOG)
s3GOOG=skewness(newlogreturnGOOG)
tst1 = s3GOOG/sqrt(6/TGOOG)
tst1
pv1 = 2*pnorm(tst1)
pv1
#answer H
k4GOOG = kurtosis(newlogreturnGOOG)
tst4 = k4GOOG/sqrt(24/TGOOG)
tst4
pv4 = 2*(1-pnorm(tst4))
pv4
