1. Pleae choose one stock data from Yahoo Finance website. 2. Please use RStudio
ID: 3853699 • Letter: 1
Question
1. Pleae choose one stock data from Yahoo Finance website.
2. Please use RStudio program for data analysis.
3. Please do (1) Polinomial equation modeling, (2)ARIMA modeling, (3)Model diagonatics, (4) GARCH modeling with your chosen stock data.
4. Please compare and intrepret of outputs of the four models.
use these r codes to get the data, please use RStudio to answer these questiones, and please provides the R code.
library(tseries)
library(TSA)
con <- url("https://finance.yahoo.com")
if(!inherits(try(open(con), silent = TRUE), "try-error")) {
close(con)
google <- get.hist.quote(instrument = "GOOG", start = "2004-08-19",
quote = "Close")
plot(google)
}
google
Explanation / Answer
data.loading <- function(tickers, start.date, end.date)
{
sl <- Sys.setlocale(locale="US")
all.dates <- seq(as.Date(start.date), as.Date(end.date), by="day")
all.dates <- subset(all.dates,weekdays(all.dates) != "Sunday" & weekdays(all.dates) != "Saturday")
all.dates.char <- as.matrix(as.character(all.dates))
open <- matrix(NA, NROW(all.dates.char), length(tickers))
hi <- open
low <- open
close <- open
volume <- open
adj.close <- open
rownames(open) <- all.dates.char
rownames(hi) <- all.dates.char
rownames(low) <- all.dates.char
rownames(close) <- all.dates.char
rownames(volume) <- all.dates.char
rownames(adj.close) <- all.dates.char
splt <- unlist(strsplit(start.date, "-"))
a <- as.character(as.numeric(splt[2])-1)
b <- splt[3]
c <- splt[1]
splt <- unlist(strsplit(end.date, "-"))
d <- as.character(as.numeric(splt[2])-1)
e <- splt[3]
f <- splt[1]
str1 <- "http://ichart.finance.yahoo.com/table.csv?s="
str3 <- paste("&a=", a, "&b=", b, "&c=", c, "&d=", d, "&e=", e, "&f=", f, "&g=d&ignore=.csv", sep="")
for (i in seq(1,length(tickers),1))
{
str2 <- tickers[i]
strx <- paste(str1,str2,str3,sep="")
x <- read.csv(strx)
datess <- as.matrix(x[1])
replacing <- match(datess, all.dates.char)
open[replacing,i] <- as.matrix(x[2])
hi[replacing,i] <- as.matrix(x[3])
low[replacing,i] <- as.matrix(x[4])
close[replacing,i] <- as.matrix(x[5])
volume[replacing,i] <- as.matrix(x[6])
adj.close[replacing,i] <- as.matrix(x[7])
}
colnames(open) <- tickers
colnames(hi) <- tickers
colnames(low) <- tickers
colnames(close) <- tickers
colnames(volume) <- tickers
colnames(adj.close) <- tickers
return(list(open=open, high=hi, low=low, close=close, volume=volume, adj.close=adj.close))
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.