data(EuStockMarkets)
mode(EuStockMarkets)
class(EuStockMarkets)
pdf("EuStocks.pdf", width = 6, height = 5)
plot(EuStockMarkets)


#Problem 1 Write a brief description of the time series plots of the four indices.
#Do the series look stationary? 
#Do the fluctuations in the series seem to be of constant size? If not, describe how the volatility fluctuates.




logR = diff(log(EuStockMarkets))
plot(logR)

#Problem2. Write a brief description of the time series plots of the four series of log returns. Do the series look stationary? Do the fluctuations in the series seem to be of constant size? If not, describe how the volatility fluctuates.
plot(as.data.frame(logR))
par(mfrow=c(2, 2)) 
for(i in colnames(logR)) 
{ 
  qqnorm(logR[ ,i], datax = T, main = i) 
  qqline(logR[ ,i], datax = T) 
  print(shapiro.test(logR[ ,i])) 
}
#Problem 3. Briefly describe the shape of each of the four normal plots and state whether the marginal distribution of each series is skewed or symmetric and whether its tails appear normal. If the tails do not appear normal, do they appear heavier or lighter than normal? What conclusions can be made from the Shapiro–Wilk tests? Include the plots with your work.
n=dim(logR)[1] 
q_grid = (1:n) / (n + 1) 
df_grid = c(1, 4, 6, 10, 20, 30) 
index.names = dimnames(logR)[[2]] 
for(i in 1:4) 
{ 
  #dev.new() 
  par(mfrow = c(3, 2)) 
  for(df in df_grid) 
  { 
    qqplot(logR[,i], qt(q_grid,df), 
           main = paste(index.names[i], ", df = ", df) ) 
    abline(lm(qt(c(0.25, 0.75), df = df) ~ 
                quantile(logR[,i], c(0.25, 0.75)))) 
  }
}