Part Finance Part R question
I have been trying to replicate the below formula in R using the Quantmod package and xts also using the diff function. The code gives me a plot for credit impulse but it doesn't seem to be replicating what I am trying to get at. See link
https://www.gam.com/media/1434580/biggs.pdf -
page 2 give the formula for Credit Impulse - where C is the stock of credit at time t
Credit impulset = (Ct – Ct-1)/GDPt – (Ct-1-Ct-2)/GDPt-1
page 3 take a look at the graph( This is the graph I am trying to replicate for Credit Impulse
Am I using the diff function the right way also could I be doing this more efficiently in R?
below is my code
#US DEBT [BN][USD][Q]
usd_debt <- getSymbols("CRDQUSAPABIS", src = "FRED", auto.assign=FALSE)
##US GDP [BN][USD][Q]
usd_gdp <- getSymbols("GDP", src = "FRED", auto.assign=FALSE)
#USD Credit Impulse
usd_debt <- usd_debt["2000/2016"]
usd_gdp <- usd_gdp["2000/2016"]
usd_ratio <- usd_debt/usd_gdp
usd_ci <- diff(usd_ratio)
plot(usd_ci)