Zeitreihenanalyse - Übung 7

From StatWiki
Jump to: navigation, search

Exercise

Test whether a seasonal trend component is present in the Amazon returns.

Engine.php: unknown value "raw" for attribute "output"
in

Amzn=readdataSK("AMZN.csv", "csv") N <- length(Amzn[,7]) Amzn[1:N,] <- Amzn[N:1,]

r <- diff(log(Amzn[,7]),k=-1); n <- N-1; t <- 1:n omega <- 2*pi/12 r.sin6 <- lm(r~cos(omega*t)+sin(omega*t)

             +cos(2*omega*t)+sin(2*omega*t)
             +cos(3*omega*t)+sin(3*omega*t)
             +cos(4*omega*t)+sin(4*omega*t)
             +cos(5*omega*t)+sin(5*omega*t)
             +cos(6*omega*t))

summary(r.sin6)

Exercise

Convert.php: File "/var/www/localhost/htdocs/StatWiki/Rfiles/R/c4fc6fe2528e5b6364ac07c116b479a51f48a9f4_0.pdf.png" does not exist
in

pdf(rpdf) rsa=readdataSK("RSAFSNA.csv", "csv") y.log=log(rsa$VALUE) y.diff <- diff(y.log); plot(y.diff,xlab="",ylab="",type="l")

n=nrow(rsa)

m <- floor(n/2) # number of frequencies

  1. floor = the largest integer not greater than

y.dft <- fft(y.diff) # use the fast Fourier transform y.dft <- y.dft[2:(m+1)] # excl. k=0, k=m+1, m+2, …,n-1

y.p <- (1/(2*pi*n))*(Mod(y.dft))^2 # Mod = modulus f <- (2*pi/n)*(1:m) # vector of m Fourier frequencies plot(f,y.p,type="l",xlab="",ylab="",ylim=c(0,0.04), axes=T)

  1. x=pretty(f)
  2. axis(1,f[1:5],sapply(1:m, function(x) parse(text=paste(x,"*frac(2*pi, n)",sep="")))[1:5],padj=0.5)