Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Objective: Using the random forest and time series analysis in r, predict stock prices. You can use any one month of data between XXXXXXXXXXto predict stocks. Output: PowerPoint summary report...

1 answer below »
Objective: Using the random forest and time series analysis in r, predict stock prices. You can use any one month of data between XXXXXXXXXXto predict stocks.
Output: PowerPoint summary report generated from R output.
Data:
· Use the National Association of Securities Dealers Automated Quotations (NASDAQ) historical data for a period of five years: 6/2/2015 – 6/1/2020. Forecast using the closing value of the stock prices.
· When collecting the data, use the following uniform resource locator (URL) to obtain historical values from NASDAQ. Interchange the stock symbols for the stocks you are going to evaluate, like “FISV” in this example: o https:
www.nasdaq.com/api/v1/historical/FISV/stocks/ XXXXXXXXXX/ XXXXXXXXXXo Read the URL into R as a comma-separated value file, for each stock assigned.
· The stocks to evaluate are:
· SBUX; Sta
ucks Corporation
· DRI; Darden Restaurants, Inc.
· PZZA; Papa Johns International, Inc..
Answered Same Day Nov 28, 2021

Solution

Hemanth answered on Nov 29 2021
149 Votes
# Installing required packages
install.packages("dplyr")
install.packages("randomForest")
install.packages("forecast")
# Loading required packages
li
ary(dplyr)
li
ary(randomForest)
li
ary(forecast)
# ============ Sta
ucks Corporation =================
# Reading Sta
ucks Corporation dataset
SBUX <- read.csv("SBUX.csv", header = TRUE, sep = ",")
# Showing first SIX records
head(SBUX)
# Printing structure of the data
str(SBUX)
# Converting Date variable datatype
SBUX$Date <- as.Date(SBUX$Date, format = "%m/%d/%Y")
# Removing Special character(Dollor)s from "Close.Last" variable.
SBUX$Close.Last <- as.numeric(gsub("\\$", "", SBUX$Close.Last))
# Selecting data from march month 2019 stocks
period <- as.Date(c('03/01/2019','03/31/2019'),"%m/%d/%Y")
SBUX <- SBUX[SBUX$Date>=period[1] & SBUX$Date<=period[2],]
# Showing first & last SIX records of the data
head(SBUX)
tail(SBUX)
# Sorting data based on "Date" variable
SBUX <- SBUX %>% a
ange(Date)
head(SBUX)
# Selecting "Close.Last" variable data
SBUX_Stock <- SBUX$Close.Last
# Summary statistics of the month of march SBUX stocks in 2019
summary(SBUX_Stock)
# Performing Random Forest model
set.seed(1234)
sbux_rf <- randomForest(SBUX_Stock ~ c(1:length(SBUX_Stock)),
importance=TRUE,
proximity=TRUE)
# Print the model
sbux_rf
# Plot the model
plot(sbux_rf, main="SBUX Stocks")
# plot Observed vs predicted values from the model
plot(SBUX_Stock,sbux_rf$predicted,
pch=19,xlab="observed Stocks",
ylab="predicted Stocks")
mtext(paste("R-squared",85.42))
# plotting residuals
plot(SBUX_Stock,c(sbux_rf$predicted - SBUX_Stock),
pch=18,ylab="residuals (predicted-observed)",
xlab="observed SBUX Stocks",
main = "Residual vs Actual",
col="blue3")
abline(h=0,col="red4",lty=1, lwd=2)
# Converting actual data into Time Series data
SBUX_ts <- ts(SBUX_Stock, frequency = 5)
# Plotting data
plot(SBUX_ts, ylab = "Stocks", main = "SBUX Stocks")
# Plotting Auto Co
elation Function & Partial Auto Co
elation...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here