# Clear the workspace
rm(list = ls()) # Clear environment
gc() # Clear memory
## used (Mb) gc trigger (Mb) max used (Mb)
## Ncells 511350 27.4 1138878 60.9 644242 34.5
## Vcells 902919 6.9 8388608 64.0 1635701 12.5
cat("\f") # Clear console
#load libraries
library(fredr)
## Warning: package 'fredr' was built under R version 4.2.3
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.2.3
## Warning: package 'ggplot2' was built under R version 4.2.3
## Warning: package 'tibble' was built under R version 4.2.3
## Warning: package 'tidyr' was built under R version 4.2.3
## Warning: package 'readr' was built under R version 4.2.3
## Warning: package 'purrr' was built under R version 4.2.3
## Warning: package 'dplyr' was built under R version 4.2.3
## Warning: package 'stringr' was built under R version 4.2.3
## Warning: package 'forcats' was built under R version 4.2.3
## Warning: package 'lubridate' was built under R version 4.2.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.0
## ✔ purrr 1.0.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(ggplot2)
#set up data connect to FRED using API key
fredr_set_key("4399da45a01e52b47f5b0926ff32157b")
You are a financial analyst at a bank that sells mortgages on the primary market. Your manager wants to understand how historical data can serve as an indicator of the federal funds rate (FFR).
The FFR is one of several factors that drive the prime rate for home mortgages.
To choose the data, first determine the most popular data series with the searched text “federal funds.”
#search for data on FFR
popular_funds_series <- fredr_series_search_text(
search_text = "federal funds",
order_by = "popularity",
sort_order = "desc",
limit = 5
)
#See full title to determine data to use
popular_funds_series[,"title"]
## # A tibble: 5 × 1
## title
## <chr>
## 1 Federal Funds Effective Rate
## 2 Overnight Reverse Repurchase Agreements: Treasury Securities Sold by the Fede…
## 3 M2
## 4 M2
## 5 Federal Funds Effective Rate
#print the search results
string_of_results<-paste(c( popular_funds_series$id), collapse=', ' )
print(paste(c("The top series id are: ", string_of_results)))
## [1] "The top series id are: "
## [2] "FEDFUNDS, RRPONTSYD, M2SL, WM2NS, DFF"
The data set that most accurately provides the federal funds rate for the past 20 years based on the title of the data set and the observation points appears to be the “Federal Funds Effective Rate” (id “FEDFUND”). This data will therefore be explored and plotted.
ffr_data<-fredr(
series_id = "FEDFUNDS",
observation_start = as.Date("2003-01-01"), #setting start and end date to 2003-2023
observation_end = as.Date("2024-03-01")
)
#Explore data for FEDFUNDS
summary(ffr_data)
## date series_id value realtime_start
## Min. :2003-01-01 Length:254 Min. :0.050 Min. :2024-03-16
## 1st Qu.:2008-04-08 Class :character 1st Qu.:0.120 1st Qu.:2024-03-16
## Median :2013-07-16 Mode :character Median :0.780 Median :2024-03-16
## Mean :2013-07-16 Mean :1.509 Mean :2024-03-16
## 3rd Qu.:2018-10-24 3rd Qu.:2.317 3rd Qu.:2024-03-16
## Max. :2024-02-01 Max. :5.330 Max. :2024-03-16
## realtime_end
## Min. :2024-03-16
## 1st Qu.:2024-03-16
## Median :2024-03-16
## Mean :2024-03-16
## 3rd Qu.:2024-03-16
## Max. :2024-03-16
ffr_data
## # A tibble: 254 × 5
## date series_id value realtime_start realtime_end
## <date> <chr> <dbl> <date> <date>
## 1 2003-01-01 FEDFUNDS 1.24 2024-03-16 2024-03-16
## 2 2003-02-01 FEDFUNDS 1.26 2024-03-16 2024-03-16
## 3 2003-03-01 FEDFUNDS 1.25 2024-03-16 2024-03-16
## 4 2003-04-01 FEDFUNDS 1.26 2024-03-16 2024-03-16
## 5 2003-05-01 FEDFUNDS 1.26 2024-03-16 2024-03-16
## 6 2003-06-01 FEDFUNDS 1.22 2024-03-16 2024-03-16
## 7 2003-07-01 FEDFUNDS 1.01 2024-03-16 2024-03-16
## 8 2003-08-01 FEDFUNDS 1.03 2024-03-16 2024-03-16
## 9 2003-09-01 FEDFUNDS 1.01 2024-03-16 2024-03-16
## 10 2003-10-01 FEDFUNDS 1.01 2024-03-16 2024-03-16
## # ℹ 244 more rows
#plot date as x and value as y
ffr_plot<-ggplot(ffr_data,aes(x=date, y= value))+
geom_line()+
ggtitle("FFR by Year")+
xlab("Year")+
ylab("Percent")
ffr_plot
#Search data for 10-year bond rate
popular_bonds_series <- fredr_series_search_text(
search_text = "10-year bond rate",
order_by = "popularity",
sort_order = "desc",
limit = 5
)
popular_bonds_series
## # A tibble: 5 × 16
## id realtime_start realtime_end title observation_start observation_end
## <chr> <chr> <chr> <chr> <chr> <chr>
## 1 T10Y2Y 2024-03-16 2024-03-16 10-Year … 1976-06-01 2024-03-15
## 2 T10Y3M 2024-03-16 2024-03-16 10-Year … 1982-01-04 2024-03-15
## 3 T10YIE 2024-03-16 2024-03-16 10-Year … 2003-01-02 2024-03-15
## 4 T5YIFR 2024-03-16 2024-03-16 5-Year, … 2003-01-02 2024-03-15
## 5 BAA10Y 2024-03-16 2024-03-16 Moody's … 1986-01-02 2024-03-14
## # ℹ 10 more variables: frequency <chr>, frequency_short <chr>, units <chr>,
## # units_short <chr>, seasonal_adjustment <chr>,
## # seasonal_adjustment_short <chr>, last_updated <chr>, popularity <int>,
## # group_popularity <int>, notes <chr>
#See full title to determine data to use
popular_bonds_series[,"title"]
## # A tibble: 5 × 1
## title
## <chr>
## 1 10-Year Treasury Constant Maturity Minus 2-Year Treasury Constant Maturity
## 2 10-Year Treasury Constant Maturity Minus 3-Month Treasury Constant Maturity
## 3 10-Year Breakeven Inflation Rate
## 4 5-Year, 5-Year Forward Inflation Expectation Rate
## 5 Moody's Seasoned Baa Corporate Bond Yield Relative to Yield on 10-Year Treasu…
#print the search results
string_of_results<-paste(c( popular_bonds_series$id), collapse=', ' )
print(paste(c("The top series id are: ", string_of_results)))
## [1] "The top series id are: "
## [2] "T10Y2Y, T10Y3M, T10YIE, T5YIFR, BAA10Y"
Two data sets appear to provide the 10-year bond rate for the past 20 years: 1. 10-Year Treasury Constant Maturity Minus 2-Year Treasury Constant Maturity 2. 10-Year Treasury Constant Maturity Minus 3-Month Treasury Constant Maturity
Based on information published on FRED, the difference between the two is the maturity to which the average yield of a range of Treasury securities are adjusted (https://fred.stlouisfed.org/series/T10Y2Y). The data for the 2-year maturity will be explored and plotted.
tenYear_bond_data<-fredr(
series_id = "T10Y2Y",
observation_start = as.Date("2003-01-01"), #setting start and end date to 2003-2023
observation_end = as.Date("2024-03-01")
)
#Explore data
summary(tenYear_bond_data)
## date series_id value realtime_start
## Min. :2003-01-01 Length:5523 Min. :-1.080 Min. :2024-03-16
## 1st Qu.:2008-04-16 Class :character 1st Qu.: 0.270 1st Qu.:2024-03-16
## Median :2013-08-01 Mode :character Median : 1.210 Median :2024-03-16
## Mean :2013-08-01 Mean : 1.148 Mean :2024-03-16
## 3rd Qu.:2018-11-15 3rd Qu.: 1.950 3rd Qu.:2024-03-16
## Max. :2024-03-01 Max. : 2.910 Max. :2024-03-16
## NA's :227
## realtime_end
## Min. :2024-03-16
## 1st Qu.:2024-03-16
## Median :2024-03-16
## Mean :2024-03-16
## 3rd Qu.:2024-03-16
## Max. :2024-03-16
##
tenYear_bond_data
## # A tibble: 5,523 × 5
## date series_id value realtime_start realtime_end
## <date> <chr> <dbl> <date> <date>
## 1 2003-01-01 T10Y2Y NA 2024-03-16 2024-03-16
## 2 2003-01-02 T10Y2Y 2.27 2024-03-16 2024-03-16
## 3 2003-01-03 T10Y2Y 2.26 2024-03-16 2024-03-16
## 4 2003-01-06 T10Y2Y 2.25 2024-03-16 2024-03-16
## 5 2003-01-07 T10Y2Y 2.27 2024-03-16 2024-03-16
## 6 2003-01-08 T10Y2Y 2.29 2024-03-16 2024-03-16
## 7 2003-01-09 T10Y2Y 2.32 2024-03-16 2024-03-16
## 8 2003-01-10 T10Y2Y 2.37 2024-03-16 2024-03-16
## 9 2003-01-13 T10Y2Y 2.34 2024-03-16 2024-03-16
## 10 2003-01-14 T10Y2Y 2.34 2024-03-16 2024-03-16
## # ℹ 5,513 more rows
#plot date as x and value as y
tenYear_bond_plot<-ggplot(tenYear_bond_data,aes(x=date, y= value))+
geom_line()+
ggtitle("10-Year Treasury Constant Maturity Minus 2-Year Treasury Constant Maturity")+
xlab("Year")+
ylab("Percent")
tenYear_bond_plot
## Warning: Removed 1 row containing missing values (`geom_line()`).
#Search data for the inflation rate
popular_inflation_series <- fredr_series_search_text(
search_text = "inflation cpi",
order_by = "popularity",
sort_order = "desc",
limit = 5
)
popular_inflation_series
## # A tibble: 5 × 16
## id realtime_start realtime_end title observation_start observation_end
## <chr> <chr> <chr> <chr> <chr> <chr>
## 1 CPIAUCSL 2024-03-16 2024-03-16 Cons… 1947-01-01 2024-02-01
## 2 FPCPITOTL… 2024-03-16 2024-03-16 Infl… 1960-01-01 2022-01-01
## 3 CORESTICK… 2024-03-16 2024-03-16 Stic… 1968-01-01 2024-02-01
## 4 CPILFESL 2024-03-16 2024-03-16 Cons… 1957-01-01 2024-02-01
## 5 CUSR0000S… 2024-03-16 2024-03-16 Cons… 1953-01-01 2024-02-01
## # ℹ 10 more variables: frequency <chr>, frequency_short <chr>, units <chr>,
## # units_short <chr>, seasonal_adjustment <chr>,
## # seasonal_adjustment_short <chr>, last_updated <chr>, popularity <int>,
## # group_popularity <int>, notes <chr>
#See full title and ID to determine data to use
popular_inflation_series[,"title"]
## # A tibble: 5 × 1
## title
## <chr>
## 1 Consumer Price Index for All Urban Consumers: All Items in U.S. City Average
## 2 Inflation, consumer prices for the United States
## 3 Sticky Price Consumer Price Index less Food and Energy
## 4 Consumer Price Index for All Urban Consumers: All Items Less Food and Energy …
## 5 Consumer Price Index for All Urban Consumers: Used Cars and Trucks in U.S. Ci…
popular_inflation_series[,"id"]
## # A tibble: 5 × 1
## id
## <chr>
## 1 CPIAUCSL
## 2 FPCPITOTLZGUSA
## 3 CORESTICKM159SFRBATL
## 4 CPILFESL
## 5 CUSR0000SETA02
#print the search results
string_of_results<-paste(c( popular_inflation_series$id), collapse=', ' )
print(paste(c("The top series id are: ", string_of_results)))
## [1] "The top series id are: "
## [2] "CPIAUCSL, FPCPITOTLZGUSA, CORESTICKM159SFRBATL, CPILFESL, CUSR0000SETA02"
The data set that most accurately provides the inflation rate for the past 20 years based on the title of the data set and the observation points appears to be the “Inflation, consumer prices for the United States” (id “FPCPITOTLZGUSA”). This data will therefore be explored and plotted.
inflation_data<-fredr(
series_id = "FPCPITOTLZGUSA",
observation_start = as.Date("2003-01-01"), #setting start and end date to 2003-2023
observation_end = as.Date("2024-03-01")
)
#Explore data
summary(inflation_data)
## date series_id value realtime_start
## Min. :2003-01-01 Length:20 Min. :-0.3555 Min. :2024-03-16
## 1st Qu.:2007-10-01 Class :character 1st Qu.: 1.5829 1st Qu.:2024-03-16
## Median :2012-07-02 Mode :character Median : 2.2001 Median :2024-03-16
## Mean :2012-07-02 Mean : 2.4777 Mean :2024-03-16
## 3rd Qu.:2017-04-02 3rd Qu.: 3.1741 3rd Qu.:2024-03-16
## Max. :2022-01-01 Max. : 8.0028 Max. :2024-03-16
## realtime_end
## Min. :2024-03-16
## 1st Qu.:2024-03-16
## Median :2024-03-16
## Mean :2024-03-16
## 3rd Qu.:2024-03-16
## Max. :2024-03-16
inflation_data
## # A tibble: 20 × 5
## date series_id value realtime_start realtime_end
## <date> <chr> <dbl> <date> <date>
## 1 2003-01-01 FPCPITOTLZGUSA 2.27 2024-03-16 2024-03-16
## 2 2004-01-01 FPCPITOTLZGUSA 2.68 2024-03-16 2024-03-16
## 3 2005-01-01 FPCPITOTLZGUSA 3.39 2024-03-16 2024-03-16
## 4 2006-01-01 FPCPITOTLZGUSA 3.23 2024-03-16 2024-03-16
## 5 2007-01-01 FPCPITOTLZGUSA 2.85 2024-03-16 2024-03-16
## 6 2008-01-01 FPCPITOTLZGUSA 3.84 2024-03-16 2024-03-16
## 7 2009-01-01 FPCPITOTLZGUSA -0.356 2024-03-16 2024-03-16
## 8 2010-01-01 FPCPITOTLZGUSA 1.64 2024-03-16 2024-03-16
## 9 2011-01-01 FPCPITOTLZGUSA 3.16 2024-03-16 2024-03-16
## 10 2012-01-01 FPCPITOTLZGUSA 2.07 2024-03-16 2024-03-16
## 11 2013-01-01 FPCPITOTLZGUSA 1.46 2024-03-16 2024-03-16
## 12 2014-01-01 FPCPITOTLZGUSA 1.62 2024-03-16 2024-03-16
## 13 2015-01-01 FPCPITOTLZGUSA 0.119 2024-03-16 2024-03-16
## 14 2016-01-01 FPCPITOTLZGUSA 1.26 2024-03-16 2024-03-16
## 15 2017-01-01 FPCPITOTLZGUSA 2.13 2024-03-16 2024-03-16
## 16 2018-01-01 FPCPITOTLZGUSA 2.44 2024-03-16 2024-03-16
## 17 2019-01-01 FPCPITOTLZGUSA 1.81 2024-03-16 2024-03-16
## 18 2020-01-01 FPCPITOTLZGUSA 1.23 2024-03-16 2024-03-16
## 19 2021-01-01 FPCPITOTLZGUSA 4.70 2024-03-16 2024-03-16
## 20 2022-01-01 FPCPITOTLZGUSA 8.00 2024-03-16 2024-03-16
#plot date as x and value as y
inflation_plot<-ggplot(inflation_data,aes(x=date, y= value))+
geom_line()+
ggtitle("Inflation, consumer prices for the United States")+
xlab("Year")+
ylab("Percent")
inflation_plot
#Search data for the unemployment rate
popular_unemp_series <- fredr_series_search_text(
search_text = "unemployment",
order_by = "popularity",
sort_order = "desc",
limit = 5
)
popular_unemp_series
## # A tibble: 5 × 16
## id realtime_start realtime_end title observation_start observation_end
## <chr> <chr> <chr> <chr> <chr> <chr>
## 1 CPIAUCSL 2024-03-16 2024-03-16 Cons… 1947-01-01 2024-02-01
## 2 UNRATE 2024-03-16 2024-03-16 Unem… 1948-01-01 2024-02-01
## 3 PAYEMS 2024-03-16 2024-03-16 All … 1939-01-01 2024-02-01
## 4 ICSA 2024-03-16 2024-03-16 Init… 1967-01-07 2024-03-09
## 5 SAHMREALT… 2024-03-16 2024-03-16 Real… 1959-12-01 2024-02-01
## # ℹ 10 more variables: frequency <chr>, frequency_short <chr>, units <chr>,
## # units_short <chr>, seasonal_adjustment <chr>,
## # seasonal_adjustment_short <chr>, last_updated <chr>, popularity <int>,
## # group_popularity <int>, notes <chr>
#See full title to determine data to use
popular_unemp_series[,"title"]
## # A tibble: 5 × 1
## title
## <chr>
## 1 Consumer Price Index for All Urban Consumers: All Items in U.S. City Average
## 2 Unemployment Rate
## 3 All Employees, Total Nonfarm
## 4 Initial Claims
## 5 Real-time Sahm Rule Recession Indicator
#print the search results
string_of_results<-paste(c(popular_unemp_series$id), collapse=', ' )
print(paste(c("The top series id are: ", string_of_results)))
## [1] "The top series id are: "
## [2] "CPIAUCSL, UNRATE, PAYEMS, ICSA, SAHMREALTIME"
The data set that most accurately provides the unemployment rate for the past 20 years based on the title of the data set and the observation points appears to be the “Unemployment Rate” (id “UNRATE”). This data will therefore be explored and plotted.
unemp_data<-fredr(
series_id = "UNRATE",
observation_start = as.Date("2003-01-01"), #setting start and end date to 2003-2023
observation_end = as.Date("2024-03-01")
)
#Explore
summary(unemp_data)
## date series_id value realtime_start
## Min. :2003-01-01 Length:254 Min. : 3.40 Min. :2024-03-16
## 1st Qu.:2008-04-08 Class :character 1st Qu.: 4.40 1st Qu.:2024-03-16
## Median :2013-07-16 Mode :character Median : 5.30 Median :2024-03-16
## Mean :2013-07-16 Mean : 5.88 Mean :2024-03-16
## 3rd Qu.:2018-10-24 3rd Qu.: 7.20 3rd Qu.:2024-03-16
## Max. :2024-02-01 Max. :14.80 Max. :2024-03-16
## realtime_end
## Min. :2024-03-16
## 1st Qu.:2024-03-16
## Median :2024-03-16
## Mean :2024-03-16
## 3rd Qu.:2024-03-16
## Max. :2024-03-16
unemp_data
## # A tibble: 254 × 5
## date series_id value realtime_start realtime_end
## <date> <chr> <dbl> <date> <date>
## 1 2003-01-01 UNRATE 5.8 2024-03-16 2024-03-16
## 2 2003-02-01 UNRATE 5.9 2024-03-16 2024-03-16
## 3 2003-03-01 UNRATE 5.9 2024-03-16 2024-03-16
## 4 2003-04-01 UNRATE 6 2024-03-16 2024-03-16
## 5 2003-05-01 UNRATE 6.1 2024-03-16 2024-03-16
## 6 2003-06-01 UNRATE 6.3 2024-03-16 2024-03-16
## 7 2003-07-01 UNRATE 6.2 2024-03-16 2024-03-16
## 8 2003-08-01 UNRATE 6.1 2024-03-16 2024-03-16
## 9 2003-09-01 UNRATE 6.1 2024-03-16 2024-03-16
## 10 2003-10-01 UNRATE 6 2024-03-16 2024-03-16
## # ℹ 244 more rows
#plot date as x and value as y
unemp_plot<-ggplot(unemp_data,aes(x=date, y= value))+
geom_line()+
ggtitle("Unemployment Rate")+
xlab("Year")+
ylab("Percent")
unemp_plot
#Search data for recession information
popular_recess_series <- fredr_series_search_text(
search_text = "recession",
order_by = "popularity",
sort_order = "desc",
limit = 5
)
popular_recess_series
## # A tibble: 5 × 16
## id realtime_start realtime_end title observation_start observation_end
## <chr> <chr> <chr> <chr> <chr> <chr>
## 1 SAHMREALT… 2024-03-16 2024-03-16 Real… 1959-12-01 2024-02-01
## 2 CES050000… 2024-03-16 2024-03-16 Aver… 2006-03-01 2024-02-01
## 3 RECPROUSM… 2024-03-16 2024-03-16 Smoo… 1967-06-01 2024-01-01
## 4 JHDUSRGDP… 2024-03-16 2024-03-16 Date… 1967-10-01 2023-07-01
## 5 USREC 2024-03-16 2024-03-16 NBER… 1854-12-01 2024-02-01
## # ℹ 10 more variables: frequency <chr>, frequency_short <chr>, units <chr>,
## # units_short <chr>, seasonal_adjustment <chr>,
## # seasonal_adjustment_short <chr>, last_updated <chr>, popularity <int>,
## # group_popularity <int>, notes <chr>
#See full title to determine data to use
popular_recess_series[,"title"]
## # A tibble: 5 × 1
## title
## <chr>
## 1 Real-time Sahm Rule Recession Indicator
## 2 Average Hourly Earnings of All Employees, Total Private
## 3 Smoothed U.S. Recession Probabilities
## 4 Dates of U.S. recessions as inferred by GDP-based recession indicator
## 5 NBER based Recession Indicators for the United States from the Period followi…
popular_recess_series[,"id"]
## # A tibble: 5 × 1
## id
## <chr>
## 1 SAHMREALTIME
## 2 CES0500000003
## 3 RECPROUSM156N
## 4 JHDUSRGDPBR
## 5 USREC
#print the search results
string_of_results<-paste(c( popular_recess_series$id), collapse=', ' )
print(paste(c("The top series id are: ", string_of_results)))
## [1] "The top series id are: "
## [2] "SAHMREALTIME, CES0500000003, RECPROUSM156N, JHDUSRGDPBR, USREC"
The data set that most accurately provides the recession periods over the past 20 years based on the title of the data set and the observation points appears to be the “Dates of U.S. recessions as inferred by GDP-based recession indicator” (id “JHDUSRGDPBR”). This data will therefore be explored and plotted.
recess_data<-fredr(
series_id = "JHDUSRGDPBR",
observation_start = as.Date("2003-01-01"), #setting start and end date to 2003-2023
observation_end = as.Date("2024-03-01")
)
#Explore data
summary(recess_data)
## date series_id value realtime_start
## Min. :2003-01-01 Length:83 Min. :0.0000 Min. :2024-03-16
## 1st Qu.:2008-02-15 Class :character 1st Qu.:0.0000 1st Qu.:2024-03-16
## Median :2013-04-01 Mode :character Median :0.0000 Median :2024-03-16
## Mean :2013-04-01 Mean :0.1084 Mean :2024-03-16
## 3rd Qu.:2018-05-16 3rd Qu.:0.0000 3rd Qu.:2024-03-16
## Max. :2023-07-01 Max. :1.0000 Max. :2024-03-16
## realtime_end
## Min. :2024-03-16
## 1st Qu.:2024-03-16
## Median :2024-03-16
## Mean :2024-03-16
## 3rd Qu.:2024-03-16
## Max. :2024-03-16
recess_data
## # A tibble: 83 × 5
## date series_id value realtime_start realtime_end
## <date> <chr> <dbl> <date> <date>
## 1 2003-01-01 JHDUSRGDPBR 0 2024-03-16 2024-03-16
## 2 2003-04-01 JHDUSRGDPBR 0 2024-03-16 2024-03-16
## 3 2003-07-01 JHDUSRGDPBR 0 2024-03-16 2024-03-16
## 4 2003-10-01 JHDUSRGDPBR 0 2024-03-16 2024-03-16
## 5 2004-01-01 JHDUSRGDPBR 0 2024-03-16 2024-03-16
## 6 2004-04-01 JHDUSRGDPBR 0 2024-03-16 2024-03-16
## 7 2004-07-01 JHDUSRGDPBR 0 2024-03-16 2024-03-16
## 8 2004-10-01 JHDUSRGDPBR 0 2024-03-16 2024-03-16
## 9 2005-01-01 JHDUSRGDPBR 0 2024-03-16 2024-03-16
## 10 2005-04-01 JHDUSRGDPBR 0 2024-03-16 2024-03-16
## # ℹ 73 more rows
#1 if yes recession, 0 if no
#Plot inflation dates
recess_plot<-ggplot(recess_data,aes(x=date, y= value))+
geom_line()+
ggtitle("US Recessions as inferred by GDP-based recession indicator")+
xlab("Year")+
ylab("1 to 0")
recess_plot
#try a histogram
recess_plot<-ggplot(recess_data,aes(x=date, y= value))+
geom_line()+
ggtitle("US Recessions as inferred by GDP-based recession indicator")+
xlab("Year")+
ylab("1 to 0")
yrng<-range(recess_data$value)
#Plot of all rates
money_plot<-ggplot()+
geom_line(data=ffr_data,aes(x=date, y= value, color="FFR"))+
geom_line(data=tenYear_bond_data,aes(x=date, y= value, color="Bond Rate"))+
geom_line(data=inflation_data,aes(x=date, y= value, color="Inflation Rate"))+
geom_line(data=unemp_data,aes(x=date, y= value, color="Unemployment Rate"))+
geom_line(data=recess_data,aes(x=date, y= value*15, color = "Recession Period"))+
scale_y_continuous(
# Features of the first axis
name = "Percent",
# Add a second axis and specify its features
sec.axis = sec_axis(~./15, name="1 or 0")
) +
ggtitle("Economic Indicators")+
xlab("Year")
money_plot
## Warning: Removed 1 row containing missing values (`geom_line()`).
The “money-plot” is a combination of the previous plots which provides the federal funds rate, 10-year bond rate, inflation rate, unemployment rate, and recession periods over the last 20 years. The visualization shows trends before, during, and after a recession. By observing and noting these trends, the federal funds rate can be determined based on the current values of the other indicators relative to their recent past values and the potential for a recession.
The unemployment rate and bond rate appear to trend upward during times of recession while the federal funds rate trends down and the inflation rate trends down and then back up during those same periods. Observing the latest data, the unemployment rate and bond rate appear to have plateaued and are beginning to trend up; federal funds rate appears to be plateauing; and the inflation rate has been trending up since 2020. These observations indicate the beginning of a recession and the likelihood of the federal funds rate trending down in the near future.