#Finding seasonality base on Fourier transformation #Call necessary packages require(TSA) require(PortfolioAnalytics) require(quantmod) #Get data start=as.Date("2017-11-17") end=as.Date("2021-05-15") getSymbols("^TWII",src="yahoo",from=start,to=end) twii.price=TWII[,6] twii.return=CalculateReturns(twii.price,method='log') x=na.omit(twii.return) p=periodogram(x) dd = data.frame(freq=p$freq, spec=p$spec) order = dd[order(-dd$spec),] top2 = head(order, 2) # display the 2 highest "power" frequencies top2