R : Copyright 2005, The R Foundation for Statistical Computing Version 2.2.1 (2005-12-20 r36812) ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > ################################################### > ### 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) t test of coefficients of "lm" object 'cny': Estimate Std. Error t value Pr(>|t|) (Intercept) -0.0047825 0.0029128 -1.6419 0.1056 usd.chf 0.9996533 0.0069072 144.7255 <2e-16 *** jpy.chf 0.0046678 0.0085870 0.5436 0.5886 eur.chf -0.0142383 0.0274245 -0.5192 0.6055 gbp.chf -0.0077435 0.0151516 -0.5111 0.6111 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 > sigma.ci(cny) [1] 0.02842637 0.02551732 0.03360208 > summary(cny)$r.squared [1] 0.9979257 > > ################################################### > ### 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 t test of coefficients of "lm" object 'inr': Estimate Std. Error t value Pr(>|t|) (Intercept) 0.052321 0.025509 2.0511 0.04442 * usd.chf 0.811575 0.076741 10.5756 1.348e-15 *** jpy.chf 0.014311 0.072159 0.1983 0.84343 eur.chf 0.227551 0.208535 1.0912 0.27934 gbp.chf 0.061851 0.111481 0.5548 0.58099 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 [1] 0.1860595 0.1407312 0.2488134 [1] 0.8951076 > coeftest(brl, vcov = kernHAC); sigma.ci(brl); summary(brl)$r.squared t test of coefficients of "lm" object 'brl': Estimate Std. Error t value Pr(>|t|) (Intercept) -0.17798 0.10960 -1.6239 0.109400 usd.chf 0.65994 0.23855 2.7665 0.007428 ** jpy.chf 0.64936 0.24476 2.6531 0.010082 * eur.chf 1.20286 0.51738 2.3249 0.023314 * gbp.chf -0.83704 0.39922 -2.0967 0.040044 * --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 [1] 0.9048157 0.7029596 1.1623728 [1] 0.3277262 > coeftest(rub, vcov = kernHAC); sigma.ci(rub); summary(rub)$r.squared t test of coefficients of "lm" object 'rub': Estimate Std. Error t value Pr(>|t|) (Intercept) -0.017041 0.028355 -0.6010 0.5500 usd.chf 0.978324 0.063660 15.3681 <2e-16 *** jpy.chf 0.062040 0.070268 0.8829 0.3806 eur.chf -0.047786 0.236284 -0.2022 0.8404 gbp.chf -0.041353 0.144234 -0.2867 0.7753 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 [1] 0.2311927 0.1879878 0.2947098 [1] 0.8770023 > coeftest(cad, vcov = kernHAC); sigma.ci(cad); summary(cad)$r.squared t test of coefficients of "lm" object 'cad': Estimate Std. Error t value Pr(>|t|) (Intercept) -0.058755 0.063638 -0.9233 0.359388 usd.chf 0.521775 0.149497 3.4902 0.000887 *** jpy.chf 0.045652 0.132893 0.3435 0.732351 eur.chf 0.881900 0.468206 1.8836 0.064240 . gbp.chf 0.208285 0.266179 0.7825 0.436851 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 [1] 0.4553024 0.4033540 0.5423728 [1] 0.5183542 > coeftest(mxn, vcov = kernHAC); sigma.ci(mxn); summary(mxn)$r.squared t test of coefficients of "lm" object 'mxn': Estimate Std. Error t value Pr(>|t|) (Intercept) 0.002222 0.053322 0.0417 0.96689 usd.chf 0.836774 0.134035 6.2430 4.083e-08 *** jpy.chf 0.216675 0.107660 2.0126 0.04844 * eur.chf -0.050756 0.309246 -0.1641 0.87016 gbp.chf -0.101167 0.211709 -0.4779 0.63440 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 [1] 0.4104059 0.3670848 0.4873315 [1] 0.6544031 > coeftest(krw, vcov = kernHAC); sigma.ci(krw); summary(krw)$r.squared t test of coefficients of "lm" object 'krw': Estimate Std. Error t value Pr(>|t|) (Intercept) 0.0025918 0.0310067 0.0836 0.9336483 usd.chf 0.4114616 0.0768342 5.3552 1.280e-06 *** jpy.chf 0.3420887 0.0882784 3.8751 0.0002565 *** eur.chf 0.4940600 0.2567651 1.9242 0.0588529 . gbp.chf 0.1069089 0.1201347 0.8899 0.3769009 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 [1] 0.2575319 0.2287249 0.3128380 [1] 0.7429827 > coeftest(idr, vcov = kernHAC); sigma.ci(idr); summary(idr)$r.squared t test of coefficients of "lm" object 'idr': Estimate Std. Error t value Pr(>|t|) (Intercept) 0.0356784 0.1113871 0.3203 0.7498 usd.chf 0.4429601 0.3581159 1.2369 0.2207 jpy.chf -0.0098777 0.2653777 -0.0372 0.9704 eur.chf 0.8818769 0.7258147 1.2150 0.2289 gbp.chf 0.6223178 0.5363549 1.1603 0.2503 [1] 0.8974704 0.6996856 1.2263142 [1] 0.2374942 > > ################################################### > ### 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) M-fluctuation test data: scus f(efp) = 1.1925, p-value = 0.524 > 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 Monitoring of Frankel-Wei regression -------------------------------------------------------- Formula: cny.chf ~ usd.chf + jpy.chf + eur.chf + gbp.chf History period: 2005-07-26 to 2005-10-31 Break detected: 2006-03-24 -------------------------------------------------------- >