################################################### ### load packages and Frankel-Wei tools ################################################### library("zoo") library("sandwich") library("strucchange") library("lmtest") library("boot") source("fw_regression.R") ################################################### ### read log-returns from .csv file ################################################### returns <- read.zoo("currencies.csv", format = "%Y-%m-%d", sep = ",", header = TRUE) returns <- mreturns <- window(returns, start = as.Date("2005-07-26")) returns <- window(returns, end = as.Date("2005-10-31")) retdat <- as.data.frame(returns) ################################################### ### convenience functions for bootstrapping sigma ################################################### sigma <- function(obj) sqrt(sum(residuals(obj)^2)/length(residuals(obj))) sigma.ci <- function(obj, R = 1000) { b <- boot(model.frame(obj), function(x, d) sigma(lm(formula(obj), x[d,])), R = R) b <- boot.ci(b, type = "basic") return(c(b$t0, b$basic[4:5])) } set.seed(20050721) ################################################### ### Frankel-Wei regression for China ################################################### cny <- lm(cny.chf ~ usd.chf + jpy.chf + eur.chf + gbp.chf, data = retdat) coeftest(cny, vcov = kernHAC) sigma.ci(cny) summary(cny)$r.squared ################################################### ### further regressions for all the currencies ################################################### inr <- lm(inr.chf ~ usd.chf + jpy.chf + eur.chf + gbp.chf, data = retdat) brl <- lm(brl.chf ~ usd.chf + jpy.chf + eur.chf + gbp.chf, data = retdat) rub <- lm(rub.chf ~ usd.chf + jpy.chf + eur.chf + gbp.chf, data = retdat) cad <- lm(cad.chf ~ usd.chf + jpy.chf + eur.chf + gbp.chf, data = retdat) mxn <- lm(mxn.chf ~ usd.chf + jpy.chf + eur.chf + gbp.chf, data = retdat) krw <- lm(krw.chf ~ usd.chf + jpy.chf + eur.chf + gbp.chf, data = retdat) idr <- lm(idr.chf ~ usd.chf + jpy.chf + eur.chf + gbp.chf, data = retdat) coeftest(inr, vcov = kernHAC); sigma.ci(inr); summary(inr)$r.squared coeftest(brl, vcov = kernHAC); sigma.ci(brl); summary(brl)$r.squared coeftest(rub, vcov = kernHAC); sigma.ci(rub); summary(rub)$r.squared coeftest(cad, vcov = kernHAC); sigma.ci(cad); summary(cad)$r.squared coeftest(mxn, vcov = kernHAC); sigma.ci(mxn); summary(mxn)$r.squared coeftest(krw, vcov = kernHAC); sigma.ci(krw); summary(krw)$r.squared coeftest(idr, vcov = kernHAC); sigma.ci(idr); summary(idr)$r.squared ################################################### ### HAC-corrected Nyblom-Hansen test on historical data for CNY ################################################### scus <- gefp(cny.chf ~ usd.chf + jpy.chf + eur.chf + gbp.chf, data = as.data.frame(returns), fit = fw_lm, vcov = function(x, ...) kernHAC(x, sandwich = FALSE), sandwich = FALSE, order.by = time(returns)) sctest(scus) plot(scus, aggregate = FALSE, xlab = "Time", main = "") ################################################### ### Monitoring ################################################### mon <- fw_monitor(cny.chf ~ usd.chf + jpy.chf + eur.chf + gbp.chf, data = mreturns, monitor = as.Date("2005-10-31")) plot(mon, main = "") mon