Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
13 changes: 13 additions & 0 deletions AutomatedEconomicAnalysis.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX
54 changes: 24 additions & 30 deletions AutomatedEconomicAnalysisWithR.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/R

# Startup - Packages --------------------------------------------------------------------------------------------------------

pkgTest <- function(x){
if (!require(x,character.only = TRUE)) {
install.packages(x,dep=TRUE)
Expand All @@ -24,20 +26,17 @@ pkgTest("tm")
pkgTest("gmailr")
pkgTest("COVID19")

setwd("~/Documents/R/")

# Test that FRED is online ####
test.online <- try(getSymbols("GDPC1",src='FRED'))

if ((inherits(test.online, "try-error"))) {
stop("\n\n\n----------\n Not online \n----------\n\n")
}
# Startup - Online? --------------------------------------------------------------------------------------------------------

rm(list=ls())
test.online <- !inherits(try(quantmod::getSymbols("GDPC1",src='FRED')), "try-error") # Test that FRED is online
stopifnot(test.online)
rm(list=ls()) # do we need it? replace with: rm(test.online) ?


# Startup - Email setup and credentials -------------------------------------------------------------

# Email setup and credentials -------------------------------------------------------------
setwd("~/Documents/R/")

# replace with your own email info
email <- gm_mime()
Expand All @@ -49,7 +48,7 @@ FRED_API_KEY <- "" # put your own FRED API key here
source("Credentials.R") # file where MY credentials for Fred, Twitter, and Gmail are stored
fredr_set_key(FRED_API_KEY)

# Data Download -------------------------------------------------------------
# Data Download - Definitions -------------------------------------------------------------

Data.US <- c("US.GDP.Real"="GDPC1",
"US.GDP.PCE"="PCECC96",
Expand Down Expand Up @@ -204,6 +203,7 @@ Data.US <- c("US.GDP.Real"="GDPC1",

)

# Data Download - Description -------------------------------------------------------------

Data.Description <- data.frame(
Mnemonic = names(Data.US),
Expand All @@ -227,7 +227,7 @@ for ( idx in 1:nrow(Data.Description) ) {
}


# Misc. functions ---------------------------------------------------------
# Functions - Misc. ---------------------------------------------------------

misc.FREDdowload <- function(series) {

Expand Down Expand Up @@ -260,7 +260,7 @@ misc.NBER.Recessions <- function(){
}


# Charting functions ---------------------------------------------------------
# Functions - Charting ---------------------------------------------------------

misc.GDPExpansionPlot <- function( series ){

Expand Down Expand Up @@ -628,10 +628,7 @@ Chart.DoublePanel <- function(series1, series2, periods) {

}




# Weekly Update -----------------------------------------------------------
# EXE - Tweet - Weekly Update -----------------------------------------------------------

# Tuesday: Gas Prices
Chart.Duo(series1="US.GasPrices", series2="US.Commodities.Oilprices",
Expand Down Expand Up @@ -685,7 +682,7 @@ InterestRate.Chart(Data.Rates = Reduce(function(...) merge(...), list( misc.FRED



# GDP Releases -------------------------------------------------------
# EXE - Tweet - GDP Releases -------------------------------------------------------


if ( ( as.Date( as.character(tail( fredr_release_dates(release_id = 53L) ,1)[,2]) ) == Sys.Date() ) ||
Expand Down Expand Up @@ -720,7 +717,7 @@ if ( ( as.Date( as.character(tail( fredr_release_dates(release_id = 53L) ,1)[,2]
}


# Activity Measures -------------------------------------------------------
# EXE - Tweet - Activity Measures -------------------------------------------------------


Chart.Duo(series1="US.Activity.RetailSales", series2="US.Activity.RetailSalesExAuto",
Expand Down Expand Up @@ -778,12 +775,7 @@ Chart.Duo(series1="US.Activity.RetailSalesSportsGoods", series2="US.Activity.Ret
tweet.text = "Bought a #Peleton During the Pandemic? Sales of #SportingGoods Skyrocketed in 2021. https://bit.ly/3BXLMFM #AdvanceRetailSales #rstats",
email=email)






# Labor Market -------------------------------------------------------
# EXE - Tweet - Labor Market -------------------------------------------------------


Chart.Single(series="US.JOLTS.QuitsRate",
Expand Down Expand Up @@ -841,7 +833,7 @@ Chart.Four(series1 = "US.Unemployment.EmploymentToPopulation",
email = email)


# Inflation -------------------------------------------------------
# EXE - Tweet - Inflation -------------------------------------------------------

Chart.Single(series = "US.CPI.Headline.mm.yy",
period = 25,
Expand Down Expand Up @@ -898,7 +890,7 @@ Chart.Duo(series1="US.CPI.AlcoholicBeverages.mm.yy", series2="US.CPI.AlcoholicBe



# Housing -------------------------------------------------------
# EXE - Tweet - Housing -------------------------------------------------------

Chart.Single(series="US.Housing.CaseShiller",
periods = 25,
Expand All @@ -922,7 +914,7 @@ Chart.Single(series="US.Survey.Empire",



# Motor Vehicles -------------------------------------------------------
# EXE - Tweet - Motor Vehicles -------------------------------------------------------

Chart.Duo(series1="US.Auto.Autosales", series2="US.Auto.InventorySalesRatio",
periods = 25,
Expand Down Expand Up @@ -952,7 +944,7 @@ if ( as.Date( as.character(tail( fredr_release_dates(release_id = 93L) ,1)[,2])
}


# Banking Sector -------------------------------------------------------
# EXE - Tweet - Banking Sector -------------------------------------------------------

Chart.Duo(series1="US.FDIC.NetChargeOffRateTotalLoans", series2="US.FDIC.LoanLossProvisions",
periods = 35,
Expand Down Expand Up @@ -1090,7 +1082,7 @@ if ( Data.Description[Data.Description$Mnemonic == "US.SLOOS.AutoLoansStandards"
}


# Transportation -------------------------------------------------------
# EXE - Tweet - Transportation -------------------------------------------------------

if ( Data.Description[Data.Description$Mnemonic == "US.Transportation.Air",6] == Sys.Date() )
Chart.Four(series1="US.Transportation.Air",
Expand All @@ -1111,7 +1103,7 @@ if ( Data.Description[Data.Description$Mnemonic == "US.Transportation.Rail",6] =
email=email)


# COVID -------------------------------------------------------
# EXE - Tweet - COVID -------------------------------------------------------

if (weekdays(Sys.Date()) %in% c("Tuesday", "Thursday", "Sunday")) {

Expand Down Expand Up @@ -1141,4 +1133,6 @@ if (weekdays(Sys.Date()) %in% c("Tuesday", "Thursday", "Sunday")) {
}


# EXE - Email -----------------------------------------------------------------------------------------------------------------

gm_send_message(email)