#sry krub ajarn I have no idea why I cannot compile it to pdf I tried it many ways but it still doesnt work
# EE435 Assignment 3
# by Jaruvit Chantana 6104641482
library(quantmod)
library(fBasics)
library(sn) 
library(PerformanceAnalytics)
library(car)
library(tseries) 
library(forecast)
library(data.table)
library(tinytex)
#question 1
#a
dagdp=read.table(file.choose(), header = T)
dagdp$Date = as.yearmon(paste(dagdp$year, dagdp$month), "%Y %m")
dagdp$logGDP <- log(dagdp$gdp)
dagdp = mutate(dagdp,logGDPgrowth = logGDP - lag(logGDP))
plot(dagdp$Date[133:264],dagdp$logGDPgrowth[133:264],xlab='month-year',ylab='GDPgrowth',type='l')
par(mfcol=c(2,2))
plot(growth[133:264])

#b
#H0: p1=p2=p3=...=p12 = 0 H1: pi at least one of them not equal to 0
Box.test(dagdp$logGDPgrowth[2:264],lag=12,type="Ljung")
#since p-value is less than 0.05, we reject the null hypothesis H0: p1=p2=p3=...=p12 = 0 with 95% CI

#c
t.test(dagdp$logGDPgrowth)
#since p value is less than 0.05 then we reject the null hypothesis H0 : µ = 0 with 95% CI


#question 2
#a
read.table(file.choose(), header = T)
data2=read.table(file.choose(), header = T)
table.Stats(data2$amzn)
table.Stats(data2$vwrtn) 
table.Stats(data2$ewrtn)
table.Stats(data2$sprtn)
#b
data2$logAMZN <- log(1+data2$amzn)
data2$logVW <- log(1+data2$vwrtn)
data2$logEW <- log(1+data2$ewrtn)
data2$logSP <- log(1+data2$sprtn)
table.Stats(data2$logAMZN)
table.Stats(data2$logVW) 
table.Stats(data2$logEW)
table.Stats(data2$logSP)
#c
t.test(data2$logAMZN)
#since p-value is greater than 0.05 so we cannot reject that means of log return of amzn is 0
#d
hist(data2$logAMZN,nclass=40)
chart.Histogram(data2$logAMZN,methods = c("add.normal"))

#question 3
#a
data3=read.table(file.choose(), header = T)
table.Stats(data3$RET)
table.Stats(data3$vwretd) 
table.Stats(data3$ewretd)
table.Stats(data3$sprtrn) 
#b
data3$logRET <- log(1+data3$RET)
data3$logVW <- log(1+data3$vwretd)
data3$logEW <- log(1+data3$ewretd)
data3$logSP <- log(1+data3$sprtrn)
table.Stats(data3$logAMZN)
table.Stats(data3$logVW) 
table.Stats(data3$logEW)
table.Stats(data3$logSP)
#c
t.test(data3$logRET)
#d
hist(data3$logRET,nclass=40)
chart.Histogram(data3$logRET,methods = c("add.normal"))

#question 4
#a
t.test(data3$vwretd)
#since p value is less than 0.05, we reject the null hypothesis or mean is not equal to 0 with 95% CI
#b
T=length(data3$vwretd)
S=skewness(data3$vwretd)
S
tst= S/sqrt(6/T)
tst
pv=2*pnorm(tst)
pv
#p value is less than 0.05 so we reject th null hypothesis or the skewness is not equal to 0 with 95% CI
#c
K=kurtosis(data3$vwretd)
K
tst1=K/sqrt(24/T)
tst1
pv1=2*(1-pnorm(tst1))
pv1

#question 5
#a
#i
T1=length(data2$logAMZN)
S1=skewness(data2$logAMZN)
tst2=S1/sqrt(6/T1)
tst2
pv2=2*pnorm(tst2)
pv2
#since p value is greater than 0.05 so we cannot reject the null hypothesis that this log return of amazon is symmetric with 95%CI
#ii
K1=kurtosis(data2$logAMZN)
tst3=K1/sqrt(24/T)
tst3
pv3=2*(1-pnorm(tst3))
pv3
#iii
t.test(data2$logAMZN)
#b
acf(data2$logAMZN, lag=12)
pacf(data2$logAMZN, lag.max=12)
Box.test(data2$logAMZN,lag=12,type='Ljung')
#since p-value is greater than 0.05 so we cannot reject the null hypothesis stating that H0 : ρ1 = ... = ρ12 = 0
#autocorrelation between these dataset equal to 0 meaning that there is no auto correlation

#question6
data3=read.table(file.choose(), header = T)
#a
data3$log1 <- log(data3$VALUE)
data3 = mutate(data3,logReturn = log1 - lag(log1))
#b
t.test(data3$logReturn)
#c
hist(data3$logReturn)
chart.Histogram(data3$logReturn,methods = c("add.normal"))
#d
t.test(data3$logReturn)
#since the p-value is greater than 0.05 so we cannot reject that mean of the daily log return of Dollar Euro exchange rate is equal to 0

rmarkdown::render("EE435assignment3.R")
rmarkdown::render("EE435assignment3.R", "pdf_document")
