# (2) Histogram of 4 years
year <- 2015:2018
simon <- function(data){
for (j in 1:4) {
y <- year[j]
data2 <- subset(data,Year== y)
hist(data2[,5],main = paste("Histogram of",y, colnames(data)[5]), xlab = "Returns",ylab = "Density")
}
}
par(mfrow=c(2,2))
simon(BA)
par(mfrow=c(2,2))
simon(KR)
# Multivariate analysis #
# (1) Scatter plot for the relationship between BA and KR Return in 4 years
par(mfrow=c(2,2))
plot(x=BA$BA_Return[BA$Year==2015], y= KR$KR_Return[KR$Year==2015],
main = "Relationship between BA and KR Return in 2015 ",
xlab = "Return for BA", ylab = "Return for KR", pch="·")
plot(x=BA$BA_Return[BA$Year==2016], y= KR$KR_Return[KR$Year==2016],
main = "Relationship between BA and KR Return in 2016 ",
xlab = "Return for BA", ylab = "Return for KR", pch="·")
plot(x=BA$BA_Return[BA$Year==2017], y= KR$KR_Return[KR$Year==2017],
main = "Relationship between BA and KR Return in 2017 ",
xlab = "Return for BA", ylab = "Return for KR", pch="·")
plot(x=BA$BA_Return[BA$Year==2018], y= KR$KR_Return[KR$Year==2018],
main = "Relationship between BA and KR Return in 2018 ",
xlab = "Return for BA", ylab = "Return for KR", pch="·")
par(mfrow=c(2,1))
# Timeseries Plot for BA Price from 2015 to 2018
purchase.PBA <- ts(keydata$BA, start = c(2015,1,5), frequency = 252)
ts.plot(purchase.PBA, col = "red", ylab = 'BA price', xlab = 'Date', main = 'Timeseries Plot for BA Price')
# Timeseries Plot for BA Return (Absolute Value) from 2015 to 2018
purchase.RBA <- ts(abs(diff(keydata$BA)), start = c(2015,1,5), frequency = 252)
ts.plot(purchase.RBA, col = "black", ylab = 'BA return', xlab = 'Date', main = 'Timeseries Plot for BA Return (Absolute Value)')
### Problem 3. Linear Regression for KR ###
t <- nrow(KR)
kr_0 <- KR[1:t-1,5]
kr_1 <- KR[2:t,5]
liner_model <- data.frame(kr_0,y=kr_1)
cor(y=liner_model$y,x=liner_model)
model <- lm(y~.,data = liner_model)
cor(y=liner_model$y,x=liner_model)
summary(model)
# plot for liner model and using two transformation methods
par(mfrow=c(1,3))
plot(kr_0,y=kr_1, main = "Returns of KR on a given day and a previous trading day",
abline(lm(kr_0~kr_1),col = "red", lty=5),cex.lab= 1.3, cex = 1.3,pch = "·",
xlab = "Returns of KR on the previous trading day",ylab = "Returns of KR on a given day")
plot(log(kr_0),y=kr_1, main = "Returns of KR on a given day and a previous trading day",
abline(lm(kr_0~kr_1),col = "red", lty=5),cex.lab= 1.3, cex = 1.3,pch = "·",
xlab = "log(Returns of KR on the previous trading day)",ylab = "Returns of KR on a given day")
plot(sqrt(kr_0),y=kr_1, main = "Returns of KR on a given day and a previous trading day",
abline(lm(kr_0~kr_1),col = "red", lty=5),cex.lab= 1.3, cex = 1.3,pch = "·",
xlab = "sqrt(Returns of KR on the previous trading day)",ylab = "Returns of KR on a given day")