Using the given code, answer the questions below.
library(tidyquant)
library(tidyverse)
GDP <- tq_get("GDPC1", get = "economic.data", from = "1980-01-01", to ="2019-01-01")
GDP
## # A tibble: 157 x 2
## date price
## <date> <dbl>
## 1 1980-01-01 6838.
## 2 1980-04-01 6697.
## 3 1980-07-01 6689.
## 4 1980-10-01 6814.
## 5 1981-01-01 6947.
## 6 1981-04-01 6896.
## 7 1981-07-01 6978.
## 8 1981-10-01 6902.
## 9 1982-01-01 6795.
## 10 1982-04-01 6826.
## # ... with 147 more rows
GDP %>%
ggplot(aes(x = date, y = price)) +
geom_line()
Hear is the GDP over the past 39 years. You can see each recession.
UERATE <- tq_get("UNRATE", get = "economic.data", from = "1980-01-01", to ="2019-01-01")
UERATE
## # A tibble: 469 x 2
## date price
## <date> <dbl>
## 1 1980-01-01 6.3
## 2 1980-02-01 6.3
## 3 1980-03-01 6.3
## 4 1980-04-01 6.9
## 5 1980-05-01 7.5
## 6 1980-06-01 7.6
## 7 1980-07-01 7.8
## 8 1980-08-01 7.7
## 9 1980-09-01 7.5
## 10 1980-10-01 7.5
## # ... with 459 more rows
UERATE %>%
ggplot(aes(x = date, y = price)) +
geom_line()
Hear is the unemployment rate over the past 39 years. When unemployment rate hits lowest, recession seems to follow.
TREAS <- c("DGS10", "DGS20", "DGS30") %>%
tq_get( get = "economic.data", from = "1980-01-01", to ="2019-01-01")
TREAS
## # A tibble: 26,940 x 3
## symbol date price
## <chr> <date> <dbl>
## 1 DGS10 1980-01-01 NA
## 2 DGS10 1980-01-02 10.5
## 3 DGS10 1980-01-03 10.6
## 4 DGS10 1980-01-04 10.7
## 5 DGS10 1980-01-07 10.6
## 6 DGS10 1980-01-08 10.6
## 7 DGS10 1980-01-09 10.6
## 8 DGS10 1980-01-10 10.5
## 9 DGS10 1980-01-11 10.7
## 10 DGS10 1980-01-14 10.7
## # ... with 26,930 more rows
TREAS %>%
ggplot(aes(x = date, y = price, col = symbol)) +
geom_line()
Hear are the 10,20,30 year treasury bonds over the pasy 39 years. When 10 year bond at same or higher rate than 30, a recession seems to most likely follow.
TREAS <- c("DGS10", "DGS20", "DGS30") %>%
tq_get( get = "economic.data", from = "2007-01-01", to ="2010-01-01")
TREAS
## # A tibble: 2,355 x 3
## symbol date price
## <chr> <date> <dbl>
## 1 DGS10 2007-01-01 NA
## 2 DGS10 2007-01-02 4.68
## 3 DGS10 2007-01-03 4.67
## 4 DGS10 2007-01-04 4.62
## 5 DGS10 2007-01-05 4.65
## 6 DGS10 2007-01-08 4.66
## 7 DGS10 2007-01-09 4.66
## 8 DGS10 2007-01-10 4.69
## 9 DGS10 2007-01-11 4.74
## 10 DGS10 2007-01-12 4.77
## # ... with 2,345 more rows
TREAS %>%
ggplot(aes(x = date, y = price, col = symbol)) +
geom_line()
Same as graph before, just smaller time frame.
INDEX <- tq_get("USSLIND", get = "economic.data", from = "1980-01-01", to ="2019-01-01")
INDEX
## # A tibble: 445 x 2
## date price
## <date> <dbl>
## 1 1982-01-01 -0.92
## 2 1982-02-01 -0.43
## 3 1982-03-01 -0.2
## 4 1982-04-01 -0.17
## 5 1982-05-01 -0.11
## 6 1982-06-01 -0.1
## 7 1982-07-01 -0.13
## 8 1982-08-01 -0.3
## 9 1982-09-01 -0.290
## 10 1982-10-01 -0.1
## # ... with 435 more rows
INDEX %>%
ggplot(aes(x = date, y = price)) +
geom_line()
10 different economic numbers combined into 1 index When graph is going towards 0, a recession is most likely around the corner