\documentclass[a4paper,11pt]{article}
\usepackage{amsfonts,amstext,amsmath}
\usepackage[authoryear,round,longnamesfirst]{natbib}
\usepackage{graphicx,a4,ae,color,fancyvrb}
\usepackage{hyperref}

\oddsidemargin 0.1 in
\evensidemargin 0.15 in
\marginparwidth 1 in
\oddsidemargin 0.125 in
\evensidemargin 0.125 in
\marginparwidth 0.75 in
\textwidth 6.125 in

%% instead of \usepackage{Sweave}
\usepackage[T1]{fontenc}
\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontshape=sl}
\DefineVerbatimEnvironment{Soutput}{Verbatim}{}
\DefineVerbatimEnvironment{Scode}{Verbatim}{fontshape=sl}
\newenvironment{Schunk}{}{}
\setkeys{Gin}{width=0.8\textwidth}
\SweaveOpts{engine=R, eps=FALSE, keep.source = TRUE}

%% paragraphs
\setlength{\parskip}{0.7ex plus0.1ex minus0.1ex}
\setlength{\parindent}{0em}

%% commands
\newcommand{\ddquote}[1]{``#1''}
\newcommand{\darrow}{\stackrel{\mbox{\tiny \textnormal{d}}}{\longrightarrow}}
\newcommand{\parrow}{\stackrel{\mbox{\tiny \textnormal{p}}}{\longrightarrow}}
\newcommand{\given}{\, | \,}
\newcommand{\argmin}{\operatorname{argmin}\displaylimits}
\newcommand{\efp}{\mathit{efp}}
\newcommand{\nll}{\mathit{nll}}
\newcommand{\NLL}{\mathit{NLL}}
\let\proglang=\textsf
\let\pkg=\textbf
\let\code=\texttt

\begin{document}

\title{\bf Exchange Rate Regime Analysis for the Chinese Yuan}
\author{Achim Zeileis \and Ajay Shah \and Ila Patnaik}
\date{}
\maketitle

\begin{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 \cite{fxr:Zeileis+Shah+Patnaik:2010}
  initiated by \cite{fxr:Shah+Zeileis+Patnaik:2005}. Please refer
  to these papers for a more detailed discussion.
\end{abstract}

%\VignetteIndexEntry{Exchange Rate Regime Analysis for the Chinese Yuan}
%\VignetteDepends{graphics, stats, zoo, sandwich, strucchange}
%\VignetteKeywords{CNY, foreign exchange rates, structural change, monitoring, dating}
%\VignettePackage{fxregime}


<<cleanup, echo=FALSE>>=
cleanup <- TRUE
@

\section{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 \url{http://www.federalreserve.gov/releases/h10/Hist/} is
provided in the \code{FXRatesCHF} data set in \pkg{fxregime}.

<<preliminaries>>=
library("fxregime")
data("FXRatesCHF", package = "fxregime")
@

It is a ``\code{zoo}'' series containing \Sexpr{ncol(FXRatesCHF)} daily time series from
\Sexpr{start(FXRatesCHF)} to \Sexpr{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 \citep{fxr:Shah+Zeileis+Patnaik:2005}.
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 \cite{fxr:Zeileis+Shah+Patnaik:2010}
are a basket of the most important floating currencies (USD, JPY, EUR, GBP).
The returns can be extracted from \code{FXRatesCHF} and pre-processed via

<<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.

<<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
\Sexpr{round(100 * summary(cny_lm)$r.squared, digits = 1)}\% due to the extremely 
low standard deviation of $\sigma = \Sexpr{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 \code{summary()} above.)

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

<<cny-testing>>=
cny_efp <- gefp(cny_lm, fit = NULL)
@

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

<<cny-hprocess, eval=FALSE>>=
plot(cny_efp, aggregate = FALSE, ylim = c(-1.85, 1.85))
@

\setkeys{Gin}{width=\textwidth}
\begin{figure}[p]
\begin{center}
<<cny-hprocess1, fig=TRUE, height=11.3, width=9, echo=FALSE>>=
<<cny-hprocess>>
@
\caption{\label{fig:cny-hprocess} Historical fluctuation process for CNY exchange rate regime.}
\end{center}
\end{figure}

Figure~\ref{fig:cny-hprocess} shows that the fluctuation in the parameters during
this history period is very small and non-significant:

<<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

<<cny-monitoring, eval=FALSE>>=
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)
@

\setkeys{Gin}{width=\textwidth}
\begin{figure}[t!]
\begin{center}
<<cny-mprocess, fig=TRUE, height=9, width=9, echo=FALSE>>=
<<cny-monitoring>>
@
\caption{\label{fig:cny-mprocess} Monitoring fluctuation process for CNY exchange rate regime.}
\end{center}
\end{figure}

yielding the visualization in Figure~\ref{fig:cny-mprocess}.
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 \emph{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

<<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:

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

<<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

<<cny-breaks, eval=FALSE>>=
plot(cny_reg)
@

\setkeys{Gin}{width=0.75\textwidth}
\begin{figure}[t]
\begin{center}
<<cny-breaks1, fig=TRUE, height=5, width=6, echo=FALSE>>=
<<cny-breaks>>
@
\caption{\label{fig:cny-breaks} Negative log-likelihood and LWZ information
  criterion for CNY exchange rate regimes.}
\end{center}
\end{figure}

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
\Sexpr{length(breakdates(cny_reg))}~break
so that we choose a \Sexpr{length(breakdates(cny_reg))}-break
(or \Sexpr{length(breakdates(cny_reg))+1}-segment) model.
The estimated breakpoint is \Sexpr{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

<<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

<<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 ``\code{fxlm}'' objects) and then applying the usual \code{summary()}:

<<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 = \Sexpr{round(sqrt(tail(coef(cny_rf[[1]]), 1)), digits = 3)}$
to $\Sexpr{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 India
in \code{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.


\section{Summary} \label{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.

\begin{thebibliography}{2}
\newcommand{\enquote}[1]{``#1''}
\providecommand{\natexlab}[1]{#1}
\providecommand{\url}[1]{\texttt{#1}}
\providecommand{\urlprefix}{URL }
\expandafter\ifx\csname urlstyle\endcsname\relax
  \providecommand{\doi}[1]{doi:\discretionary{}{}{}#1}\else
  \providecommand{\doi}{doi:\discretionary{}{}{}\begingroup
  \urlstyle{rm}\Url}\fi
\providecommand{\eprint}[2][]{\url{#2}}

\bibitem[{Shah \emph{et~al.}(2005)Shah, Zeileis, and
  Patnaik}]{fxr:Shah+Zeileis+Patnaik:2005}
Shah A, Zeileis A, Patnaik I (2005).
\newblock \enquote{What is the New Chinese Currency Regime?}
\newblock \emph{Report~23}, Department of Statistics and Mathematics,
  WU Wirtschaftsuniversit\"at Wien, Research Report Series.
\newblock
  \urlprefix\url{http://epub.wu.ac.at/}.

\bibitem[{Zeileis \emph{et~al.}(2010)Zeileis, Shah, and
  Patnaik}]{fxr:Zeileis+Shah+Patnaik:2010}
Zeileis A, Shah A, Patnaik I (2010).
\newblock \enquote{Testing, Monitoring, and Dating Structural Changes
  in Testing, Monitoring, and Dating Structural Changes in Exchange Rate Regimes.}
\newblock \emph{Computational Statistics \& Data Analysis}, \textbf{54}(6), 1696--1706.
\newblock \doi{10.1016/j.csda.2009.12.005}.
\end{thebibliography}

\end{document}
