\documentclass[11pt]{article}

\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{amsfonts,amssymb,amsmath}
\usepackage{undertilde}
\usepackage{../MATH545}
\usepackage{enumitem}
\usepackage{booktabs}
\usepackage{bm}
\usepackage{hyperref}

\parindent 0in
\pagestyle{empty}

\def\ExNumber{4}

\lfoot{MATH 545 EXERCISES \ExNumber~Solutions} \cfoot{ } \rfoot{{\small{\em
Page \thepage \ of \pageref{LastPage}}}}

\renewcommand{\headrulewidth}{0.0pt}
\renewcommand{\footrulewidth}{0.0pt}

\def\ctitle{MATH 545: Introduction to Time Series Analysis}
\def\ttitle{Winter 2025}
\def\stitle{Exercises \ExNumber: Solutions}

\begin{document}
\pagestyle{fancy}

\maketitle


<<setup, cache=FALSE, echo=FALSE>>=
library(knitr)
library(kableExtra)
suppressMessages(library(dplyr))
# global chunk options
opts_chunk$set(cache=TRUE, autodep=TRUE)
options(scipen=999)
options(repos=c(CRAN="https://cloud.r-project.org/"))
@

<<Q0, echo=FALSE>>=
set.seed(11)
myrnd <- function(x,d) {formatC(x, format="f", digits=d)}
@

\begin{enumerate}[label=\arabic*.,itemsep=0.2in]



\item \textit{As quoted in lectures, an absolutely summable function $\gamma(h)$ is the ACVF for a stationary process if and only if it is even and
    \[
    f(\lambda) = \frac{1}{2 \pi} \sum_{h=-\infty}^\infty e^{-\imagi h \lambda} \gamma(h) \geq 0 
    \]
    for all $\lambda$ in the interval $(-\pi,\pi]$.  Use this result to assess whether the function
    \[
    \gamma(h) = \left\{ 
    \begin{array}{rl}
    1 & h=0 \\[6pt]
    -0.5 & h= \pm 2\\[6pt]
    -0.25 & h= \pm 3\\[6pt]
    0 & \text{otherwise}
    \end{array}
    \right.
    \]
    is the ACVF of a stationary process.}
    
\textbf{Solution:}  By direct calculation
    \begin{align*}
    f(\lambda)  = \frac{1}{2 \pi} \sum_{h=-\infty}^\infty e^{-\imagi h \lambda} \gamma(h) & = \frac{1}{2 \pi} \left[ 1 - 0.5 (e^{-\imagi 2 \lambda} + e^{\imagi 2 \lambda}) - 0.25 (e^{-\imagi 3 \lambda} + e^{\imagi 3 \lambda}) \right] \\[6pt]
     & = \frac{1}{2 \pi} \left[ 1 - \cos (2 \lambda) - 0.5 \cos(3 \lambda) \right]
    \end{align*}
    This function is not non-negative as (for example) $f(0) = -0.5$.  Therefore, $\gamma(.)$ is not the ACVF of a stationary process.  
    
<<Ex4-Q1-0,fig.height=4>>=
lam<-seq(-pi,pi,length=1000)
flam<-(1-cos(2*lam)-0.5*cos(3*lam))/(2*pi)
par(mar=c(4,4,2,2))
plot(lam,flam,type='l',ylim=range(-0.5,0.5),
    xlab=expression(lambda),ylab=expression(f(lambda)))
    abline(h=0,lty=3)
@
    
    If instead we had
    \[
    \gamma(h) = \left\{ 
    \begin{array}{rl}
    1 & h=0 \\[6pt]
    -0.25 & h= \pm 2\\[6pt]
    -0.125 & h= \pm 3\\[6pt]
    0 & \text{otherwise}
    \end{array}
    \right.
    \]
    then the equivalent calculation leads to
    \[
    f(\lambda) = \frac{1}{2 \pi} \left[ 1 - 0.5 \cos (2 \lambda) - 0.25 \cos(3 \lambda) \right]
    \]
    which is non-negative and even, so this is a valid ACVF. Using a discrete approximation, we can simulate a process with this ACVF/SDF.  Let 
    \[
    \{\omega_j = \pi (j/J) \qquad j=0,\ldots,J \}
    \]
    and
    \[
    \sigma_j^2 = \frac{1}{2 \pi} \left[ 1 - 0.5 \cos (2 \omega_j) - 0.25 \cos(3 \omega_j) \right]
    \]
    and then define
    \[
    X_t = \int_{-\pi}^\pi [\cos(t \lambda) + \imagi \sin (t \lambda)] \ dZ(\lambda)
    \]

    
<<Ex4-Q1-1,fig.height=4>>=
lam<-seq(-pi,pi,length=1000)
flam<-(1-0.5*cos(2*lam)-0.25*cos(3*lam))/(2*pi)
par(mar=c(4,4,2,0))
plot(lam,flam,type='l',ylim=range(-0.5,0.5),
    xlab=expression(lambda),ylab=expression(f(lambda)))
    abline(h=0,lty=3)
@

<<Ex4-Q1-2,fig.height=4>>=
k<-500
lam<-seq(-pi,pi,by=0.01)
omega<-c(0:k)*pi/k
sigsq<-(1/k)*(1-0.5*cos(2*omega)-0.25*cos(3*omega))
sum(sigsq[2:k])+0.5*(sigsq[1]+sigsq[k+1])
hvec<-c(0:25)
gammah<-0.5*sigsq[1]*cos(omega[1]*hvec)
for(j in 2:k){
    gammah<-gammah+sigsq[j]*cos(omega[j]*hvec)
}
gammah<-gammah+0.5*sigsq[k+1]*cos(omega[k+1]*hvec)
round(gammah,6)
@

<<Ex4-Q1-3,fig.height=4>>=
Uvec<-rnorm(k+1)*sqrt(sigsq)
Vvec<-rnorm(k+1)*sqrt(sigsq)
tvec<-seq(0,500,by=1)
Xt<-tvec*0
for(j in 1:(k+1)){
    Xt<-Xt+Uvec[j]*cos(omega[j]*tvec)+Vvec[j]*sin(omega[j]*tvec)
}
par(mar=c(4,4,2,2))
plot(tvec,Xt,type='l',xlab='t',ylab=expression(X[t]),ylim=range(-3,3))
acf(Xt)
points(hvec,gammah,pch=19,cex=0.7,col='red')
@

\pagebreak

\item \textit{Suppose $X_{1,t}$ and $X_{2,t}$ are independent stationary processes with ACVFs $\gamma_1(h)$ and $\gamma_2(h)$, and corresponding spectral density functions (SDFs) $f_1(\lambda)$ and $f_2(\lambda)$, respectively.}
    
    \medskip
    \textit{Derive the SDF of 
    \[
    X_1 = X_{1,t} + X_{2,t}.
    \]}

\textbf{Solution:}  We have that
\[
\gamma_X(h) = \E[X_t X_{t+h}] = \E[(X_{1,t} + X_{2,t})(X_{1,t+h} + X_{2,t+h})] = \E[X_{1,t} X_{1,t+h}] + \E[X_{2,t} X_{2,t+h}]
\]
by independence.  Hence 
\[
\gamma_X(h) = \gamma_1(h) + \gamma_2(h)
\]
and
\begin{align*}
f_X(\lambda) & = \frac{1}{2 \pi} \sum_{h=-\infty}^\infty e^{-\imagi h \lambda} \gamma(h) \\[6pt]
& = \frac{1}{2 \pi} \sum_{h=-\infty}^\infty e^{-\imagi h \lambda} ( \gamma_1(h) + \gamma_2(h) ) \\[6pt]
& = \frac{1}{2 \pi} \sum_{h=-\infty}^\infty e^{-\imagi h \lambda} \gamma_1(h)  + \frac{1}{2 \pi} \sum_{h=-\infty}^\infty e^{-\imagi h \lambda} \gamma_2(h) \\[6pt]
& = f_1(\lambda) + f_2(\lambda).
\end{align*}




\item\textit{ Derive the SDF of the stationary process $\{X_t\}$ defined by
\[
X_t = A \cos (\omega t) + B \sin (\omega t) + Z_t + 2 Z_{t-1}
\]
where
\begin{itemize}
  \item $A$ and $B$ are zero mean random variables with variance 1;
  \item $\omega \in (0,\pi/2)$ is a fixed constant;
  \item $\{Z_{t}\} \sim \WN(0,\sigma_Z^2)$;
  \item $A$, $B$ and $\{Z_t\}$ are mutually uncorrelated.
\end{itemize}}

\textbf{Solution:}  Using the result from Q2, with
\[
f_1(\lambda) = \left\{
\begin{array}{cl}
\dfrac{1}{2} & \lambda = -\omega\\[12pt]
\dfrac{1}{2} & \lambda = \omega\\[12pt]
0 & \text{otherwise}
\end{array}
\right.
\]
and 
\[
f_2(\lambda) =  \frac{\sigma_Z^2}{2 \pi} |(1+2 e^{-\imagi \lambda})|^2 =  \frac{\sigma_Z^2}{2 \pi}[1 + 4(1+ \cos(\lambda))]
\]
which is the SDF of the $\MA(1)$ process with $\theta=2$.  Then
\[
f_X(\lambda) = f_1(\lambda) + f_2(\lambda)
\]
is the SDF of $\{X_t\}$.  It is an SDF of mixed type.

\item \textit{Suppose that
\[
X_t = 0.99 X_{t-3} + Z_t
\]
where $\{Z_t\} \sim \WN(0,1)$.  Find and plot the SDF for $\{X_t\}$, and the SDF of
\[
Y_t = \frac{1}{3} (X_{t-1} + X_t + X_{t+1}).
\]}

\textbf{Solution:} Here we have an $\AR(3)$ process with $\phi_1 = \phi_2 = 0$.  The $\AR$ polynomial is
\[
\Phi(z) = 1 - 0.99 z^3
\]
which has reciprocal roots less than 1 in modulus so the process is stationary and has SDF
\[
f_X(\lambda) = \frac{1}{2 \pi} \frac{1}{|1-0.99 e^{-\imagi 3 \lambda}|^2}
\]

<<Ex4-Q4-1,fig.height=4>>=
Mod(polyroot(c(1,0,0,-0.99)))    #Roots
1/Mod(polyroot(c(1,0,0,-0.99)))  #Reciprocal roots

lam<-seq(-pi,pi,length=1000)
flam<-(1/Mod(1-0.99*exp(-1i*3*lam))^2)/(2*pi)
par(mar=c(4,4,1,0))
plot(lam,flam,type='l',xlab=expression(lambda),ylab=expression(f(lambda)))
@

Now let $\{Y_t\}$ be the filtered version of $\{X_t\}$ given by
\[
Y_t = \frac{1}{3} (X_{t-1} + X_t + X_{t+1}) = \sum_{j=-\infty}^\infty \psi_j X_{t-j} = \Psi(B) X_t
\]
where $\psi_j = 1/3$ for $j=-1,0,1$, and $\psi_j = 0$ otherwise.  Then
\[
f_Y(\lambda) = |\Psi(e^{-\imagi \lambda})|^2  f_X(\lambda) = \left(\frac{1}{3}\right)^2 |1 + e^{\imagi \lambda} +  e^{-\imagi \lambda}|^2 f_X(\lambda)
\]
<<Ex4-Q4-2,fig.height=4.5>>=
lam<-seq(-pi,pi,length=1000)
flam<-(1/Mod(1-0.99*exp(-1i*3*lam))^2)/(2*pi)
flam<-flam*(1/9)*Mod(1+exp(1i*lam)+exp(-1i*lam))^2
par(mar=c(4,4,2,0))
plot(lam,flam,type='l',xlab=expression(lambda),ylab=expression(f(lambda)))
@

<<Ex4-Q4-3,fig.height=4.35>>=
set.seed(3)
n<-500
Xt<-arima.sim(n,model=list(ar=c(0,0,0.99)))
par(mar=c(4,4,1,0))
plot(Xt,type='l')
acf(Xt,lag.max=50)
Yt<-Xt
Yt[1]<-(Xt[1]+Xt[2])/2; Yt[n]<-(Xt[n-1]+Xt[n])/2
for(i in 2:(n-1)){Yt[i]<-mean(Xt[c((i-1):(i+1))])}
par(mar=c(4,4,3,0))
plot(Yt,type='l')
acf(Yt,lag.max=50)
spectrum(Xt,demean=F,taper=0,main='Periodogram for Xt')
abline(v=1/3,col='red')
spectrum(Yt,demean=F,taper=0,main='Periodogram for Yt')
@

\item \textit{The fractional white noise process, $\{W_t\}$, defined in terms of the white noise process $\{Z_t\}$ by
\[
W_t = (1-B)^{-d} Z_t
\]
for $-0.5 < d < 0.5$ has SDF
\[
f_W(\lambda) = \frac{\sigma_Z^2}{2 \pi} \frac{1}{|1-e^{-\imagi \lambda}|^{2d}}.
\]
Comment on the absolute summability of the corresponding ACVF, $\gamma_W(h)$.}

\medskip

\textbf{Solution:} From lectures, we have the formula that for large $h > 0$
\[
\gamma_W(h) \approx C h^{2d - 1}
\]
for some constant $C$. The value $2d - 1$ lies in the range $(-2,0)$, so it is evident that if $d < 0$, then $2d - 1 < -1$, and $\gamma_W(h)$ is absolutely summable, whereas if $d > 0$, $ -1 < 2 d - 1 < 0$ it is not; this follows as the sum
\[
\sum_{h=1}^\infty h^{-\alpha}
\]
is convergent if and only if $\alpha > 1$.

\medskip
Note that for $h$ large enough
\[
\log \gamma_W(h) = \log C + (2d-1) \log h
\]
so plotting $\log \gamma_W(h)$ versus $\log h$ will lead to a straight line with slope $2d - 1$.  For $d=0.4$,

<<Ex4-Q5-1,fig.height=5>>=
H<-1000
hvec<-c(1:H)
d<-0.4
gamma0<-gamma(1-2*d)/gamma(1-d^2)
gammah<-gamma0*exp(lgamma(hvec+d)+lgamma(1-d)-lgamma(hvec-d+1)-lgamma(d))
gammah[H]
sum(abs(c(gamma0,gammah)))

cumsum(gammah)[100*c(1:10)]
par(mar=c(4,4,2,2))
plot(log(hvec), log(gammah),pch=19,cex=0.2,
    xlab='log(h)',ylab=expression(log(gamma[X](h))))
lm(log(gammah)~log(hvec))
@
Here the slope is $-0.2$.  For $d=-0.1$, the slope is -1.2.

<<Ex4-Q5-2,fig.height=5>>=
d<--0.1
gamma0<-gamma(1-2*d)/gamma(1-d^2)
gammah<-gamma0*exp(lgamma(hvec+d)+lgamma(1-d)-lgamma(hvec-d+1)-lgamma(d))
gammah[H]
sum(abs(c(gamma0,gammah)))

cumsum(gammah)[100*c(1:10)]

par(mar=c(4,4,2,2))
plot(log(hvec), log(gammah),pch=19,cex=0.2,
    xlab='log(h)',ylab=expression(log(gamma[X](h))))
lm(log(gammah)~log(hvec))
@
Therefore for $d > 0$, the ACVF converges slow enough so that the sum of its absolute values is divergent.  This renders the use of the frequency-domain approach to inference based on the SDF is more palatable than time-domain approach.

\end{enumerate}



\end{document}
