Import stock prices
stocks <- tq_get(c("AAPL", "NVDA"),
get = "stock.prices",
from = "2023-01-01",
to = "2024-01-01")
stocks
## # A tibble: 500 × 8
## symbol date open high low close volume adjusted
## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 AAPL 2023-01-03 130. 131. 124. 125. 112117500 123.
## 2 AAPL 2023-01-04 127. 129. 125. 126. 89113600 125.
## 3 AAPL 2023-01-05 127. 128. 125. 125. 80962700 123.
## 4 AAPL 2023-01-06 126. 130. 125. 130. 87754700 128.
## 5 AAPL 2023-01-09 130. 133. 130. 130. 70790800 128.
## 6 AAPL 2023-01-10 130. 131. 128. 131. 63896200 129.
## 7 AAPL 2023-01-11 131. 134. 130. 133. 69458900 132.
## 8 AAPL 2023-01-12 134. 134. 131. 133. 71379600 132.
## 9 AAPL 2023-01-13 132. 135. 132. 135. 57809700 133.
## 10 AAPL 2023-01-17 135. 137. 134. 136. 63646600 134.
## # ℹ 490 more rows
Plot stock prices
stocks %>%
ggplot(aes(x = date, y = adjusted, color = symbol)) +
geom_line()
