Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 70ad4854ce
Fetching contributors…

Cannot retrieve contributors at this time

35 lines (23 sloc) 1.098 kb
library(quantmod) = getSymbols('ICSA', src='FRED', auto.assign=F)
sp500 = getSymbols('^GSPC', src='yahoo', auto.assign=F)
# Convert quotes to weekly and fetch Cl() closing price
sp500.weekly = Cl(to.weekly(sp500))
# prices end on Friday, must bump to Saturday to match BLS release dates
index(sp500.weekly) = index(sp500.weekly) + 1
# set column names:
names( = ''
names(sp500.weekly) = "sp500"
x = merge(, sp500.weekly, all=F) = data.frame(date=index(x), coredata(x))
# create a new, normalized (and scaled) data.frame from the original data
norm.df = normalize(, sd.scale=1)
# reverse the sense of the initial jobless claims column (since the correlation
# with the S&P is negative)
norm.df$ = -1 * norm.df$
g = ggplot(norm.df) + geom_line(aes(x=date, y=sp500), color='green', size=1, alpha=0.75)
g = g + geom_line(aes(x=date,, color='red', size=1, alpha=0.75)
g = g + theme_bw() + ylab('sd')
Jump to Line
Something went wrong with that request. Please try again.