# Load packages
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.1 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.3 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ✔ purrr 1.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidyquant)
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## ── Attaching core tidyquant packages ─────────────────────── tidyquant 1.0.12 ──
## ✔ PerformanceAnalytics 2.1.0 ✔ TTR 0.24.4
## ✔ quantmod 0.4.29 ✔ xts 0.14.3── Conflicts ────────────────────────────────────────── tidyquant_conflicts() ──
## ✖ zoo::as.Date() masks base::as.Date()
## ✖ zoo::as.Date.numeric() masks base::as.Date.numeric()
## ✖ dplyr::filter() masks stats::filter()
## ✖ xts::first() masks dplyr::first()
## ✖ dplyr::lag() masks stats::lag()
## ✖ xts::last() masks dplyr::last()
## ✖ PerformanceAnalytics::legend() masks graphics::legend()
## ✖ quantmod::summary() masks base::summary()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Stock index
tq_index_options()
## [1] "DOW" "DOWGLOBAL" "SP400" "SP500" "SP600"
data <- tq_index("SP400")
## Getting holdings for SP400
Stock exchanges
tq_exchange_options()
## [1] "AMEX" "NASDAQ" "NYSE"
data <- tq_exchange("NYSE")
## Getting data...
tq_get
stock prices from yahoo finance
stock <- tq_get("VOO")
economic data from FRED
unemployment_nh <- tq_get("NHUR", get = "economic.data")
unemployment_nh
## # A tibble: 128 × 3
## symbol date price
## <chr> <date> <dbl>
## 1 NHUR 2016-01-01 2.9
## 2 NHUR 2016-02-01 2.9
## 3 NHUR 2016-03-01 2.8
## 4 NHUR 2016-04-01 2.9
## 5 NHUR 2016-05-01 2.9
## 6 NHUR 2016-06-01 2.9
## 7 NHUR 2016-07-01 2.9
## 8 NHUR 2016-08-01 2.9
## 9 NHUR 2016-09-01 2.9
## 10 NHUR 2016-10-01 2.9
## # ℹ 118 more rows