library(tseries) library(entropy) # install.packages("devtools", dependencies = T) # library(devtools) # install_github("cran/FinTS") library(FinTS) load("eurusd_m1.rdata") WINDOW_SIZE <- 60*24 #1 day TOTAL_BARS_N <- round(60*24*252/12) #1 month entropyChart <- rep(NA, TOTAL_BARS_N) #entropy adftestChartDF <- rep(NA, TOTAL_BARS_N) #Dickey-Fuller adftestChartLO <- rep(NA, TOTAL_BARS_N) #Lag order adftestChartP <- rep(NA, TOTAL_BARS_N) #p-value archtestChartCS <- rep(NA, TOTAL_BARS_N) #Chi-squared archtestChartDF <- rep(NA, TOTAL_BARS_N) #DF archtestChartP <- rep(NA, TOTAL_BARS_N) #p-value EURUSD_M1_LOG <- log(EURUSD_M1[-1]/EURUSD_M1[-length(EURUSD_M1)]) EURUSD_M1 <- tail(EURUSD_M1, TOTAL_BARS_N) EURUSD_M1_LOG <- tail(EURUSD_M1_LOG, TOTAL_BARS_N) for(i in WINDOW_SIZE:TOTAL_BARS_N){ entropyChart[i] <- entropy(EURUSD_M1_LOG[(i-WINDOW_SIZE+1):i]) adf <- adf.test(EURUSD_M1_LOG[(i-WINDOW_SIZE+1):i]) adftestChartDF[i] <- adf$statistic adftestChartLO[i] <- adf$parameter adftestChartP[i] <- adf$p.value arch <- ArchTest(EURUSD_M1_LOG[(i-WINDOW_SIZE+1):i]) archtestChartCS[i] <- arch$statistic archtestChartDF[i] <- arch$parameter archtestChartP[i] <- arch$p.value } plot(EURUSD_M1, type="l", main="EURUSD") plot(EURUSD_M1_LOG, type="l", main="log(EURUSD[-1]/EURUSD)") plot(entropyChart, type="l", main = "entropy") plot(adftestChartDF, type="l", main = "adf.test Dickey-Fuller") plot(adftestChartLO, type="l", main = "adf.test Lag order") plot(adftestChartP, type="l", main = "adf.test p-value") plot(archtestChartCS, type="l", main = "ArchTest Chi-squared") plot(archtestChartDF, type="l", main = "ArchTest DF") plot(archtestChartP, type="l", main = "ArchTest p-value") par(mfrow=c(3,1)) plot(EURUSD_M1, type="l", main="EURUSD") grid() plot(adftestChartDF, type="l", main = "adf.test Dickey-Fuller") grid() plot(archtestChartCS, type="l", main = "ArchTest Chi-squared") grid()