# 5. Consider the MA(4) model with ρ1 = 0.8, ρ2 = 0.6, ρ3 = 0.4 and ρ4 = 0.2.
# a) Sketch the ACF plot.
# b) Now, let θ1 = 0.8, θ2 = 0.6, θ3 = 0.4 and θ4 = 0.2. Generate n= 150 observations of this MA(4) time series. Then, compute and plot the sample autocorrelation function.

library(TSA)
## 
## Attaching package: 'TSA'
## The following objects are masked from 'package:stats':
## 
##     acf, arima
## The following object is masked from 'package:utils':
## 
##     tar
a=c(0.8,0.6,0.4,0.2)
plot(a,type='h',col='blue',ylim=0:1,xlab="Lags",ylab=expression(rho) ,lwd=2)

set.seed(2424)
w=rnorm(200,0,1)
MA4=vector(length=150)
theta1=.8
theta2=.6
theta3=.4
theta4=.2
for(i in 1:150)
{MA4[i]=w[50+i]-(theta1*w[50+i-1])-(theta2*w[50+i-2])-(theta3*w[50+i-3])-(theta4*w[50+i-4])
  }
par(mfrow=c(1,2))
plot(time(MA4), MA4,ylab=expression(Y[t]), xlab='Time',type='o',col='blue',lwd=2)
acf(MA4 , col='blue',lwd=2)