Using the given code, answer the questions below.
library(tidyquant)
library(tidyverse)
stocks <- tq_get("AAPL", get = "stock.prices", from = "2016-01-01")
stocks
stocks %>%
ggplot(aes(x = date, y = close)) +
geom_line()
There are 7 columns (variables)
The variables are, date, open, high, low, close, volume, and adjusted
stocks <- tq_get(c("AAPL", "MSFT"), get = "stock.prices", from = "2016-01-01")
stocks
There are 8 variables and there is another variable called symbol
Hint: Use dplyr::mutate. Market cap is given by the formula, MC = N × P, where MC is the market capitalization, N is the number of shares outstanding, and P is the closing price per share.
stocks <- stocks %>%
mutate(MC = volume * close)
stocks
Hint: Use dplyr::select.
stocks <- stocks %>%
select(symbol, date, close, MC)
stocks
Hint: Use ggplot2::ggplot.
stocks %>%
ggplot(aes(x = date, y = close, color = symbol)) +
geom_line()