12/3/2021
library(plotly)
library(tidyverse)
library(tidyquant)
# download stock prices for GAFAM
tickers = c("GOOG", "AAPL", "FB", "AMZN" ,"MSFT")
start = as.Date("2020-01-01"); end = as.Date("2021-11-30")
gafam <- tq_get(tickers, from = start, to = end, get = "stock.prices")
gafam <- group_by(gafam, symbol) %>% arrange(date)
first.day <- unique(gafam$date)[1]
first.price <- gafam$adjusted[gafam$date == first.day]
gafam$scaled <- (gafam$adjusted / first.price) * 100
# plot stock prices
fig <- plot_ly(gafam, x = ~date, y = ~scaled, color = ~symbol,
type = "scatter", mode = "lines") %>%
layout(title = "Stock Prices of GAFAM",
xaxis = list(title = "date (Jan 2020 - Nov 2021)"),
yaxis = list(title = "stock price (Jan 1, 2020 = 100)"))
fig