---
title: "Exchange Rate Regime Analysis for the Chinese Yuan"
author: "Achim Zeileis, Ajay Shah, Ila Patnaik"
output:
  rmarkdown::html_vignette:
    highlight: monochrome
abstract: >
  We investigate the Chinese exchange rate regime after China gave up
  on a fixed exchange rate to the US dollar in 2005. This reproduces
  the analysis from @fxregime initiated by @cny. Please refer
  to these papers for a more detailed discussion.
bibliography: fxregime.bib
vignette: >
  %\VignetteIndexEntry{Exchange Rate Regime Analysis for the Chinese Yuan}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteDepends{graphics, stats, zoo, sandwich, strucchange}
  %\VignetteKeywords{CNY, foreign exchange rates, structural change, monitoring, dating}
  %\VignettePackage{fxregime}
---

```{r cleanup, include=FALSE}
cleanup <- TRUE
library("fxregime")
knitr::opts_chunk$set(
  engine = "R",
  collapse = TRUE,
  comment = "##",
  message = FALSE,
  warning = FALSE,
  echo = TRUE
)
```

## Analysis

Exchange rate regime analysis is based on a linear regression model
for cross-currency returns. A large data set derived from exchange
rates available online from the US Federal Reserve
at <https://www.federalreserve.gov/releases/h10/Hist/> is
provided in the `FXRatesCHF` data set in `fxregime`.

```{r preliminaries}
library("fxregime")
data("FXRatesCHF", package = "fxregime")
```

It is a `zoo` series containing `r ncol(FXRatesCHF)` daily time series from
`r start(FXRatesCHF)` to `r end(FXRatesCHF)`. The columns correspond to the prices for various
currencies (in ISO 4217 format) with respect to CHF as the unit currency.

In the following, we investigate the exchange rate regime for the
Chinese yuan CNY which was fixed to the US dollar USD in the years leading
up to mid-2005. In July 2005, China announced a small appreciation of CNY,
and, in addition, a reform of the exchange rate regime.  The People's
Bank of China (PBC) announced this reform to involve a shift away from
the fixed exchange rate to a basket of currencies with greater
flexibility. In August 2005, PBC also announced that USD, JPY, EUR and KRW
would be the currencies in this basket. Further currencies announced to be
of interest are GBP, MYR, SGD, RUB, AUD, THB and CAD.

Despite the announcements of the PBC, little evidence could be found for China moving
away from a USD peg in the months after July 2005 [@cny].
To begin our investigation here, we follow up on our own analysis from autumn 2005: Using
daily returns for the first three months after the announcement, we establish a stable exchange
regression and monitor it in the subsequent months.
The currencies considered by @fxregime
are a basket of the most important floating currencies (USD, JPY, EUR, GBP).
The returns can be extracted from `FXRatesCHF` and pre-processed via

```{r cny-data}
cny <- fxreturns("CNY", frequency = "daily",
  start = as.Date("2005-07-25"), end = as.Date("2009-07-31"),
  other = c("USD", "JPY", "EUR", "GBP"), data = FXRatesCHF)
```

In a first step, we fit the exchange regression for these
first three months after the announcements of the PBC.

```{r cny-fitting}
cny_lm <- fxlm(CNY ~ USD + JPY + EUR + GBP,
  data = window(cny, end = as.Date("2005-10-31")))
summary(cny_lm)
```

Only the USD coefficient differing significantly from 0 (but not significantly
from 1), thus signalling a very clear USD peg. The $R^2$ of the regression is
`r round(100 * summary(cny_lm)$r.squared, digits = 1)`% due to the extremely 
low standard deviation of $\sigma = `r round(sqrt(tail(coef(cny_lm), 1)), digits = 3)`$.
(Note that we use the un-adjusted estimate of $\sigma$, rather than the adjusted
version reported in the `summary()` above.)

To capture the fluctuation in the parameters during this history period, we compute
the associated empirical fluctuation process

```{r cny-testing}
cny_efp <- gefp(cny_lm, fit = NULL)
```

that can be visualized (along with the boundaries for the double maximum test) by

```{r cny-hprocess, fig.height=11.3, fig.width=9, fig.cap="Historical fluctuation process for CNY exchange rate regime."}
plot(cny_efp, aggregate = FALSE, ylim = c(-1.85, 1.85))
```

This shows that the fluctuation in the parameters during
this history period is very small and non-significant:

```{r cny-sctest}
sctest(cny_efp)
```

The same fluctuation process can be continued in the monitoring period to check
whether future observations still conform with the established model. Using a linear
boundary, derived at 5% significance level (for potentially monitoring up to $T = 4$), this
can be performed via:

```{r cny-fxmonitor, fig.height=9, fig.width=9, fig.cap="Monitoring fluctuation process for CNY exchange rate regime."}
cny_mon <- fxmonitor(CNY ~ USD + JPY + EUR + GBP,
  data = window(cny, end = as.Date("2006-05-31")),
  start = as.Date("2005-11-01"), end = 4)
plot(cny_mon, aggregate = FALSE)
```

In the first months, up to spring 2006, there is still
moderate fluctuation in all processes signalling no departure from the previously established
USD peg. In fact, the only larger deviation during that time period is surprisingly a _decrease_ in the
variance---corresponding to a somewhat tighter USD peg---which almost leads to a boundary
crossing in January 2006. However, the situation relaxes a bit before in the next weeks before in
March 2006 the variance component of the fluctuation process starts to deviate clearly from its mean.
However, none of the coefficients deviates from its zero mean, signalling that there was
no significant change in the currency weights. The change occurs in

```{r cny-monitorbreak}
cny_mon
```

To capture the changes in the China's exchange rate regime more formally, we fit a segmented
exchange rate regression based on the full extended data set:

```{r cny-dating, eval=FALSE}
cny_reg <- fxregimes(CNY ~ USD + JPY + EUR + GBP,
  data = cny, h = 20, breaks = 10)
```

```{r cny-dating1, echo=FALSE}
if(file.exists("cny_reg.rda")) load("cny_reg.rda") else {
<<cny-dating>>
save(cny_reg, file = "cny_reg.rda")
}
if(cleanup) file.remove("cny_reg.rda")
```


We determine the optimal breakpoints for $1, \dots, 10$ breaks with a minimal segment
size of $20$ observations and compute the associated segmented negative log-likelihood
(NLL) and LWZ criterion. Both can be visualized via

```{r cny-breaks, fig.height=5, fig.width=6, fig.cap="Negative log-likelihood and LWZ information criterion for CNY exchange rate regimes."}
plot(cny_reg)
```

NLL decreases with every additional break but with a marked decrease only for going from 0
to 1~break. This is also reflected in the LWZ criterion that assumes its minimum for
`r length(breakdates(cny_reg))`~break
so that we choose a `r length(breakdates(cny_reg))`-break
(or `r length(breakdates(cny_reg))+1`-segment) model.
The estimated breakpoint is `r breakdates(cny_reg)`, i.e., shortly before
the boundary crossing in the monitoring procedure, confirming the findings above. 
The confidence interval for the break can be obtained by

```{r cny-confint}
confint(cny_reg, level = 0.9)
```

showing that the end of the low variance period can be
determined more precisely than the start of the high variance period.
The parameter estimates for both segments can be obtained by

```{r cny-coef}
coef(cny_reg)
```

A complete summary can be computed by first re-fitting the model on both sub-samples
(returning a list of ```fxlm`'' objects) and then applying the usual `summary()`:

```{r cny-refit}
cny_rf <- refit(cny_reg)
lapply(cny_rf, summary)
```

These results allow
for several conclusions about the Chinese exchange rate regime after spring 2006: 
CNY was still closely linked to USD. The exchange rate regime got much
more flexible increasing from $\sigma = `r round(sqrt(tail(coef(cny_rf[[1]]), 1)), digits = 3)`$
to $`r round(sqrt(tail(coef(cny_rf[[2]]), 1)), digits = 3)`$ which is still very low, even
compared with other pegged exchange rate regimes (see the results for India
in `vignette("INR", package = "fxregime")`). The intercept
was clearly smaller than 0, reflecting a slow appreciation of the CNY
and thus signalling a modest liberation of the rigid USD peg in spring 2006.
Towards the end of 2008, the modest liberation was abandoned again and since
2009 the exchange rate regime is again an extremely tight USD peg without appreciation.


## Summary {#sec:summary}

For the Chinese yuan, a 4-segment model is found for the time after
July 2005 when China gave up on a fixed exchange rate to the
USD. While being closely linked to USD in all periods, there
had been small steps in the direction of the claims of the Chinese
central bank: flexibility slightly increased while the weight of the
USD in the currency basket slightly decreased. However, these steps
were reversed again towards the end of 2008.


## References
