# Load packages
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6      ✔ purrr   0.3.4 
## ✔ tibble  3.1.8      ✔ dplyr   1.0.10
## ✔ tidyr   1.2.1      ✔ stringr 1.4.1 
## ✔ readr   2.1.2      ✔ forcats 0.5.2 
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
library(tidyquant)
## Loading required package: lubridate
## 
## Attaching package: 'lubridate'
## 
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
## 
## Loading required package: PerformanceAnalytics
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## 
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## 
## 
## Attaching package: 'xts'
## 
## The following objects are masked from 'package:dplyr':
## 
##     first, last
## 
## 
## Attaching package: 'PerformanceAnalytics'
## 
## The following object is masked from 'package:graphics':
## 
##     legend
## 
## Loading required package: quantmod
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo

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("TSLA")

Economic Data from FRED

employment_nh <- tq_get("NHUR", get = "economic.data")
employment_nh
## # A tibble: 128 × 3
##    symbol date       price
##    <chr>  <date>     <dbl>
##  1 NHUR   2012-01-01   5.2
##  2 NHUR   2012-02-01   5.2
##  3 NHUR   2012-03-01   5.3
##  4 NHUR   2012-04-01   5.4
##  5 NHUR   2012-05-01   5.4
##  6 NHUR   2012-06-01   5.5
##  7 NHUR   2012-07-01   5.6
##  8 NHUR   2012-08-01   5.6
##  9 NHUR   2012-09-01   5.6
## 10 NHUR   2012-10-01   5.6
## # … with 118 more rows