Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library(Quandl)
- library(xts)
- library(vars)
- library(lmtest)
- ### Data
- pGold <- Quandl("BUNDESBANK/BBK01_WT5511", start_date="2010-01-01")
- Gold <- xts(pGold$Value, order.by=pGold$Date)
- bitcoin <- Quandl("BITCOIN/BITSTAMPUSD")
- btc <- xts(bitcoin$'Weighted Price', order.by=bitcoin$Date)
- drop <- which(btc > 10**6)
- btc <- btc[-drop]; rm(drop)
- ### Plots
- par(mfrow=c(2,1))
- plot(log(btc))
- plot(log(Gold))
- plot(diff(log(btc)))
- plot(diff(log(Gold)))
- par(mfrow=c(1,1))
- ### Quick Granger Causality test
- # Use differences in logs
- d.l.Gold <- diff(log(Gold))
- d.l.btc <- diff(log(btc))
- dat <- na.omit(merge(d.l.Gold, d.l.btc))
- # Console output from here on:
- > VARselect(dat) # AIC: 4 lags
- $selection
- AIC(n) HQ(n) SC(n) FPE(n)
- 4 4 1 4
- $criteria
- 1 2 3 4 5 6 7 8 9 10
- AIC(n) -1.444529e+01 -1.445135e+01 -1.446099e+01 -1.448978e+01 -1.448490e+01 -1.448642e+01 -1.447868e+01 -1.447276e+01 -1.446438e+01 -1.445322e+01
- HQ(n) -1.442900e+01 -1.442419e+01 -1.442296e+01 -1.444088e+01 -1.442514e+01 -1.441579e+01 -1.439719e+01 -1.438041e+01 -1.436116e+01 -1.433914e+01
- SC(n) -1.440331e+01 -1.438139e+01 -1.436304e+01 -1.436384e+01 -1.433098e+01 -1.430451e+01 -1.426879e+01 -1.423488e+01 -1.419851e+01 -1.415937e+01
- FPE(n) 5.327073e-07 5.294907e-07 5.244134e-07 5.095320e-07 5.120251e-07 5.112516e-07 5.152244e-07 5.182883e-07 5.226560e-07 5.285245e-07
- > grangertest(formula = d.l.Gold ~ d.l.btc, data = dat, order=4) #***
- Granger causality test
- Model 1: d.l.Gold ~ Lags(d.l.Gold, 1:4) + Lags(d.l.btc, 1:4)
- Model 2: d.l.Gold ~ Lags(d.l.Gold, 1:4)
- Res.Df Df F Pr(>F)
- 1 634
- 2 638 -4 5.8054 0.0001362 ***
- ---
- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
- > grangertest(formula = d.l.btc ~ d.l.Gold, data = dat, order=4) #***
- Granger causality test
- Model 1: d.l.btc ~ Lags(d.l.btc, 1:4) + Lags(d.l.Gold, 1:4)
- Model 2: d.l.btc ~ Lags(d.l.btc, 1:4)
- Res.Df Df F Pr(>F)
- 1 634
- 2 638 -4 4.6772 0.0009999 ***
- ---
- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
- # Significant Granger Causality in both directions.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement