── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::first() masks xts::first()
✖ dplyr::lag() masks stats::lag()
✖ dplyr::last() masks xts::last()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(scales)
Attaching package: 'scales'
The following object is masked from 'package:purrr':
discard
The following object is masked from 'package:readr':
col_factor
library(zoo)
Taxa de Juros 2 Anos
# Defina o período para os dadosstart_date <-"1970-01-01"end_date <-Sys.Date()# Obtenha os dados da Federal Funds Ratefed_funds <-getSymbols("FEDFUNDS", src ="FRED", from = start_date, to = end_date, auto.assign =FALSE)# Obtenha os dados da taxa de juros de Treasury Bills de 2 anostreasury_bills_2yr <-getSymbols("DGS2", src ="FRED", from = start_date, to = end_date, auto.assign =FALSE)# Ajuste os dados para terem o mesmo número de linhasdata <-na.omit(merge(fed_funds, treasury_bills_2yr))# Renomeie as colunascolnames(data) <-c("Federal_Funds_Rate", "Treasury_Bills_2yr_Rate")# Crie um gráfico usando ggplot2ggplot(data, aes(x =index(data))) +geom_line(aes(y = Federal_Funds_Rate, color ="Federal Funds Rate")) +geom_line(aes(y = Treasury_Bills_2yr_Rate, color ="Treasury Bills 2yr Rate")) +scale_color_manual(values =c("red", "blue")) +labs(title ="Federal Funds Rate vs Treasury Bills 2 anos Rate",y ="Interest Rate (%)",color ="Interest Rate Type") +theme_economist_white()
Janelas para a taxa de juros (1978-01-01 a 1981-01-01)
# Definir as datas de início e fimstart_date <-"1970-01-01"end_date <-"1981-01-01"# Obter os dados da Federal Funds Ratefed_funds <-getSymbols("FEDFUNDS", src ="FRED", from = start_date, to = end_date, auto.assign =FALSE)# Obter os dados da taxa de juros de Treasury Bills de 2 anostreasury_bills_2yr <-getSymbols("DGS2", src ="FRED", from = start_date, to = end_date, auto.assign =FALSE)# Ajustar os dados para terem o mesmo número de linhasdata <-na.omit(merge(fed_funds, treasury_bills_2yr))# Renomear as colunascolnames(data) <-c("Federal_Funds_Rate", "Treasury_Bills_2yr_Rate")# Criar um gráfico usando ggplot2ggplot(data, aes(x =index(data))) +geom_line(aes(y = Federal_Funds_Rate, color ="Federal Funds Rate")) +geom_line(aes(y = Treasury_Bills_2yr_Rate, color ="Treasury Bills 2yr Rate")) +scale_color_manual(values =c("red", "blue")) +labs(title ="Federal Funds Rate vs Treasury Bills 2 anos Rate",y ="Interest Rate (%)",color ="Interest Rate Type") +theme_economist_white()
Janelas para a taxa de juros (1989-01-01 a 1991-01-01)
# Definir as novas datas de início e fimstart_date <-"1989-01-01"end_date <-"1991-01-01"# Obter os dados da Federal Funds Ratefed_funds <-getSymbols("FEDFUNDS", src ="FRED", from = start_date, to = end_date, auto.assign =FALSE)# Obter os dados da taxa de juros de Treasury Bills de 2 anostreasury_bills_2yr <-getSymbols("DGS2", src ="FRED", from = start_date, to = end_date, auto.assign =FALSE)# Ajustar os dados para terem o mesmo número de linhasdata <-na.omit(merge(fed_funds, treasury_bills_2yr))# Renomear as colunascolnames(data) <-c("Federal_Funds_Rate", "Treasury_Bills_2yr_Rate")# Criar um gráfico usando ggplot2ggplot(data, aes(x =index(data))) +geom_line(aes(y = Federal_Funds_Rate, color ="Federal Funds Rate")) +geom_line(aes(y = Treasury_Bills_2yr_Rate, color ="Treasury Bills 2yr Rate")) +scale_color_manual(values =c("red", "blue")) +labs(title ="Federal Funds Rate vs Treasury Bills 2 anos Rate",y ="Interest Rate (%)",color ="Interest Rate Type") +theme_economist_white()
Janelas para a taxa de juros (2000-01-01 a 2002-01-01)
# Definir as novas datas de início e fimstart_date <-"2000-01-01"end_date <-"2002-01-01"# Obter os dados da Federal Funds Ratefed_funds <-getSymbols("FEDFUNDS", src ="FRED", from = start_date, to = end_date, auto.assign =FALSE)# Obter os dados da taxa de juros de Treasury Bills de 2 anostreasury_bills_2yr <-getSymbols("DGS2", src ="FRED", from = start_date, to = end_date, auto.assign =FALSE)# Ajustar os dados para terem o mesmo número de linhasdata <-na.omit(merge(fed_funds, treasury_bills_2yr))# Renomear as colunascolnames(data) <-c("Federal_Funds_Rate", "Treasury_Bills_2yr_Rate")# Criar um gráfico usando ggplot2ggplot(data, aes(x =index(data))) +geom_line(aes(y = Federal_Funds_Rate, color ="Federal Funds Rate")) +geom_line(aes(y = Treasury_Bills_2yr_Rate, color ="Treasury Bills 2yr Rate")) +scale_color_manual(values =c("red", "blue")) +labs(title ="Federal Funds Rate vs Treasury Bills 2 anos Rate",y ="Interest Rate (%)",color ="Interest Rate Type") +theme_economist_white()
Janelas para a taxa de juros (2006-01-01 a 2008-01-01)
# Definir as novas datas de início e fimstart_date <-"2006-01-01"end_date <-"2008-01-01"# Obter os dados da Federal Funds Ratefed_funds <-getSymbols("FEDFUNDS", src ="FRED", from = start_date, to = end_date, auto.assign =FALSE)# Obter os dados da taxa de juros de Treasury Bills de 2 anostreasury_bills_2yr <-getSymbols("DGS2", src ="FRED", from = start_date, to = end_date, auto.assign =FALSE)# Ajustar os dados para terem o mesmo número de linhasdata <-na.omit(merge(fed_funds, treasury_bills_2yr))# Renomear as colunascolnames(data) <-c("Federal_Funds_Rate", "Treasury_Bills_2yr_Rate")# Criar um gráfico usando ggplot2ggplot(data, aes(x =index(data))) +geom_line(aes(y = Federal_Funds_Rate, color ="Federal Funds Rate")) +geom_line(aes(y = Treasury_Bills_2yr_Rate, color ="Treasury Bills 2yr Rate")) +scale_color_manual(values =c("red", "blue")) +labs(title ="Federal Funds Rate vs Treasury Bills 2 anos Rate",y ="Interest Rate (%)",color ="Interest Rate Type") +theme_economist_white()
Janelas para a taxa de juros (2019-01-01 até agora)
# Definir a data de início como 2019-01-01start_date <-"2019-01-01"# Definir a data final como a data atualend_date <-Sys.Date()# Obter os dados da Federal Funds Ratefed_funds <-getSymbols("FEDFUNDS", src ="FRED", from = start_date, to = end_date, auto.assign =FALSE)# Obter os dados da taxa de juros de Treasury Bills de 2 anostreasury_bills_2yr <-getSymbols("DGS2", src ="FRED", from = start_date, to = end_date, auto.assign =FALSE)# Ajustar os dados para terem o mesmo número de linhasdata <-na.omit(merge(fed_funds, treasury_bills_2yr))# Renomear as colunascolnames(data) <-c("Federal_Funds_Rate", "Treasury_Bills_2yr_Rate")# Criar um gráfico usando ggplot2ggplot(data, aes(x =index(data))) +geom_line(aes(y = Federal_Funds_Rate, color ="Federal Funds Rate")) +geom_line(aes(y = Treasury_Bills_2yr_Rate, color ="Treasury Bills 2yr Rate")) +scale_color_manual(values =c("red", "blue")) +labs(title ="Federal Funds Rate vs Treasury Bills 2 anos Rate",y ="Interest Rate (%)",color ="Interest Rate Type") +theme_economist_white()
Desemprego
# Defina o período para os dadosstart_date <-"1970-01-01"end_date <-Sys.Date()# Obtenha os dados da taxa de desemprego dos EUAgetSymbols("UNRATE", src ="FRED", from = start_date, to = end_date)
[1] "UNRATE"
unemployment_rate <-na.omit(UNRATE)# Crie um data frame com as datas e a taxa de desempregodata <-data.frame(Date =index(unemployment_rate), Unemployment_Rate =as.numeric(coredata(unemployment_rate)))# Crie um gráfico usando ggplot2 com a taxa de desempregoggplot(data, aes(x = Date, y = Unemployment_Rate)) +geom_line(color ="red") +labs(title ="Taxa de Desemprego",y ="Taxa de Desemprego (%)",x ="Year") +theme_economist_white()+geom_vline(xintercept =as.numeric(as.Date(c("1978-01-01", "1980-12-31"))), linetype ="dashed", color ="black") +geom_vline(xintercept =as.numeric(as.Date(c("1989-01-01", "1990-12-31"))), linetype ="dashed", color ="red") +geom_vline(xintercept =as.numeric(as.Date(c("2000-01-01", "2001-12-31"))), linetype ="dashed", color ="black") +geom_vline(xintercept =as.numeric(as.Date(c("2006-01-01", "2007-12-31"))), linetype ="dashed", color ="red") +geom_vline(xintercept =as.numeric(as.Date(c("2019-01-01"))), linetype ="dashed", color ="black")
PIB POTENCIAL E REAL
start_date <-"1970-01-01"end_date <-Sys.Date()# Obtenha os dados do Produto Interno Bruto (PIB) real e do PIB potencial dos EUAgetSymbols(c("GDPC1", "GDPPOT"), src ="FRED", from = start_date, to = end_date)
[1] "GDPC1" "GDPPOT"
# Ajuste o comprimento dos dados do PIB para corresponder aos outros dadosgdp_real <-na.omit(GDPC1)gdp_potential <-na.omit(GDPPOT)gdp <-merge(gdp_real, gdp_potential)# Crie um data frame com as datas, o PIB real e o PIB potencialdata <-data.frame(Date =index(gdp), GDP_Real =as.numeric(coredata(gdp[,1])),GDP_Potential =as.numeric(coredata(gdp[,2])))# Crie um gráfico usando ggplot2 com o PIB real e o PIB potencialggplot(data, aes(x = Date)) +geom_line(aes(y = GDP_Real, color ="Real GDP")) +geom_line(aes(y = GDP_Potential, color ="Potential GDP")) +scale_color_manual(values =c("blue", "red")) +labs(title ="US Real GDP vs Potential GDP",y ="GDP (billions of dollars)",x ="Data",color ="GDP Type") +theme_economist_white()+geom_vline(xintercept =as.numeric(as.Date(c("1978-01-01", "1980-12-31"))), linetype ="dashed", color ="black") +geom_vline(xintercept =as.numeric(as.Date(c("1989-01-01", "1990-12-31"))), linetype ="dashed", color ="red") +geom_vline(xintercept =as.numeric(as.Date(c("2000-01-01", "2001-12-31"))), linetype ="dashed", color ="black") +geom_vline(xintercept =as.numeric(as.Date(c("2006-01-01", "2007-12-31"))), linetype ="dashed", color ="red") +geom_vline(xintercept =as.numeric(as.Date(c("2019-01-01"))), linetype ="dashed", color ="black")
Warning: Removed 1 row containing missing values or values outside the scale range
(`geom_line()`).