I have the following code for plotting Brock value
require(quantmod)
# Pull S&P500 from Yahoo
getSymbols("^GSPC", src="yahoo", from="1947-01-01")
# Convert to monthly, since GDP/AAA are quarterly/monthly, respectively
SPX <- to.monthly(GSPC, name="SPX")
# Pull GDP and AAA bond yield from FRED
getSymbols("AAA;GDP", src="FRED")
# Convert xts index to yearmon, so series will merge cleanly
index(AAA) <- as.yearmon(index(AAA))
index(GDP) <- as.yearmon(index(GDP))
# Merge, fill w/NA, and omit all obs where we don't have data for all 3 series
x <- na.omit(merge(SPX, GDP, AAA, fill=na.locf))
indexTZ(x) <- "UTC" # avoid potential timezone issues with non-datetime index
# Calculate Brock Value
x$BV <- x$GDP/(2*x$AAA)
# plot
plot(log(x[,c("SPX.Close","BV")]), main="Brock Value")
The above code produces following plot:
What I am trying to achieve is superimpose a S&P 500 curve on the plot like it is shown on this figure:
How would this be possible?
# Your Plot
plot(index(x), log(x[,"SPX.Close"]),
main= "Log Brock Value and Log S&P Close", col = "black",
ylab = "Log Value", xlab = "Years", type = "l")
lines(index(x), log(x[,c("BV")]), col = "red")
legend('bottomright', c("SPX.Close","Brock"),
lty=1, col=c('black', 'red'), bty='n', cex=1.2)