Skip to content

Instantly share code, notes, and snippets.

@zachmayer
Created July 1, 2011 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zachmayer/1058784 to your computer and use it in GitHub Desktop.
Save zachmayer/1058784 to your computer and use it in GitHub Desktop.
Example code for casualfactors
library(quantmod)
getSymbols(c('AHETPI','CES0500000003','CPIAUCSL','GASREGM'),src = "FRED")
getSymbols('XAU/USD',src = "oanda")
#Definitions:
#AHETPI = Average Hourly Earnings of Production and Nonsupervisory Employees: Total Private
#CES0500000003 = Average Hourly Earnings of All Employees: Total Private
#CPIAUCSL = Consumer Price Index for All Urban Consumers: All Items
#GASREGM = US Regular All Formulations Gas Price
#XAUUSD USD per 1 oz of gold. Last 500 days only
#Convert from dollars to goods
Hourly_goods <- CES0500000003/CPIAUCSL
Hourly_NonSup_goods <- AHETPI/CPIAUCSL
#Convert from dollars to gallons of gas
Hourly_gas <- CES0500000003/GASREGM
Hourly_NonSup_gas <- AHETPI/GASREGM
#Convert from dollars to oz of gold
Hourly_gold <- CES0500000003/XAUUSD
Hourly_NonSup_gold <- AHETPI/XAUUSD
#Setup data for plotting
Hourly <- data.frame(cbind(Hourly_goods,Hourly_gas,Hourly_gold))
Hourly_NonSup <- data.frame(cbind(Hourly_NonSup_goods,Hourly_NonSup_gas,Hourly_NonSup_gold))
names(Hourly) <- c('Goods','Gas','Gold')
names(Hourly_NonSup) <- c('Goods','Gas','Gold')
Hourly$Date <- as.Date(rownames(Hourly))
Hourly_NonSup$Date <- as.Date(rownames(Hourly_NonSup))
#Make plots
library(ggplot2)
library(gridExtra)
grid.arrange( ggplot(Hourly, aes(x=Date, y=Goods)) + geom_line(),
ggplot(Hourly, aes(x=Date, y=Gas)) + geom_line(),
ggplot(Hourly, aes(x=Date, y=Gold)) + geom_line())
grid.arrange( ggplot(Hourly_NonSup, aes(x=Date, y=Goods)) + geom_line(),
ggplot(Hourly_NonSup, aes(x=Date, y=Gas)) + geom_line(),
ggplot(Hourly_NonSup, aes(x=Date, y=Gold)) + geom_line())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment