Import stock prices
stocks <- tq_get(c("JNJ", "MSFT", "BAC"),
get = "stock.prices",
from = "2016-01-01",
to = "2018-01-01")
stocks
## # A tibble: 1,509 × 8
## symbol date open high low close volume adjusted
## <chr> <date> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 JNJ 2016-01-04 102. 102. 99.4 100. 12722800 79.7
## 2 JNJ 2016-01-05 101. 101. 101. 101. 6467200 80.1
## 3 JNJ 2016-01-06 99.8 101. 99.6 100. 7733800 79.7
## 4 JNJ 2016-01-07 99.3 100. 98.9 99.2 9433100 78.7
## 5 JNJ 2016-01-08 99.9 99.9 97.8 98.2 9766700 77.9
## 6 JNJ 2016-01-11 98.2 98.6 96.1 97.6 8151400 77.4
## 7 JNJ 2016-01-12 98.0 98.6 97.2 98.2 6745000 78.0
## 8 JNJ 2016-01-13 98.5 99.0 96.8 97.0 8290700 77.0
## 9 JNJ 2016-01-14 97.1 99.5 97 98.9 10164300 78.5
## 10 JNJ 2016-01-15 96.4 98 96.2 97 12662200 77.0
## # ℹ 1,499 more rows
Plot stock prices
stocks %>%
ggplot(aes(x = date, y = adjusted, color = symbol)) +
geom_line()
