if (!require("devtools")) install.packages("devtools") devtools::install_github("deanfantazzini/bitcoinFinance") install.packages("dplyr") library(magrittr) library(bitcoinFinance) Cstack_info() ## Data Download download_coinmarketcap_daily <- function(cryptoname = "bitcoin", start_date = 20130501, end_date = 20190701) { news <- xml2::read_html(paste("https://coinmarketcap.com/currencies/", cryptoname, "/historical-data/?start=", start_date, "&end=", end_date, sep = "")) table_news <- news %>% rvest::html_nodes("table") table_news <- table_news[[1]] %>% rvest::html_table() return(table_news) } library(magrittr) download_coinmarketcap_daily <- function(cryptoname = "bitcoin", start_date = 20130428, end_date = 20170705) { news <- xml2::read_html(paste("https://coinmarketcap.com/currencies/", cryptoname, "/historical-data/?start=", start_date, "&end=", end_date, sep = "")) table_news <- news %>% rvest::html_nodes("table") table_news <- table_news[[1]] %>% rvest::html_table() return(table_news) } dat <- download_coinmarketcap_daily(cryptoname = "ethereum", start_date = 20160101, end_date = 20170704) head(dat) #1 #https://coinmarketcap.com/currencies/bitcoin/historical-data/?start=20130429&end=20180422 bitcoin_2<- download_coinmarketcap_daily(cryptoname = "bitcoin", start_date = 20130429, end_date = 20180422) #2 ethereum <- download_coinmarketcap_daily(cryptoname = "ethereum", start_date = 20151201, end_date = 20190701) #3 ripple <- download_coinmarketcap_daily(cryptoname = "ripple", start_date = 20151201, end_date = 20190701) #4 tether <- download_coinmarketcap_daily(cryptoname = "tether", start_date = 20151201, end_date = 20190701) #5 bitcoin_cash <- download_coinmarketcap_daily(cryptoname = "bitcoin-cash", start_date = 20151201, end_date = 20190701) #6 litecoin <- download_coinmarketcap_daily(cryptoname = "litecoin", start_date = 20151201, end_date = 20190701) #7 eos <- download_coinmarketcap_daily(cryptoname = "eos", start_date = 20151201, end_date = 20190701) #8 binance_coin<- download_coinmarketcap_daily(cryptoname = "binance-coin", start_date = 20151201, end_date = 20190701) #9 bitcoin_sv <- download_coinmarketcap_daily(cryptoname = "bitcoin-sv", start_date = 20151201, end_date = 20190701) #10 stellar <- download_coinmarketcap_daily(cryptoname = "stellar", start_date = 20151201, end_date = 20190701) #11 tron <- download_coinmarketcap_daily(cryptoname = "tron", start_date = 20151201, end_date = 20190701) #12 cardano <- download_coinmarketcap_daily(cryptoname = "cardano", start_date = 20151201, end_date = 20190701) iota <- download_coinmarketcap_daily(cryptoname = "iota", start_date = 20190101, end_date = 20190701) #for 2016 monero<-download_coinmarketcap_daily(cryptoname = "monero", start_date = 20151201, end_date = 20190701) nem<-download_coinmarketcap_daily(cryptoname = "nem", start_date = 20151201, end_date = 20190701) staker<-download_coinmarketcap_daily(cryptoname = "staker", start_date = 20151201, end_date = 20190701) siacoin<-download_coinmarketcap_daily(cryptoname = "siacoin", start_date = 20151201, end_date = 20190701) ethereum_classic<-download_coinmarketcap_daily(cryptoname = "ethereum-classic", start_date = 20151201, end_date = 20190701) dash<-download_coinmarketcap_daily(cryptoname = "dash", start_date = 20151201, end_date = 20190701) # Rename columns names(ethereum_reverse)<-c("Date","Open","High","Low","Close","Volume","Market Cap") head(bitcoin) # Convert to the date format # as.Date(dat$Date,format='%b %d, %Y') # as.Date('Jun 26, 2001',format='%b %d, %Y') write.csv(bitcoin, file = "bitcoin.csv") write.csv(bitcoin_2, file = "bitcoin_2.csv") write.csv(ethereum, file = "ethereum.csv") write.csv(ripple, file = "ripple.csv") write.csv(tether, file = "tether.csv") write.csv(bitcoin_cash, file = "bitcoin_cash.csv") write.csv(litecoin, file = "litecoin.csv") write.csv(eos, file = "eos.csv") write.csv(binance_coin, file = "binance_coin.csv") write.csv(bitcoin_sv, file = "bitcoin_sv.csv") write.csv(stellar, file = "stellar.csv") write.csv(tron, file = "tron.csv") write.csv(cardano, file = "cardano.csv") #for 2016 write.csv(monero, file = "monero.csv") write.csv(nem, file = "nem.csv") write.csv(staker, file = "staker.csv") write.csv(siacoin, file = "siacoin.csv") write.csv(ethereum_classic, file = "ethereum_classic.csv") write.csv(dash, file = "dash.csv") # Date format change install.packages("readr") library("readr") bitcoin <- read_csv("Bitcoin.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) ethereum <- read_csv("ethereum.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) ripple <- read_csv("ripple.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) tether <- read_csv("tether.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) bitcoin_cash <- read_csv("bitcoin_cash.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) litecoin <- read_csv("litecoin.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) eos <- read_csv("eos.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) binance_coin <- read_csv("binance_coin.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) bitcoin_sv <- read_csv("bitcoin_sv.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) stellar <- read_csv("stellar.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) tron <- read_csv("tron.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) cardano<- read_csv("cardano.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) #for 2016 monero <- read_csv("monero.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) nem <- read_csv("nem.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) staker <- read_csv("staker.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) siacoin <- read_csv("siacoin.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) ethereum_classic <- read_csv("ethereum_classic.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) dash<- read_csv("dash.csv", col_types = cols(Date = col_date(format = "%b %d, %Y"))) bitcoin_term <- read_csv("Bitcoin_term.csv") bitcoin_currency <- read_csv("Bitcoin_currency.csv") blockchain_term <- read_csv("Blockchain_term.csv") crypto_topic <- read_csv("Cryptocurrency_topic.csv") ether_topic <- read_csv("Ether_cryptocurrency.csv") ethereum_term<-read_csv("Ethereum_term.csv") install.packages("gridExtra") library(gridExtra) names(bitcoin_currency)<-c("Week", "Popularity") subset_bitcoin_currency<-cbind(subset(bitcoin_currency, Week>="2015-12-01"& Week<="2019-07-01"),subset(crypto_topic, Week>="2015-12-01"& Week<="2019-07-01"), subset(ethereum_term, Week>="2015-12-01"& Week<="2019-07-01")) subset_bitcoin_currency$`Ethereum Polularity (%)`<-as.numeric(subset_bitcoin_currency$`Ethereum Polularity (%)`) subset_bitcoin_currency[4,6]<-1 names(subset_bitcoin_currency)<-c("Week", "Bitcoin Popularity (%)", "Week_1", "Cryptocurrency_Polularity", "Week_2", "Ethereum Polularity (%)") library(dplyr) subset_bitcoin_currency<-dplyr::left_join( bitcoin,subset_bitcoin_currency, by=c("Date"="Week") ) %>% dplyr::left_join(ethereum, by="Date" ) names(subset_bitcoin_currency)<-c("Order.x", "Date","Open.x", "High.x", "Low.x" ,"Bitcoin Price (USD)","Volume.x","Market Cap.x","Bitcoin Popularity (%)", "Week_1", "Cryptocurrency_Polularity", "Week_2","Ethereum Polularity (%)","Order.y","Open.y" , "High.y", "Low.y" ,"Ethereum Price (USD)", "Volume.y", "Market Cap.y") size <- 10 themePlot <- theme( plot.title = element_text(size=size,hjust = 0.5), axis.text.y = element_text(size=size), axis.text.x = element_text(size=size), axis.title.y = element_text(size=size), axis.title.x = element_text(size=size), legend.text = element_text(size = size), panel.background = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"), panel.border = element_rect(colour = "black", fill=NA, size=0.5) ) colors_trends <- c("Bitcoin Price" = "red", "Popularity (%)" = "blue") g1<-ggplot(data = na.omit(subset_bitcoin_currency), aes(x = Date))+ geom_line(aes(y =`Bitcoin Price (USD)`, color = "Bitcoin Price")) + geom_line(aes(y = 1+ `Bitcoin Popularity (%)`*200, color = "Popularity (%)"))+ scale_y_continuous("Bitcoin Price (USD)", sec.axis = sec_axis(~ (. - 1)/200, name = "Bitcoin Popularity (%)")) + ggtitle("Google Trends Bitcoin & Bitcoin Price") + labs(x = "Date", y = "(Google Trends Bitcoin & Bitcoin Price", color = " ") + scale_color_manual(values = colors_trends)+ scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom",legend.direction="horizontal", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="blue"), axis.text.y.right=element_text(color="blue"), plot.title = element_text(size=size,hjust = 0.5), axis.text.y = element_text(size=size), axis.text.x = element_text(size=size), axis.title.y = element_text(size=size), axis.title.x = element_text(size=size), legend.text = element_text(size = size)) colors_trends_eth <- c("Ethereum Price" = "red", "Popularity (%)" = "blue") g2<-ggplot(data = na.omit(subset_bitcoin_currency), aes(x = Date))+ geom_line(aes(y =`Ethereum Price (USD)`, color = "Ethereum Price")) + geom_line(aes(y = 1+ `Ethereum Polularity (%)`*15, color = "Popularity (%)"))+ scale_y_continuous("Ethereum Price (USD)", sec.axis = sec_axis(~ (. - 1)/15, name = "Ethereum Polularity (%)")) + ggtitle("Google Trends Ethereum & Ethereum Price") + labs(x = "Date", y = "(Google Trends Ethereum & Ethereum Price)", color = " ") + scale_color_manual(values = colors_trends_eth)+ scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom",legend.direction="horizontal", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="blue"), axis.text.y.right=element_text(color="blue"), plot.title = element_text(size=size,hjust = 0.5), axis.text.y = element_text(size=size), axis.text.x = element_text(size=size), axis.title.y = element_text(size=size), axis.title.x = element_text(size=size), legend.text = element_text(size = size)) colors_g3<-c("Bitcoin Price"="red","Ethereum Price"="blue") g3<-ggplot(data = subset(subset_bitcoin_currency, Date>="2017-09-03" & Date<="2017-09-10"), aes(x = Date))+ geom_line(aes(y =`Bitcoin Price (USD)`, color = "Bitcoin Price")) + geom_line(aes(y = 1200+ `Ethereum Price (USD)`*10, color = "Ethereum Price"))+ scale_y_continuous("Bitcoin Price (USD)", sec.axis = sec_axis(~ (. - 1200)/10, name = "Ethereum Price")) + ggtitle("Bitcoin & Ethereum Price Chart") + labs(x = "Date", y = "(Bitcoin & Ethereum Price Chart", color = " ") + scale_color_manual(values = colors_g3)+ scale_x_date(labels=date_format("%Y-%m-%d"))+ theme(legend.position="bottom",legend.direction="horizontal", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="blue"), axis.text.y.right=element_text(color="blue"), plot.title = element_text(size=size,hjust = 0.5), axis.text.y = element_text(size=size), axis.text.x = element_text(size=size), axis.title.y = element_text(size=size), axis.title.x = element_text(size=size), legend.text = element_text(size = size)) ## Change reverse order bitcoin<-bitcoin[order(bitcoin$Date, decreasing=FALSE),] bitcoin_2<-bitcoin[order(bitcoin_2$Date, decreasing=FALSE),] ethereum<-ethereum[order(ethereum$Date, decreasing=FALSE),] ripple<-ripple[order(ripple$Date, decreasing=FALSE),] tether<-tether[order(tether$Date, decreasing=FALSE),] bitcoin_cash<-bitcoin_cash[order(bitcoin_cash$Date, decreasing=FALSE),] litecoin<-litecoin[order(litecoin$Date, decreasing=FALSE),] eos<-eos[order(eos$Date, decreasing=FALSE),] binance_coin<-binance_coin[order(binance_coin$Date, decreasing=FALSE),] bitcoin_sv<-bitcoin_sv[order(bitcoin_sv$Date, decreasing=FALSE),] stellar<-stellar[order(stellar$Date, decreasing=FALSE),] tron<-tron[order(tron$Date, decreasing=FALSE),] cardano<-cardano[order(cardano$Date, decreasing=FALSE),] #for 2016 monero<-monero[order(monero$Date, decreasing=FALSE),] nem<-nem[order(nem$Date, decreasing=FALSE),] staker<-staker[order(staker$Date, decreasing=FALSE),] siacoin<-siacoin[order(siacoin$Date, decreasing=FALSE),] ethereum_classic<-ethereum_classic[order(ethereum_classic$Date, decreasing=FALSE),] dash<-dash[order(dash$Date, decreasing=FALSE),] #Rename again..... names(bitcoin)<-c("Order", "Date","Open","High","Low","BTC_Close","Volume","Market Cap") names(bitcoin_2)<-c("Order", "Date","Open","High","Low","BTC_Close","Volume","Market Cap") names(ethereum)<-c("Order", "Date","Open","High","Low","ETH_Close","Volume","Market Cap") names(ripple)<-c("Order", "Date","Open","High","Low","XRP_Close","Volume","Market Cap") names(tether)<-c("Order", "Date","Open","High","Low","USDT_Close","Volume","Market Cap") names(bitcoin_cash)<-c("Order", "Date","Open","High","Low","BCH_Close","Volume","Market Cap") names(litecoin)<-c("Order", "Date","Open","High","Low","LTC_Close","Volume","Market Cap") names(eos)<-c("Order", "Date","Open","High","Low","EOS_Close","Volume","Market Cap") names(binance_coin)<-c("Order", "Date","Open","High","Low","BNB_Close","Volume","Market Cap") names(bitcoin_sv)<-c("Order", "Date","Open","High","Low","BSV_Close","Volume","Market Cap") names(stellar)<-c("Order", "Date","Open","High","Low","XLM_Close","Volume","Market Cap") names(tron)<-c("Order", "Date","Open","High","Low","TRX_Close","Volume","Market Cap") names(cardano)<-c("Order", "Date","Open","High","Low","ADA_Close","Volume","Market Cap") #for 2016 names(monero)<-c("Order", "Date","Open","High","Low","XMR_Close","Volume","Market Cap") names(nem)<-c("Order", "Date","Open","High","Low","XEM_Close","Volume","Market Cap") names(staker)<-c("Order", "Date","Open","High","Low","STR_Close","Volume","Market Cap") names(siacoin)<-c("Order", "Date","Open","High","Low","SC_Close","Volume","Market Cap") names(ethereum_classic)<-c("Order", "Date","Open","High","Low","ETC_Close","Volume","Market Cap") names(dash)<-c("Order", "Date","Open","High","Low","DASH_Close","Volume","Market Cap") ##data_all<-data.frame(cbind(bitcoin$Date, bitcoin$BTC_Close, ethereum$ETH_Close, ripple$XRP_Close, tether$USDT_Close, bitcoin_cash$BCH_Close, litecoin$LTC_Close, eos$EOS_Close, binance_coin$BNB_Close, bitcoin_sv$BSV_Close, stellar$XLM_Close, tron$TRX_Close, cardano$ADA_Close)) library(dplyr) #for 2016 data_all_2106<-dplyr::left_join(bitcoin, ethereum, by="Date" ) %>% dplyr::left_join(ripple, by="Date" )%>% dplyr::left_join(monero, by="Date" )%>% dplyr::left_join(nem, by="Date" )%>% dplyr::left_join(staker, by="Date" )%>% dplyr::left_join(siacoin, by="Date" )%>% dplyr::left_join(litecoin, by="Date" )%>% dplyr::left_join(ethereum_classic, by="Date" )%>% dplyr::left_join(dash, by="Date") data_all_2016<-select(data_all,"Date", "BTC_Close","ETH_Close", "XRP_Close", "XMR_Close", "XEM_Close", "STR_Close", "SC_Close", "LTC_Close", "ETC_Close", "DASH_Close") data_all<-dplyr::left_join(bitcoin, ethereum, by="Date" ) %>% dplyr::left_join(ripple, by="Date" )%>% dplyr::left_join(tether, by="Date" )%>% dplyr::left_join(bitcoin_cash, by="Date" )%>% dplyr::left_join(litecoin, by="Date" )%>% dplyr::left_join(eos, by="Date" )%>% dplyr::left_join(binance_coin, by="Date" )%>% dplyr::left_join(bitcoin_sv, by="Date" )%>% dplyr::left_join(stellar, by="Date" )%>% dplyr::left_join(tron, by="Date" )%>% dplyr::left_join(cardano, by="Date") data_all<-select(data_all,"Date", "BTC_Close","ETH_Close", "XRP_Close", "USDT_Close", "BCH_Close", "LTC_Close", "EOS_Close", "BNB_Close", "BSV_Close", "XLM_Close", "TRX_Close","ADA_Close") ##names(data_all)<-c("BTC_Close","ETH_Close", "XRP_Close", "USDT_Close", "BCH_Close", "LTC_Close", "EOS_Close", "BNB_Close", "BSV_Close", "XLM_Close", "TRX_Close","ADA_Close") ##colnames(data_all)<-c("Date", "BTC_Close","ETH_Close", "XRP_Close", "USDT_Close", "BCH_Close", "LTC_Close", "EOS_Close", "BNB_Close", "BSV_Close", "XLM_Close", "TRX_Close","ADA_Close") #Prices col_p1<-c("BTC_Close"="blue") p1<-ggplot(data = subset(data_all, Date>="2019-05-01", Date<="2019-07-01"), aes(x = Date))+ geom_line(aes(y=BTC_Close, color = "BTC_Close" ))+ labs(color = " ") + ggtitle("Bitcoin Price Chart") + xlab(label='Date') + ylab(label='Bitcoin Price (USD)')+ scale_x_date(labels=date_format("%y-%m"))+ scale_color_manual(values = col_p1)+ theme(legend.position="bottom",legend.direction="horizontal", plot.title = element_text(size=size,hjust = 0.5), axis.text.y = element_text(size=size), axis.text.x = element_text(size=size), axis.title.y = element_text(size=size), axis.title.x = element_text(size=size), legend.text = element_text(size = size)) col_p2<-c("ETH_Close"="blue") p2<-ggplot(data = subset(data_all, Date>="2019-05-01", Date<="2019-07-01"), aes(x = Date))+ geom_line(aes(y=ETH_Close, color = "ETH_Close"))+ labs(color = " ") + ggtitle("Ethereum Price Chart") + xlab(label='Date') + ylab(label='Ethereum Price (USD)')+ scale_x_date(labels=date_format("%y-%m"))+ scale_color_manual(values = col_p2)+ theme(legend.position="bottom",legend.direction="horizontal", plot.title = element_text(size=size,hjust = 0.5), axis.text.y = element_text(size=size), axis.text.x = element_text(size=size), axis.title.y = element_text(size=size), axis.title.x = element_text(size=size), legend.text = element_text(size = size)) grid.arrange(p1,p2,nrow=1) price_chart<- ggplot(data = data_all, aes(x = Date, y = BTC_Close)) + geom_line(color = "blue" ) + geom_line(aes (y = ETH_Close), color = "black", size = 0.5) + geom_line(aes (y = XRP_Close), color = "deeppink", size = 0.5) + geom_line(aes (y = USDT_Close), color = "chartreuse", size = 0.5) + geom_line(aes (y = BCH_Close), color = "yellow", size = 0.5) + geom_line(aes (y = LTC_Close), color = "brown", size = 0.5) + geom_line(aes (y = EOS_Close), color = "red", size = 0.5) + geom_line(aes (y = BNB_Close), color = "purple", size = 0.5) + geom_line(aes (y = BSV_Close), color = "darkorange", size = 0.5) + geom_line(aes (y = XLM_Close), color = "cyan", size = 0.5) + geom_line(aes (y = TRX_Close), color = "coral", size = 0.5) + geom_line(aes (y = ADA_Close), color = "aquamarine", size = 0.5) + ggtitle("Cryptocurrency Price Chart") + xlab(label='Date') + ylab(label='Price USD') + #coord_cartesian(ylim = c(-0.01, 0.048)) + themePlot ##### SADF & GSDAF install.packages("devtools") devtools::install_github("itamarcaspi/rtadfr") library(rtadfr) # SADF tests #BITCOIN log_bitcoin <-diff(log(bitcoin$BTC_Close)) set.seed(1234) # for replicability obs <- nrow(bitcoin) # Sample size r0 <- round(obs*(0.01 + 1.8 / sqrt(obs))) # Minimal window size test <- rtadf(bitcoin$BTC_Close, r0, test = "sadf", type="drift") # estimate test statistic and date-stamping sequence cvs <- rtadfSimPar(obs, nrep = 1000, r0, test = "sadf") # simulate critical values and date-stamping threshold print(testDf) test_sadf_bitcoin<-test cvs_sadf_bitcoin<-cvs testDf_bitcoin<- list("test statistic" = test_sadf_bitcoin$testStat, "critical values" = cvs_sadf_bitcoin$testCVs) # test results #dateStampDf1<- ts(cbind(test_sadf_bitcoin$testSeq, cvs_sadf_bitcoin$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf <- cbind.data.frame("testSeq" = test_sadf_bitcoin$testSeq, "dateStamp" = cvs_sadf_bitcoin$datestampCVs[,2], "date" = bitcoin$Date, "Log_BTC"=log(bitcoin$BTC_Close)) #ts.plot(dateStampDf1, plot.type = "single", col=c("blue", "red")) colors_bitcoin <- c("95% critical values" = "blue", "Forward ADF sequence" = "red", "Log_BTC" = "green") SADF_Test_Bitcoin<- ggplot(dateStampDf, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="Forward ADF sequence")) + geom_line(aes(y = 1+ Log_BTC*1, color = "Log_BTC"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. - 1)/1, name = "Log_BTC")) + ggtitle("SADF Test Bitcoin") + labs(x = "Date", y = "(SADF Test Bitcoin)", color = "Legend") + scale_color_manual(values = colors_bitcoin)+ scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom",legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_bitcoin<-subset(dateStampDf, testSeq>=dateStamp) #ETHEREUM #obs <- nrow(bitcoin) # Sample size #r0 <- round(obs*(0.01 + 1.8 / sqrt(obs))) # Minimal window size test_sadf_ethereum <- rtadf(ethereum$ETH_Close, r0, test = "sadf", type = "drift", selectlags = "AIC") # estimate test statistic and date-stamping sequence cvs_sadf_ethereum <-cvs_sadf_bitcoin # same number of observations, simulate critical values and date-stamping threshold testDf_ethereum <- list("test statistic" = test_sadf_ethereum$testStat, "critical values" = cvs_sadf_ethereum$testCVs) # test results print(testDf_ethereum) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_ethereum <- cbind.data.frame("testSeq" = test_sadf_ethereum$testSeq, "dateStamp" = cvs_sadf_ethereum$datestampCVs[,2], "date" = ethereum$Date, "Log_ETH"=log(ethereum$ETH_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_ethereum <- c("95% critical values" = "blue", "Forward ADF sequence" = "red", "Log_ETH" = "green") SADF_Test_Ethereum<- ggplot(dateStampDf_ethereum, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="Forward ADF sequence")) + geom_line(aes(y = 5+ Log_ETH*1, color = "Log_ETH"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. - 5)/1, name = "Log_ETH")) + ggtitle("SADF Test Ethereum") + labs(x = "Date", y = "(SADF Test Ethereum)", color = "Legend") + scale_color_manual(values = colors_ethereum)+ scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_ethereum<-subset(dateStampDf_ethereum, testSeq>=dateStamp) # RIPPLE test_sadf_ripple<- rtadf(ripple$XRP_Close, r0, test = "sadf") # estimate test statistic and date-stamping sequence cvs_sadf_ripple<-cvs_sadf_bitcoin # same number of observations, simulate critical values and date-stamping threshold testDf_ripple<- list("test statistic" = test_sadf_ripple$testStat, "critical values" = cvs_sadf_ripple$testCVs) # test results print(testDf_ripple) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_ripple <- cbind.data.frame("testSeq" = test_sadf_ripple$testSeq, "dateStamp" = cvs_sadf_ripple$datestampCVs[,2], "date" = ripple$Date, "Log_XRP"=log(ripple$XRP_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) b <- 2 a <- b*10 colors <- c("95% critical values" = "blue", "Forward ADF sequence" = "red", "Log_XRP" = "green") SADF_Test_Ripple<-ggplot(dateStampDf_ripple, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="Forward ADF sequence")) + geom_line(aes(y = a + Log_XRP*b, color = "Log_XRP"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. - a)/b, name = "Log_XRP")) + # scale_x_continuous("Date", origin = "1970-01-01") + ggtitle("SADF Test Ripple") + labs(x = "Date", y = "(SADF Test Ripple)", color = "Legend") + scale_color_manual(values = colors)+ scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_ripple<-subset(dateStampDf_ripple, testSeq>=dateStamp) #ggplot(dateStampDf_ripple, aes(x = date, y = dateStamp)) + geom_line(color = "blue" ) + geom_line(aes(y=testSeq), method="loess", col="red") + geom_line(aes(y=Log_XRP * 1), method="loess", col="green") + scale_y_continuous(name="testSeq", sec.axis=sec_axis(~./10, name="Log_XRP")) + theme( axis.title.y.left=element_text(color="green"), axis.text.y.left=element_text(color="green"), axis.title.y.right=element_text(color="red"), axis.text.y.right=element_text(color="red") ) # TETHER test_sadf_tether<- rtadf(tether$USDT_Close, r0, test = "sadf", type="none") # estimate test statistic and date-stamping sequence cvs_sadf_tether<-cvs_sadf_bitcoin # same number of observations, simulate critical values and date-stamping threshold testDf_tether<- list("test statistic" = test_sadf_tether$testStat, "critical values" = cvs_sadf_tether$testCVs) # test results print(testDf_tether) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_tether <- cbind.data.frame("testSeq" = test_sadf_tether$testSeq, "dateStamp" = cvs_sadf_tether$datestampCVs[,2], "date" = tether$Date, "Log_USDT"=log(tether$USDT_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_tether <- c("95% critical values" = "blue", "Forward ADF sequence" = "red", "Log_USDT" = "green") SADF_Test_Tether<- ggplot(dateStampDf_tether, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="Forward ADF sequence")) + geom_line(aes(y = 1+ Log_USDT*5, color = "Log_USDT"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -1)/5, name = "Log_USDT")) + ggtitle("SADF Test Tether") + labs(x = "Date", y = "(SADF Test Tether)", color = "Legend") + scale_color_manual(values = colors_tether)+ scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_tether<-subset(dateStampDf_tether, testSeq>=dateStamp) # BITCOIN CASH obs_bitcoin_cash <- nrow(bitcoin_cash) # Sample size r0_bitcoin_cash <- round(obs_bitcoin_cash*(0.01 + 1.8 / sqrt(obs_bitcoin_cash))) # Minimal window size test_sadf_bitcoin_cash<- rtadf(bitcoin_cash$BCH_Close, r0_bitcoin_cash, test = "sadf", type="none") # estimate test statistic and date-stamping sequence cvs_sadf_bitcoin_cash <- rtadfSimPar(obs_bitcoin_cash, nrep = 1000, r0_bitcoin_cash, test = "sadf") testDf_bitcoin_cash<- list("test statistic" = test_sadf_bitcoin_cash$testStat, "critical values" = cvs_sadf_bitcoin_cash$testCVs) # test results print(testDf_bitcoin_cash) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_bitcoin_cash <- cbind.data.frame("testSeq" = test_sadf_bitcoin_cash$testSeq, "dateStamp" = cvs_sadf_bitcoin_cash$datestampCVs[,2], "date" = bitcoin_cash$Date, "Log_BCH"=log(bitcoin_cash$BCH_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_bitcoin_cash <- c("95% critical values" = "blue", "Forward ADF sequence" = "red", "Log_BCH" = "green") SADF_Test_Bitcoin_Cash<- ggplot(dateStampDf_bitcoin_cash, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="Forward ADF sequence")) + geom_line(aes(y = 1+ Log_BCH*0.5, color = "Log_BCH"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -1)/0.5, name = "Log_BCH")) + ggtitle("SADF Test Bitcoin Cash") + labs(x = "Date", y = "(SADF Test Bitcoin Cash)", color = "Legend") + scale_color_manual(values = colors_bitcoin_cash)+ scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom",legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_bitcoin_cash<-subset(dateStampDf_bitcoin_cash, testSeq>=dateStamp) # LITECOIN test_sadf_litecoin <- rtadf(litecoin$LTC_Close, r0, test = "sadf", type="drift") # estimate test statistic and date-stamping sequence cvs_sadf_litecoin <-cvs_sadf_bitcoin # same number of observations, simulate critical values and date-stamping threshold testDf_litecoin<- list("test statistic" = test_sadf_litecoin$testStat, "critical values" = cvs_sadf_litecoin$testCVs) # test results print(testDf_litecoin) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_litecoin <- cbind.data.frame("testSeq" = test_sadf_litecoin$testSeq, "dateStamp" = cvs_sadf_litecoin$datestampCVs[,2], "date" = litecoin$Date, "Log_LTC"=log(litecoin$LTC_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_litecoin <- c("95% critical values" = "blue", "Forward ADF sequence" = "red", "Log_LTC" = "green") SADF_Test_Litecoin<- ggplot(dateStampDf_litecoin, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="Forward ADF sequence")) + geom_line(aes(y = 4+ Log_LTC*1.5, color = "Log_LTC"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -4)/1.5, name = "Log_LTC")) + ggtitle("SADF Test Litecoin") + labs(x = "Date", y = "(SADF Test Litecoin)", color = "Legend") + scale_color_manual(values = colors_litecoin)+ scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_litecoin<-subset(dateStampDf_litecoin, testSeq>=dateStamp) # EOS obs_eos <- nrow(eos) # Sample size r0_eos <- round(obs_eos*(0.01 + 1.8 / sqrt(obs_eos))) # Minimal window size test_sadf_eos<- rtadf(eos$EOS_Close, r0_eos, test = "sadf", type="none") # estimate test statistic and date-stamping sequence cvs_sadf_eos <- rtadfSimPar(obs_eos, nrep = 1000, r0_eos, test = "sadf") testDf_eos<- list("test statistic" = test_sadf_eos$testStat, "critical values" = cvs_sadf_eos$testCVs) # test results print(testDf_eos) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_eos<- cbind.data.frame("testSeq" = test_sadf_eos$testSeq, "dateStamp" = cvs_sadf_eos$datestampCVs[,2], "date" = eos$Date, "Log_EOS"=log(eos$EOS_Close) ) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_eos <- c("95% critical values" = "blue", "Forward ADF sequence" = "red", "Log_EOS" = "green") SADF_Test_EOS<- ggplot(dateStampDf_eos, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="Forward ADF sequence")) + geom_line(aes(y = 1+Log_EOS*1, color = "Log_EOS"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -1)/1, name = "Log_EOS")) + ggtitle("SADF Test EOS") + labs(x = "Date", y = "(SADF Test EOS)", color = "Legend") + scale_color_manual(values = colors_eos)+ scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom",legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_eos<-subset(dateStampDf_eos, testSeq>=dateStamp) # BINANCE COIN obs_binance_coin <- nrow(binance_coin) # Sample size r0_binance_coin <- round(obs_binance_coin*(0.01 + 1.8 / sqrt(obs_binance_coin))) # Minimal window size test_sadf_binance_coin<- rtadf(binance_coin$BNB_Close, r0_binance_coin, test = "sadf", type="none") # estimate test statistic and date-stamping sequence cvs_sadf_binance_coin <- rtadfSimPar(obs_binance_coin, nrep = 1000, r0_binance_coin, test = "sadf") testDf_binance_coin<- list("test statistic" = test_sadf_binance_coin$testStat, "critical values" = cvs_sadf_binance_coin$testCVs) # test results print(testDf_binance_coin) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_binance_coin<- cbind.data.frame("testSeq" = test_sadf_binance_coin$testSeq, "dateStamp" = cvs_sadf_binance_coin$datestampCVs[,2], "date" = binance_coin$Date, "Log_BNB"=log(binance_coin$BNB_Close) ) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_binance_coin <- c("95% critical values" = "blue", "Forward ADF sequence" = "red", "Log_BNB" = "green") SADF_Test_Binance_Coin<- ggplot(dateStampDf_binance_coin, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="Forward ADF sequence")) + geom_line(aes(y = 1+Log_BNB*1, color = "Log_BNB"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -1)/1, name = "Log_BNB")) + ggtitle("SADF Test Binance Coin") + labs(x = "Date", y = "(SADF Test Binance Coin)", color = "Legend") + scale_color_manual(values = colors_binance_coin)+ scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_binance_coin<-subset(dateStampDf_binance_coin, testSeq>=dateStamp) # BITCOIN SV obs_bitcoin_sv <- nrow(bitcoin_sv) # Sample size r0_bitcoin_sv <- round(obs_bitcoin_sv*(0.01 + 1.8 / sqrt(obs_bitcoin_sv))) # Minimal window size test_sadf_bitcoin_sv<- rtadf(bitcoin_sv$BSV_Close, r0_bitcoin_sv, test = "sadf", type="none") # estimate test statistic and date-stamping sequence cvs_sadf_bitcoin_sv <- rtadfSimPar(obs_bitcoin_sv, nrep = 1000, r0_bitcoin_sv, test = "sadf") testDf_bitcoin_sv<- list("test statistic" = test_sadf_bitcoin_sv$testStat, "critical values" = cvs_sadf_bitcoin_sv$testCVs) # test results print(testDf_bitcoin_sv) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_bitcoin_sv<- cbind.data.frame("testSeq" = test_sadf_bitcoin_sv$testSeq, "dateStamp" = cvs_sadf_bitcoin_sv$datestampCVs[,2], "date" = bitcoin_sv$Date, "Log_BSV"=log(bitcoin_sv$BSV_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_bitcoin_sv <- c("95% critical values" = "blue", "Forward ADF sequence" = "red", "Log_BSV" = "green") SADF_Test_Bitcoin_SV<- ggplot(dateStampDf_bitcoin_sv, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="Forward ADF sequence")) + geom_line(aes(y =1+ Log_BSV*0.5, color = "Log_BSV"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -1)/0.5, name = "Log_BSV")) + ggtitle("SADF Test Bitcoin SV") + labs(x = "Date", y = "(SADF Test Bitcoin SV)", color = "Legend") + scale_color_manual(values = colors_bitcoin_sv)+ scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_bitcoin_sv<-subset(dateStampDf_bitcoin_sv, testSeq>=dateStamp) # STELLAR test_sadf_stellar<- rtadf(stellar$XLM_Close, r0, test = "sadf", type="drift") # estimate test statistic and date-stamping sequence cvs_sadf_stellar <- cvs_sadf_bitcoin testDf_stellar<- list("test statistic" = test_sadf_stellar$testStat, "critical values" = cvs_sadf_stellar$testCVs) # test results print(testDf_stellar) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_stellar<- cbind.data.frame("testSeq" = test_sadf_stellar$testSeq, "dateStamp" = cvs_sadf_stellar$datestampCVs[,2], "date" = stellar$Date, "Log_XML"=log(stellar$XLM_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_stellar <- c("95% critical values" = "blue", "Forward ADF sequence" = "red", "Log_XML" = "green") SADF_Test_Stellar<- ggplot(dateStampDf_stellar, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="Forward ADF sequence")) + geom_line(aes(y =10+ Log_XML*2, color = "Log_XML"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -10)/2, name = "Log_XML")) + ggtitle("SADF Test Stellar") + labs(x = "Date", y = "(SADF Test Stellar)", color = "Legend") + scale_color_manual(values = colors_stellar)+ scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_stellar<-subset(dateStampDf_stellar, testSeq>=dateStamp) # TRON obs_tron <- nrow(tron) # Sample size r0_tron <- round(obs_tron*(0.01 + 1.8 / sqrt(obs_tron))) # Minimal window size test_sadf_tron<- rtadf(tron$TRX_Close, r0_tron, test = "sadf", type="none") # estimate test statistic and date-stamping sequence cvs_sadf_tron<- rtadfSimPar(obs_tron, nrep = 1000, r0_tron, test = "sadf") testDf_tron<- list("test statistic" = test_sadf_stellar$testStat, "critical values" = cvs_sadf_stellar$testCVs) # test results print(testDf_bitcoin_sv) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_tron<- cbind.data.frame("testSeq" = test_sadf_tron$testSeq, "dateStamp" = cvs_sadf_tron$datestampCVs[,2], "date" = tron$Date, "Log_TRX"=log(tron$TRX_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_tron <- c("95% critical values" = "blue", "Forward ADF sequence" = "red", "Log_TRX" = "green") SADF_Test_Tron<- ggplot(dateStampDf_tron, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="Forward ADF sequence")) + geom_line(aes(y =15+ Log_TRX*2, color = "Log_TRX"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -15)/2, name = "Log_TRX")) + ggtitle("SADF Test Tron") + labs(x = "Date", y = "(SADF Test Tron)", color = "Legend") + scale_color_manual(values = colors_tron)+ scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_tron<-subset(dateStampDf_tron, testSeq>=dateStamp) # CARDANO obs_cardano <- nrow(cardano) # Sample size r0_cardano <- round(obs_cardano*(0.01 + 1.8 / sqrt(obs_cardano))) # Minimal window size test_sadf_cardano<- rtadf(cardano$ADA_Close, r0_cardano, test = "sadf", type="none") # estimate test statistic and date-stamping sequence cvs_sadf_cardano<- rtadfSimPar(obs_cardano, nrep = 1000, r0_cardano, test = "sadf") testDf_cardano<- list("test statistic" = test_sadf_cardano$testStat, "critical values" = cvs_sadf_cardano$testCVs) # test results print(testDf_cardano) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_cardano<- cbind.data.frame("testSeq" = test_sadf_cardano$testSeq, "dateStamp" = cvs_sadf_cardano$datestampCVs[,2], "date" = cardano$Date, "Log_ADA"=log(cardano$ADA_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_cardano <- c("95% critical values" = "blue", "Forward ADF sequence" = "red", "Log_ADA" = "green") SADF_Test_Cardano<- ggplot(dateStampDf_cardano, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="Forward ADF sequence")) + geom_line(aes(y =8+ Log_ADA*2, color = "Log_ADA"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -8)/2, name = "Log_ADA")) + ggtitle("SADF Test Cardano") + labs(x = "Date", y = "(SADF Test Cardano)", color = "Legend") + scale_color_manual(values = colors_cardano)+ scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot size <- 10 date_stamping_cardano<-subset(dateStampDf_cardano, testSeq>=dateStamp) # SADF GRAPHS grid.arrange(#SADF_Test_Bitcoin, # SADF_Test_Ethereum, # SADF_Test_Ripple, # SADF_Test_Tether, # SADF_Test_Bitcoin_Cash, # SADF_Test_Litecoin, # SADF_Test_EOS, # SADF_Test_Binance_Coin, # SADF_Test_Bitcoin_SV, # SADF_Test_Stellar, SADF_Test_Tron, SADF_Test_Cardano, ncol=2) #GSADF set.seed(1234) # for replicability obs <- nrow(bitcoin) # Sample size r0 <- round(obs*(0.01 + 1.8 / sqrt(obs))) # Minimal window size test_gsadf_bitcoin <- rtadf(bitcoin$BTC_Close, r0, test = "gsadf") # estimate test statistic and date-stamping sequence cvs_gsadf_bitcoin <- rtadfSimPar(obs, nrep = 1000, r0, test = "gsadf") # simulate critical values and date-stamping threshold testDf_gsadf<- list("test statistic" = test_gsadf_bitcoin$testStat, "critical values" = cvs_gsadf_bitcoin$testCVs) # test results dateStampDf_bitcoin_gsadf<- cbind.data.frame("testSeq" = test_gsadf_bitcoin$testSeq, "dateStamp" = cvs_gsadf_bitcoin$datestampCVs[,2], "date" = bitcoin$Date, "Log_BTC"=log(bitcoin$BTC_Close)) colors_bitcoin <- c("95% critical values" = "blue", "GSADF Sequence" = "red", "Log_BTC" = "green") GSADF_Test_Bitcoin_1<- ggplot(dateStampDf_bitcoin_gsadf, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="GSADF Sequence")) + geom_line(aes(y = 1+ Log_BTC*0.8, color = "Log_BTC"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. - 1)/0.8, name = "Log_BTC")) + ggtitle("GSADF Test Bitcoin") + labs(x = "Date", y = "(GSADF Test Bitcoin)", color = "Legend") + scale_color_manual(values = colors_bitcoin)+ theme(legend.position="bottom",legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_bitcoin_gsadf_1<-subset(dateStampDf_bitcoin_gsadf, testSeq>=dateStamp) #GSADF Ethereum test_gsadf_ethereum_none <- rtadf(ethereum$ETH_Close, r0, test = "gsadf",type="drift", selectlags ="Fixed", lags=0) testDf_ethereum_gsadf<- list("test statistic" = test_gsadf_ethereum_none$testStat, "critical values" = cvs_gsadf_bitcoin$testCVs) # test results print(testDf_ethereum_gsadf) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_ethereum_gsadf <- cbind.data.frame("testSeq" = test_gsadf_ethereum_none$testSeq, "dateStamp" = cvs_gsadf_bitcoin$datestampCVs[,2], "date" = ethereum$Date, "Log_ETH"=log(ethereum$ETH_Close)) colors_ethereum <- c("95% critical values" = "blue", "GSADF Sequence" = "red", "Log_ETH" = "green") GSADF_Test_Ethereum<- ggplot(dateStampDf_ethereum_gsadf, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="GSADF Sequence")) + geom_line(aes(y = 5+ Log_ETH*1, color = "Log_ETH"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. - 5)/1, name = "Log_ETH")) + ggtitle("GSADF Test Ethereum") + labs(x = "Date", y = "(GSADF Test Ethereum)", color = "Legend") + scale_color_manual(values = colors_ethereum)+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_ethereum_gsadf<-subset(dateStampDf_ethereum_gsadf, testSeq>=dateStamp) #GSADF ripple test_gsadf_ripple_none <- rtadf(ripple$XRP_Close, r0, test = "gsadf",type="drift", selectlags ="Fixed", lags=0) testDf_ripple_gsadf<- list("test statistic" = test_gsadf_ripple_none$testStat, "critical values" = cvs_gsadf_bitcoin$testCVs) # test results print(testDf_ripple_gsadf) dateStampDf_ripple <- cbind.data.frame("testSeq" = test_gsadf_ripple_none$testSeq, "dateStamp" = cvs_gsadf_bitcoin$datestampCVs[,2], "date" = ripple$Date, "Log_XRP"=log(ripple$XRP_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) b <- 2 a <- b*10 colors_ripple<- c("95% critical values" = "blue", "GSADF Sequence" = "red", "Log_XRP" = "green") GSADF_Test_Ripple<-ggplot(dateStampDf_ripple, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="GSADF Sequence")) + geom_line(aes(y = a + Log_XRP*b, color = "Log_XRP"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. - a)/b, name = "Log_XRP")) + ggtitle("GSADF Test Ripple") + labs(x = "Date", y = "(GSADF Test Ripple)", color = "Legend") + scale_color_manual(values = colors_ripple)+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_ripple_gsadf<-subset(dateStampDf_ripple, testSeq>=dateStamp) install.packages("gridExtra") library(gridExtra) grid.arrange( # GSADF_Test_Ripple, # GSADF_Test_Ripple, GSADF_Test_Bitcoin_1, GSADF_Test_Ethereum, #SADF_Test_Tether, #SADF_Test_Bitcoin_Cash, #SADF_Test_Litecoin, #SADF_Test_EOS, #SADF_Test_Binance_Coin, #SADF_Test_Bitcoin_SV, #SADF_Test_Stellar, #SADF_Test_Tron, #SADF_Test_Cardano, ncol=2) obs<-nrow(litecoin) r0 <- round(obs*(0.01 + 1.8 / sqrt(obs))) set.seed(1234) cvs_gsadf_litecoin <- rtadfSimPar(obs, nrep = 1000, r0, test = "gsadf") # simulate critical values and date-stamping threshold test_gsadf_litecoin_ln_none <- rtadf(litecoin_ln$LTC_Close_ln, r0, test = "gsadf",type="none", lags=0 ) # estimate test statistic and date-stamping sequence testDf_litecoin_gsadf<- list("test statistic" = test_gsadf_litecoin_none$testStat, "critical values" = cvs_gsadf_litecoin$testCVs) # test results print(testDf_litecoin_gsadf) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_litecoin_gsadf <- cbind.data.frame("testSeq" = test_gsadf_litecoin_none$testSeq, "dateStamp" = cvs_gsadf_litecoin$datestampCVs[,2], "date" = litecoin$Date, "Log_LTC"=log(litecoin$LTC_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_litecoin_gsadf <- c("95% critical values" = "blue", "GSADF Sequence" = "red", "Log_LTC" = "green") GSADF_Test_Litecoin<- ggplot(dateStampDf_litecoin_gsadf, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="GSADF Sequence")) + geom_line(aes(y = 4+ Log_LTC*1.5, color = "Log_LTC"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -4)/1.5, name = "Log_LTC")) + ggtitle("GSADF Test Litecoin") + labs(x = "Date", y = "(GSADF Test Litecoin)", color = "Legend") + scale_color_manual(values = colors_litecoin_gsadf)+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot #bitcoin_sv obs_bitcoin_sv <- nrow(bitcoin_sv) # Sample size r0_bitcoin_sv <- round(obs_bitcoin_sv*(0.01 + 1.8 / sqrt(obs_bitcoin_sv))) # Minimal window size cvs_gsadf_bitcoin_sv <- rtadfSimPar(obs_bitcoin_sv, nrep = 1000, r0_bitcoin_sv, test = "gsadf") test_gsadf_bitcoin_sv_ln_none <- rtadf(bitcoin_sv_ln$BSV_Close_ln, r0_bitcoin_sv, test = "gsadf",type="none", lags=0 ) # estimate test statistic and date-stamping sequence testDf_bitcoin_sv_gsadf<- list("test statistic" = test_gsadf_bitcoin_sv_none$testStat, "critical values" = cvs_gsadf_bitcoin_sv$testCVs) # test results print(testDf_bitcoin_sv_gsadf) dateStampDf_bitcoin_sv_gsadf<- cbind.data.frame("testSeq" = test_gsadf_bitcoin_sv_none$testSeq, "dateStamp" = cvs_gsadf_bitcoin_sv$datestampCVs[,2], "date" = bitcoin_sv$Date, "Log_BSV"=log(bitcoin_sv$BSV_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_bitcoin_sv <- c("95% critical values" = "blue", "GSADF Sequence" = "red", "Log_BSV" = "green") GSADF_Test_Bitcoin_SV<- ggplot(dateStampDf_bitcoin_sv_gsadf, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="GSADF Sequence")) + geom_line(aes(y =1+ Log_BSV*0.5, color = "Log_BSV"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -1)/0.5, name = "Log_BSV")) + ggtitle("GSADF Test Bitcoin SV") + labs(x = "Date", y = "(GSADF Test Bitcoin SV)", color = "Legend") + scale_color_manual(values = colors_bitcoin_sv)+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_bitcoin_sv_gsadf<-subset(dateStampDf_bitcoin_sv_gsadf, testSeq>=dateStamp) #bitcoin_cash obs_bitcoin_cash <- nrow(bitcoin_cash) # Sample size r0_bitcoin_cash <- round(obs_bitcoin_cash*(0.01 + 1.8 / sqrt(obs_bitcoin_cash))) cvs_gsadf_bitcoin_cash <- rtadfSimPar(obs_bitcoin_cash, nrep = 1000, r0_bitcoin_cash, test = "gsadf") test_gsadf_bitcoin_cash_none <- rtadf(bitcoin_cash$BCH_Close, r0_bitcoin_cash, test = "gsadf",type="drift", selectlags ="Fixed", lags=0) testDf_bitcoin_cash_gsadf<- list("test statistic" = test_gsadf_bitcoin_cash_none$testStat, "critical values" = cvs_gsadf_bitcoin_cash$testCVs) # test results print(testDf_bitcoin_cash_gsadf) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_bitcoin_cash_gsadf <- cbind.data.frame("testSeq" = test_gsadf_bitcoin_cash_none$testSeq, "dateStamp" = cvs_gsadf_bitcoin_cash$datestampCVs[,2], "date" = bitcoin_cash$Date, "Log_BCH"=log(bitcoin_cash$BCH_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_bitcoin_cash <- c("95% critical values" = "blue", "GSADF Sequence" = "red", "Log_BCH" = "green") GSADF_Test_Bitcoin_Cash<- ggplot(dateStampDf_bitcoin_cash_gsadf, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="GSADF Sequence")) + geom_line(aes(y = 1+ Log_BCH*0.5, color = "Log_BCH"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -1)/0.5, name = "Log_BCH")) + ggtitle("GSADF Test Bitcoin Cash") + labs(x = "Date", y = "(GSADF Test Bitcoin Cash)", color = "Legend") + scale_color_manual(values = colors_bitcoin_cash)+ theme(legend.position="bottom",legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_bitcoin_cash<-subset(dateStampDf_bitcoin_cash_gsadf, testSeq>=dateStamp) # EOS obs_eos <- nrow(eos) # Sample size r0_eos <- round(obs_eos*(0.01 + 1.8 / sqrt(obs_eos))) cvs_gsadf_eos <- rtadfSimPar(obs_eos, nrep = 1000, r0_eos, test = "gsadf") test_gsadf_eos_none <- rtadf(eos$EOS_Close, r0_eos, test = "gsadf",type="drift", selectlags ="Fixed", lags=0) testDf_eos_gsadf<- list("test statistic" = test_gsadf_eos_none$testStat, "critical values" = cvs_gsadf_eos$testCVs) # test results print(testDf_eos_gsadf) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_eos_gsadf<- cbind.data.frame("testSeq" = test_gsadf_eos_none$testSeq, "dateStamp" = cvs_gsadf_eos$datestampCVs[,2], "date" = eos$Date, "Log_EOS"=log(eos$EOS_Close) ) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_eos_gsadf <- c("95% critical values" = "blue", "GSADF Sequence" = "red", "Log_EOS" = "green") GSADF_Test_EOS<- ggplot(dateStampDf_eos_gsadf, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="GSADF Sequence")) + geom_line(aes(y = 1+Log_EOS*1, color = "Log_EOS"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -1)/1, name = "Log_EOS")) + ggtitle("GSADF Test EOS") + labs(x = "Date", y = "(GSADF Test EOS)", color = "Legend") + scale_color_manual(values = colors_eos_gsadf)+ theme(legend.position="bottom",legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_eos_gsadf<-subset(dateStampDf_eos_gsadf, testSeq>=dateStamp) #GSADF Binance Coin obs_binance <- nrow(binance_coin) # Sample size r0_binance <- round(obs_binance*(0.01 + 1.8 / sqrt(obs_binance))) cvs_gsadf_binance_coin <- rtadfSimPar(obs_binance, nrep = 1000, r0_binance, test = "gsadf") test_gsadf_binance_coin_none <- rtadf(binance_coin$BNB_Close, r0_binance, test = "gsadf",type="drift", selectlags ="Fixed", lags=0) testDf_binance_coin_gsadf<- list("test statistic" = test_gsadf_binance_coin_none$testStat, "critical values" = cvs_gsadf_binance_coin$testCVs) # test results print(testDf_binance_coin_gsadf) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_binance_coin_gsadf<- cbind.data.frame("testSeq" = test_gsadf_binance_coin_none$testSeq, "dateStamp" = cvs_gsadf_binance_coin$datestampCVs[,2], "date" = binance_coin$Date, "Log_BNB"=log(binance_coin$BNB_Close) ) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_binance_coin_gsadf <- c("95% critical values" = "blue", "GSADF Sequence" = "red", "Log_BNB" = "green") GSADF_Test_Binance_Coin<- ggplot(dateStampDf_binance_coin_gsadf, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="GSADF Sequence")) + geom_line(aes(y = 1+Log_BNB*1, color = "Log_BNB"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -1)/1, name = "Log_BNB")) + ggtitle("GSADF Test Binance Coin") + labs(x = "Date", y = "(GSADF Test Binance Coin)", color = "Legend") + scale_color_manual(values = colors_binance_coin_gsadf)+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_binance_coin_gsadf<-subset(dateStampDf_binance_coin_gsadf, testSeq>=dateStamp) #GSADF TRON obs_tron <- nrow(tron) # Sample size r0_tron <- round(obs_tron*(0.01 + 1.8 / sqrt(obs_tron))) cvs_gsadf_tron <- rtadfSimPar(obs_tron, nrep = 1000, r0_tron, test = "gsadf") test_gsadf_tron_none <- rtadf(tron$TRX_Close, r0_tron, test = "gsadf",type="drift", selectlags ="Fixed", lags=0) testDf_tron_gsadf<- list("test statistic" = test_gsadf_tron_none$testStat, "critical values" = cvs_gsadf_tron$testCVs) # test results print(testDf_tron_gsadf) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_tron_gsadf<- cbind.data.frame("testSeq" = test_gsadf_tron_none$testSeq, "dateStamp" = cvs_gsadf_tron$datestampCVs[,2], "date" = tron$Date, "Log_TRX"=log(tron$TRX_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_tron_gsadf <- c("95% critical values" = "blue", "GSADF Sequence" = "red", "Log_TRX" = "green") GSADF_Test_Tron<- ggplot(dateStampDf_tron_gsadf, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="GSADF Sequence")) + geom_line(aes(y =15+ Log_TRX*2, color = "Log_TRX"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -15)/2, name = "Log_TRX")) + ggtitle("GSADF Test Tron") + labs(x = "Date", y = "(GSADF Test Tron)", color = "Legend") + scale_color_manual(values = colors_tron_gsadf)+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_tron_gsadf<-subset(dateStampDf_tron_gsadf, testSeq>=dateStamp) #CARDANO obs_cardano <- nrow(cardano) # Sample size r0_cardano <- round(obs_cardano*(0.01 + 1.8 / sqrt(obs_cardano))) # Minimal window size cvs_gsadf_cardano <- rtadfSimPar(obs_cardano, nrep = 1000, r0_cardano, test = "gsadf") test_gsadf_cardano_none <- rtadf(cardano$ADA_Close, r0_cardano, test = "gsadf",type="drift", selectlags ="Fixed", lags=0) testDf_cardano_gsadf<- list("test statistic" = test_gsadf_cardano_none$testStat, "critical values" = cvs_gsadf_cardano$testCVs) # test results print(testDf_cardano_gsadf) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_cardano_gsadf<- cbind.data.frame("testSeq" = test_gsadf_cardano_none$testSeq, "dateStamp" = cvs_gsadf_cardano$datestampCVs[,2], "date" = cardano$Date, "Log_ADA"=log(cardano$ADA_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_cardan_gsadf <- c("95% critical values" = "blue", "GSADF Sequence" = "red", "Log_ADA" = "green") GSADF_Test_Cardano<- ggplot(dateStampDf_cardano_gsadf, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="GSADF Sequence")) + geom_line(aes(y =8+ Log_ADA*2, color = "Log_ADA"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -8)/2, name = "Log_ADA")) + ggtitle("GSADF Test Cardano") + labs(x = "Date", y = "(GSADF Test Cardano)", color = "Legend") + scale_color_manual(values = colors_cardan_gsadf)+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot date_stamping_cardano<-subset(dateStampDf_cardano_gsadf, testSeq>=dateStamp) library(gridExtra) grid.arrange( #GSADF_Test_Ethereum, #SADF_Test_Tether, #GSADF_Test_Bitcoin_Cash, #SADF_Test_Litecoin, #GSADF_Test_EOS, #GSADF_Test_Binance_Coin, #GSADF_Test_Bitcoin_SV, #SADF_Test_Stellar, GSADF_Test_Tron, #GSADF_Test_Cardano, ncol=2) obs<-nrow(stellar) r0 <- round(obs*(0.01 + 1.8 / sqrt(obs))) cvs_gsadf_stellar <- rtadfSimPar(obs, nrep = 1000, r0, test = "gsadf") # simulate critical values and date-stamping threshold test_gsadf_stellar_none <- rtadf(stellar$XLM_Close, r0, test = "gsadf",type="drift", selectlags ="Fixed", lags=0) test_gsadf_stellar_drift <- rtadf(stellar$XLM_Close, r0, test = "gsadf",type="drift",selectlags ="Fixed", lags=0) # estimate test statistic and date-stamping sequence testDf_stellar_gsadf<- list("test statistic" = test_gsadf_stellar_drift$testStat, "critical values" = cvs_gsadf_stellar$testCVs) # test results print(testDf_stellar_gsadf) #dateStampDf2<- ts(cbind(test_sadf_ethereum$testSeq, cvs_sadf_ethereum$datestampCVs[,2]), start = c(2015,1), frequency = 365) # data for datestamping procedure dateStampDf_stellar_gsadf<- cbind.data.frame("testSeq" = test_gsadf_stellar_drift$testSeq, "dateStamp" = cvs_gsadf_stellar$datestampCVs[,2], "date" = stellar$Date, "Log_XML"=log(stellar$XLM_Close)) #ts.plot(dateStampDf2, plot.type = "single", col=c("blue", "red")) colors_stellar_gsadf <- c("95% critical values" = "blue", "GSADF Sequence" = "red", "Log_XML" = "green") GSADF_Test_Stellar<- ggplot(dateStampDf_stellar_gsadf, aes(x = date)) + geom_line(aes(y = dateStamp, color = "95% critical values")) + geom_line(aes(y=testSeq, color="GSADF Sequence")) + geom_line(aes(y =10+ Log_XML*2, color = "Log_XML"))+ scale_y_continuous("testSeq", sec.axis = sec_axis(~ (. -10)/2, name = "Log_XML")) + ggtitle("GSADF Test Stellar") + labs(x = "Date", y = "(GSADF Test Stellar)", color = "Legend") + scale_color_manual(values = colors_stellar_gsadf)+ theme(legend.position="bottom", legend.direction="vertical", axis.title.y.left=element_text(color="red"), axis.text.y.left=element_text(color="red"), axis.title.y.right=element_text(color="green"), axis.text.y.right=element_text(color="green"))+ themePlot size <- 12 date_stamping_stellar_gsadf<-subset(dateStampDf_stellar_gsadf, testSeq>=dateStamp) install.packages("gridExtra") library(gridExtra) grid.arrange( # GSADF_Test_Stellar, #GSADF_Test_Stellar, GSADF_Test_Bitcoin_1, GSADF_Test_Ethereum, #SADF_Test_Tether, #SADF_Test_Bitcoin_Cash, #SADF_Test_Litecoin, #SADF_Test_EOS, #SADF_Test_Binance_Coin, #SADF_Test_Bitcoin_SV, #SADF_Test_Stellar, #SADF_Test_Tron, #SADF_Test_Cardano, ncol=2) # correlation matrix if(!require(devtools)) install.packages("devtools") devtools::install_github("kassambara/ggcorrplot") library(ggcorrplot) subset2016<-subset(data_all, data_all$Date>"2015-12-31" & data_all$Date<="2016-12-31") subset2016<-subset2016[,2:ncol(subset2016)] subset2017<-subset(data_all, data_all$Date>"2017-10-01" & data_all$Date<="2017-12-31") subset2017<-subset2017[,2:ncol(subset2017)] subset2018<-subset(data_all, data_all$Date>"2017-12-31") subset2018<-subset2018[,2:ncol(subset2018)] subset2019<-subset(data_all, Date>="2018-11-09") subset2019<-subset2019[,2:ncol(subset2019)] corr2016<- round(cor(subset2016), 2) corr2017<- round(cor(subset2017), 2) corr2018<- round(cor(subset2018), 2) corr2019<- round(cor(subset2019), 2) corr<-round(cor(data_all), 2) head(corr) # matrix of correlation p-values p.mat <- cor_pmat(data_all) head(p.mat) # Visualize the correlation matrix/heatmap # -------------------------------- # method = "square" (default) #data_all$Date<-as.Date(data_all$Date, origin = "1970-01-01") corr_plot2016<-ggcorrplot(corr2016, hc.order = FALSE, show.legend = TRUE, outline.col = "white", lab = TRUE, title="Pearson Correlation Coefficient Matrix 2016") corr_plot2017<-ggcorrplot(corr2017, hc.order = FALSE, show.legend = TRUE, outline.col = "white", lab = TRUE, title="Pearson Correlation Coefficient Matrix 2017") corr_plot2018<-ggcorrplot(corr2018, hc.order = FALSE, show.legend = TRUE, outline.col = "white", lab = TRUE, title="Pearson Correlation Coefficient Matrix 2018") corr_plot2019<-ggcorrplot(corr2019, hc.order = FALSE, show.legend = TRUE, outline.col = "white", lab = TRUE, title="Pearson Correlation Coefficient Matrix 2018-2019") corr_plot<-ggcorrplot(corr, hc.order = FALSE, show.legend = TRUE, outline.col = "white", lab = TRUE, title="Pearson Correlation Coefficient Matrix") ggcorrplot(round(cor(list(subset2016), 2)), hc.order = TRUE, show.legend = TRUE, outline.col = "white", lab = TRUE) #Entry Data Analysis install.packages("stats") library(stats) summary(bitcoin$BTC_Close) qqnorm(bitcoin$BTC_Close) qqline(bitcoin$BTC_Close) acf(bitcoin$BTC_Close) sd(bitcoin$BTC_Close) install.packages("moments") library(moments) skewness(bitcoin$BTC_Close) kurtosis(bitcoin$BTC_Close) jarque.test(bitcoin$BTC_Close) returns_bitcoin_log<- diff(log(bitcoin$BTC_Close)) returns_ethereum_log<-diff(log(ethereum$ETH_Close)) returns_ripple_log<- diff(log(ripple$XRP_Close)) returns_tether_log<- diff(log(tether$USDT_Close)) returns_bitcoin_cash_log<- diff(log(bitcoin_cash$BCH_Close)) returns_litecoin_log<- diff(log(litecoin$LTC_Close)) returns_eos_log<- diff(log(eos$EOS_Close)) returns_binance_coin_log<- diff(log(binance_coin$BNB_Close)) returns_bitcoin_sv_log<- diff(log(bitcoin_sv$BSV_Close)) returns_stellar_log<- diff(log(stellar$XLM_Close)) returns_tron_log<- diff(log(tron$TRX_Close)) returns_cardano_log<- diff(log(cardano$ADA_Close)) returns_bitcoin <- diff(bitcoin$BTC_Close)/bitcoin$BTC_Close[-length(bitcoin$BTC_Close)] returnticker_bitcoin <- data.frame(bitcoin$Date[-length(bitcoin$Date)],returns_bitcoin) plot(returnticker_bitcoin$bitcoin.Date..length.bitcoin.Date.., returnticker_bitcoin$returns_bitcoin, xlab="Date", ylab="Returns", typ='l') summary(returnticker_bitcoin$returns_bitcoin) qqnorm(returnticker_bitcoin$returns_bitcoin) qqline(returnticker_bitcoin$returns_bitcoin) acf(returnticker_bitcoin$returns_bitcoin) sd(returnticker_bitcoin$returns_bitcoin) hist_bitcoin<-hist(returnticker_bitcoin$returns_bitcoin) # get column names colnames(bitcoin) #TEST FOR EXPONENTIAL GROWTH # estimate the parameters fit <- fitdistr(bitcoin$BTC_Close, "exponential") show(fit) # goodness of fit test ks.test(bitcoin$BTC_Close, "pexp", fit$estimate) # p-value > 0.05 -> distribution not refused #JARQUE-BERA TEST plot_hist1<-hist(bitcoin$BTC_Close) plot(plot_hist1) jarque.bera.test(bitcoin$BTC_Close) ##single window LPPL install.packages("cmaes") install.packages("Metrics") install.packages("nortest") library('cmaes') library('quantmod') library('zoo') library('nortest') library('Metrics') # Intersections for date stamping library(dplyr) ##dateStampDf %>% ## select(testSeq, dateStamp, date) %>% ##filter(round(testSeq, 6)==round(dateStamp,6)) dateStampDf %>% select(testSeq, dateStamp, date) %>% filter(date>'2018-01-01'&date<'2018-03-01' ) dateStampDf %>% select(testSeq, dateStamp, date) %>% filter(testSeq<0 ) # 2018-01-29 #LPPL if (!require("devtools")) install.packages("devtools") devtools::install_github("deanfantazzini/bubble") library("bubble") library("bitcoinFinance") #BITCOIN bitcoin_subset<-subset(bitcoin,Date>="2016-08-15" & Date<="2017-11-27") #lppl_3step_bitcoin<-lppl_estimate_rob_3s(bitcoin_subset$BTC_Close,lppl_1step_bitcoin,lppl_2step_bitcoin) lppl_estimate_rob_3all_bitcoin<-lppl_estimate_rob_3all(bitcoin_subset$BTC_Close, par_start = c(bet=0.5, ome=6, A=log(bitcoin_subset$BTC_Close[NROW(bitcoin_subset$BTC_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) lppl_estimate_rob_3all_bitcoin$param.JLS[2] #lppl_simulate_FS_bitcoin<-lppl_simulate_FS(T=1500, lppl_3step) AIC_bitcoin<-nrow(data.frame(lppl_estimate_rob_3all_bitcoin$resids))*log(sum(lppl_estimate_rob_3all_bitcoin$resids^2)/nrow(data.frame(lppl_estimate_rob_3all_bitcoin$resids)))+2*7 print(AIC_bitcoin) kpss.test(lppl_estimate_rob_3all_bitcoin$resids) RMSE(lppl_estimate_rob_3all_bitcoin$resids) bitcoin_subset$Date[1]+lppl_estimate_rob_3all_bitcoin$param.JLS[7] n_fit<-round(lppl_estimate_rob_3all_bitcoin$param.JLS[7]) sdum=rep(1,n_fit) tt_sim=seq(1, n_fit, 1) f_t=(lppl_estimate_rob_3all_bitcoin$param.FS[7] - tt_sim)^lppl_estimate_rob_3all_bitcoin$param.FS[1] g_t=( (lppl_estimate_rob_3all_bitcoin$param.FS[7] - tt_sim)^lppl_estimate_rob_3all_bitcoin$param.FS[1] )*cos( lppl_estimate_rob_3all_bitcoin$param.FS[2]*log(lppl_estimate_rob_3all_bitcoin$param.FS[7] - tt_sim) ) h_t=( (lppl_estimate_rob_3all_bitcoin$param.FS[7] - tt_sim)^lppl_estimate_rob_3all_bitcoin$param.FS[1] )*sin( lppl_estimate_rob_3all_bitcoin$param.FS[2]*log(lppl_estimate_rob_3all_bitcoin$param.FS[7] - tt_sim) ) Y_bitcoin=log(bitcoin$BTC_Close) RMSE <-function(x){ sqrt(mean((x)^2)) } #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_bitcoin = sdum*lppl_estimate_rob_3all_bitcoin$param.FS[3] + lppl_estimate_rob_3all_bitcoin$param.FS[4] *f_t + lppl_estimate_rob_3all_bitcoin$param.FS[5]*g_t + lppl_estimate_rob_3all_bitcoin$param.FS[6] *h_t abc<- data.frame(subset(bitcoin,Date>="2016-02-15" & Date<="2018-01-13") , Yfit_bitcoin) Yfit_bitcoin_df=data.frame(subset(bitcoin, Date>="2016-08-15" & Date<=(bitcoin_subset$Date[1]+lppl_estimate_rob_3all_bitcoin$param.JLS[7]-1)), Yfit_bitcoin ) Y_bitcoin<-subset(bitcoin, Date>="2016-08-15" & Date<="2019-01-15") Y_df = data.frame(Y_bitcoin$Date, Yfit_bitcoin_df) df = list(Date=Y_bitcoin$Date, Yfit_bitcoin=Yfit_bitcoin_df$Yfit_bitcoin, Y_bitcoin=log(Y_bitcoin$BTC_Close)) attributes(df) = list(names = names(df), row.names=1:max(length(Y_bitcoin$Date), length(Yfit_bitcoin)), class='data.frame') df colors_b<-c("LPPL Bitcoin Fit"="red", "Log Bitcoin price"="blue") Y_fitted_actual_bitcoin<-ggplot(data = na.omit(df), aes(x = Date)) + geom_line(aes( y = Y_bitcoin, color = "Log Bitcoin price" ))+ geom_line(aes (y=Yfit_bitcoin, color = "LPPL Bitcoin Fit")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Bitcoin") + # xlab(label='Date') + # ylab(label='Fitted VS Actual') + labs(x = "Date", y = "Fitted VS Actual", color = "") + scale_color_manual(values = colors_b)+ # coord_cartesian(ylim = c(-0.01, 0.048)) + scale_x_date(labels=date_format("%y-%m"))+ theme(legend.position="bottom", legend.direction="vertical")+ themePlot Y_fitted_actual_bitcoin #BITCOIN PREDICTION bitcoin_pr<-subset(bitcoin,Date>="2019-03-09" & Date<="2019-06-29") #lppl_3step_bitcoin<-lppl_estimate_rob_3s(bitcoin_subset$BTC_Close,lppl_1step_bitcoin,lppl_2step_bitcoin) lppl_estimate_rob_3all_bitcoin_pr<-lppl_estimate_rob_3all(bitcoin_pr$BTC_Close, par_start = c(bet=0.5, ome=6, A=log(bitcoin_pr$BTC_Close[NROW(bitcoin_pr$BTC_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) lppl_estimate_rob_3all_bitcoin_pr$param.JLS[2] AIC_bitcoin_pr<-nrow(data.frame(lppl_estimate_rob_3all_bitcoin_pr$resids))*log(sum(lppl_estimate_rob_3all_bitcoin_pr$resids^2)/nrow(data.frame(lppl_estimate_rob_3all_bitcoin_pr$resids)))+2*7 print(AIC_bitcoin_pr) kpss.test(lppl_estimate_rob_3all_bitcoin_pr$resids) RMSE(lppl_estimate_rob_3all_bitcoin_pr$resids) bitcoin_pr$Date[1]+lppl_estimate_rob_3all_bitcoin_pr$param.JLS[7] n_pr<-round(lppl_estimate_rob_3all_bitcoin_pr$param.JLS[7]) sdum_pr=rep(1,n_pr) tt_sim_pr=seq(1, n_pr, 1) f_t_pr=(lppl_estimate_rob_3all_bitcoin_pr$param.FS[7] - tt_sim_pr)^lppl_estimate_rob_3all_bitcoin_pr$param.FS[1] g_t_pr=( (lppl_estimate_rob_3all_bitcoin_pr$param.FS[7] - tt_sim_pr)^lppl_estimate_rob_3all_bitcoin_pr$param.FS[1] )*cos( lppl_estimate_rob_3all_bitcoin_pr$param.FS[2]*log(lppl_estimate_rob_3all_bitcoin_pr$param.FS[7] - tt_sim_pr) ) h_t_pr=( (lppl_estimate_rob_3all_bitcoin_pr$param.FS[7] - tt_sim_pr)^lppl_estimate_rob_3all_bitcoin_pr$param.FS[1] )*sin( lppl_estimate_rob_3all_bitcoin_pr$param.FS[2]*log(lppl_estimate_rob_3all_bitcoin_pr$param.FS[7] - tt_sim_pr) ) Yfit_bitcoin_pr = data.frame(sdum_pr*lppl_estimate_rob_3all_bitcoin_pr$param.FS[3] + lppl_estimate_rob_3all_bitcoin_pr$param.FS[4] *f_t_pr + lppl_estimate_rob_3all_bitcoin_pr$param.FS[5]*g_t_pr + lppl_estimate_rob_3all_bitcoin_pr$param.FS[6] *h_t_pr) names(Yfit_bitcoin_pr)<-c("Fitted") Y_bitcoin_pr<-subset(bitcoin, Date>="2019-03-08" & Date<="2019-07-02") Y_df = data.frame(Y_bitcoin_pr$Date, Yfit_bitcoin_pr) df_pr = list(Date=Y_bitcoin_pr$Date, Yfit_bitcoin_pr_all=Yfit_bitcoin_pr_all$Fitted,Yfit_bitcoin_pr=Yfit_bitcoin_pr$Fitted, Y_bitcoin=log(Y_bitcoin_pr$BTC_Close)) attributes(df_pr) = list(names = names(df_pr), row.names=1:max(length(Y_bitcoin_pr$Date), length(Yfit_bitcoin_pr)), class='data.frame') df_pr # <-Yfit_bitcoin_pr bind<-data.frame(Yfit_bitcoin_pr[(nrow(Yfit_bitcoin_pr_all)+1):(nrow(Yfit_bitcoin_pr_all)+15),1]) names(bind)<-c("Fitted") Yfit_bitcoin_pr_all<-rbind(Yfit_bitcoin_pr_all, bind) library(ggplot2) library(scales) colrs_pr<-c("Actual-Log Bitcoin Price"="blue", "Fitted Rolling LPPL"="red", "Fitted LPPL"="green" ) Y_fitted_actual_bitcoin_pr<-ggplot(data = na.omit(df_pr), aes(x = Date)) + geom_line(aes(y = Y_bitcoin, color="Actual-Log Bitcoin Price")) + geom_line(aes (y=Yfit_bitcoin_pr_all, color = "Fitted Rolling LPPL")) + geom_line(aes (y=Yfit_bitcoin_pr, color = "Fitted LPPL")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Bitcoin Prediction") + xlab(label='Date') + ylab(label='Fitted VS Actual') + labs(x = "Date", y = "Fitted VS Actual", color = "") + scale_color_manual(values = colrs_pr)+ theme(legend.position="bottom", legend.direction="horizontal")+ # coord_cartesian(ylim = c(-0.01, 0.048)) + scale_x_date(labels=date_format("%y-%m"))+ themePlot # colrs_pr<-c("Actual-Log Bitcoin Price"="blue", "Fitted Rolling LPPL"="red", "Fitted LPPL"="green" ) # Y_fitted_actual_bitcoin_pr<-ggplot(data = na.omit(df_pr), aes(x = Date)) + # geom_line(aes(y = Y_bitcoin, color = "Actual Log-Bitcoin Price", size = 0.5)) + # geom_line(aes (y=Yfit_bitcoin_pr_all, na.rm = TRUE), color = "Fitted Rolling LPPL", size = 0.5) + # geom_line(aes (y=Yfit_bitcoin_pr, na.rm = TRUE), color = "Fitted LPPL", size = 0.5) + # #scale_x_discrete(na.translate = FALSE)+ # ggtitle("LPPL Bitcoin Prediction") + # xlab(label='Date') + # ylab(label='Fitted VS Actual') + # labs(x = "Date", # y = "('Fitted VS Actual')", # color = "Legend") + # scale_color_manual(values = colrs_pr)+ # # coord_cartesian(ylim = c(-0.01, 0.048)) + # scale_x_date(labels=date_format("%Y-%m"))+ # themePlot Y_fitted_actual_bitcoin_pr #ETHEREUM ethereum_subset<-subset(ethereum, Date>="2017-11-20" & Date<="2018-01-04")#Date>="2017-07-11" & Date<="2018-01-10") lppl_estimate_rob_3all_ethereum<-lppl_estimate_rob_3all(ethereum_subset$ETH_Close, par_start = c(bet=0.5, ome=6, A=log(ethereum_subset$ETH_Close[NROW(ethereum_subset$ETH_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) ##lppl_simulate_FS_ethereum<-lppl_simulate_FS(T=1500, lppl_3step) lppl_estimate_rob_3all_ethereum lppl_estimate_rob_3all_ethereum$param.JLS[2] AIC_ethereum<-nrow(data.frame(lppl_estimate_rob_3all_ethereum$resids))*log((sum(lppl_estimate_rob_3all_ethereum$resids^2))/nrow(data.frame(lppl_estimate_rob_3all_ethereum$resids)))+2*7 print(AIC_ethereum) kpss.test(lppl_estimate_rob_3all_ethereum$resids) RMSE(lppl_estimate_rob_3all_ethereum$resids) ethereum_subset$Date[1]+lppl_estimate_rob_3all_ethereum$param.JLS[7] n_fit_eth<-round(lppl_estimate_rob_3all_ethereum$param.JLS[7]) sdum_eth=rep(1,n_fit_eth) tt_sim_eth=seq(1, n_fit_eth, 1) f_t_eth=(lppl_estimate_rob_3all_ethereum$param.FS[7] - tt_sim_eth)^lppl_estimate_rob_3all_ethereum$param.FS[1] g_t_eth=( (lppl_estimate_rob_3all_ethereum$param.FS[7] - tt_sim_eth)^lppl_estimate_rob_3all_ethereum$param.FS[1] )*cos( lppl_estimate_rob_3all_ethereum$param.FS[2]*log(lppl_estimate_rob_3all_ethereum$param.FS[7] - tt_sim_eth) ) h_t_eth=( (lppl_estimate_rob_3all_ethereum$param.FS[7] - tt_sim_eth)^lppl_estimate_rob_3all_ethereum$param.FS[1] )*sin( lppl_estimate_rob_3all_ethereum$param.FS[2]*log(lppl_estimate_rob_3all_ethereum$param.FS[7] - tt_sim_eth) ) Y_ethereum=log(ethereum$ETH_Close) #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_eth = sdum_eth*lppl_estimate_rob_3all_ethereum$param.FS[3] + lppl_estimate_rob_3all_ethereum$param.FS[4] *f_t_eth + lppl_estimate_rob_3all_ethereum$param.FS[5]*g_t_eth + lppl_estimate_rob_3all_ethereum$param.FS[6] *h_t_eth Yfit_ethereum_df=data.frame(subset(ethereum, Date>="2017-11-20" & Date<=round(ethereum_subset$Date[1]+lppl_estimate_rob_3all_ethereum$param.JLS[7])-1),Yfit_eth ) Y_ethereum<-subset(ethereum, Date>="2017-11-20" & Date<="2019-01-15") Y_df = data.frame(Y_ethereum$Date, Yethereum_df) df_ethereum = list(Date=Y_ethereum$Date, Yfit_eth=Yfit_eth, Y_ethereum=log(Y_ethereum$ETH_Close)) attributes(df_ethereum) = list(names = names(df_ethereum), row.names=1:max(length(Y_ethereum$Date), length(Yfit_eth)), class='data.frame') df_ethereum colors_e<-c("LPPL Ethereum Fit"="red", "Log Ethereum price"="blue") Y_fitted_actual_ethereum<-ggplot(data = na.omit(df_ethereum), aes(x = Date)) + geom_line(aes(y = Y_ethereum, color = "Log Ethereum price")) + geom_line(aes (y=Yfit_eth, color = "LPPL Ethereum Fit")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Ethereum") + # xlab(label='Date') + # ylab(label='Fitted VS Actual') + labs(x = "Date", y = "Fitted VS Actual", color = "") + scale_color_manual(values = colors_e)+ # coord_cartesian(ylim = c(-0.01, 0.048)) + theme(legend.position="bottom", legend.direction="vertical")+ scale_x_date(labels=date_format("%y-%m"))+ themePlot Y_fitted_actual_ethereum grid.arrange(Y_fitted_actual_bitcoin, Y_fitted_actual_ethereum,nrow=1) #ETHEREUM PREDICTION ethereum_pr<-subset(ethereum, Date>="2019-05-15" & Date<=ethereum_pr$Date[1]+14+14+14+4)#Date>="2017-07-11" & Date<="2018-01-10") lppl_estimate_rob_3all_ethereum_pr<-lppl_estimate_rob_3all(ethereum_pr$ETH_Close, par_start = c(bet=0.5, ome=6, A=log(ethereum_pr$ETH_Close[NROW(ethereum_pr$ETH_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) ##lppl_simulate_FS_ethereum<-lppl_simulate_FS(T=1500, lppl_3step) lppl_estimate_rob_3all_ethereum_pr lppl_estimate_rob_3all_ethereum_pr$param.JLS[2] AIC_ethereum<-nrow(data.frame(lppl_estimate_rob_3all_ethereum_pr$resids))*log((sum(lppl_estimate_rob_3all_ethereum_pr$resids^2))/nrow(data.frame(lppl_estimate_rob_3all_ethereum_pr)))+2*7 print(AIC_ethereum) kpss.test(lppl_estimate_rob_3all_ethereum_pr$resids) RMSE(lppl_estimate_rob_3all_ethereum_pr$resids) ethereum_pr$Date[1]+lppl_estimate_rob_3all_ethereum_pr$param.JLS[7] n_fit_eth_pr<-round(lppl_estimate_rob_3all_ethereum_pr$param.JLS[7]) sdum_eth_pr=rep(1,n_fit_eth_pr) tt_sim_eth_pr=seq(1, n_fit_eth_pr, 1) f_t_eth_pr=(lppl_estimate_rob_3all_ethereum_pr$param.FS[7] - tt_sim_eth_pr)^lppl_estimate_rob_3all_ethereum_pr$param.FS[1] g_t_eth_pr=( (lppl_estimate_rob_3all_ethereum_pr$param.FS[7] - tt_sim_eth_pr)^lppl_estimate_rob_3all_ethereum_pr$param.FS[1] )*cos( lppl_estimate_rob_3all_ethereum_pr$param.FS[2]*log(lppl_estimate_rob_3all_ethereum_pr$param.FS[7] - tt_sim_eth_pr) ) h_t_eth_pr=( (lppl_estimate_rob_3all_ethereum_pr$param.FS[7] - tt_sim_eth_pr)^lppl_estimate_rob_3all_ethereum_pr$param.FS[1] )*sin( lppl_estimate_rob_3all_ethereum_pr$param.FS[2]*log(lppl_estimate_rob_3all_ethereum_pr$param.FS[7] - tt_sim_eth_pr) ) Y_ethereum=log(ethereum$ETH_Close) #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_eth_pr = data.frame(sdum_eth_pr*lppl_estimate_rob_3all_ethereum_pr$param.FS[3] + lppl_estimate_rob_3all_ethereum_pr$param.FS[4] *f_t_eth_pr + lppl_estimate_rob_3all_ethereum_pr$param.FS[5]*g_t_eth_pr + lppl_estimate_rob_3all_ethereum_pr$param.FS[6] *h_t_eth_pr) names(Yfit_eth_pr)<-c("Fitted") # Yfit_eth_pr_all<-Yfit_eth_pr bind_eth<-data.frame(Yfit_eth_pr[32:nrow(Yfit_eth_pr),1]) names(bind_eth)<-c("Fitted") Yfit_eth_pr_all<-rbind(Yfit_eth_pr_all, bind_eth) names(Yfit_eth_pr)<-c("Fitted") dates<-data.frame(seq(as.Date("2019/7/2"), as.Date("2019/7/13"), "day")) names(dates)<-c("Date") Y_eth_pr<-subset(ethereum, Date>="2019-05-15" & Date<="2019-07-13", select=c("Date")) names(Y_eth_pr)<-c("Date") Y_eth_pr<-rbind(Y_eth_pr, dates) Y_eth_pr_2<-subset(ethereum, Date>="2019-05-15" & Date<="2019-07-13") Yfit_ethereum_df_pr = data.frame(Y_eth_pr$Date, Y_eth_pr) df_eth_pr = list(Date=Y_eth_pr$Date, Yfit_eth_pr_all=Yfit_eth_pr_all$Fitted,Yfit_eth_pr=Yfit_eth_pr$Fitted, Y_eth=log(Y_eth_pr_2$ETH_Close)) attributes(df_eth_pr) = list(names = names(df_eth_pr), row.names=1:max(length(Y_eth_pr$Date), length(Yfit_eth_pr)), class='data.frame') df_eth_pr<-df_eth_pr[1:59,] colrs_pr<-c("Actual Log Ethereum Price"="blue", "Fitted Rolling LPPL"="red", "Fitted LPPL"="green" ) Y_fitted_actual_eth_pr<-ggplot(data = na.omit(df_eth_pr), aes(x = Date)) + geom_line(aes(y = Y_eth, color="Actual Log Ethereum Price")) + geom_line(aes (y=Yfit_eth_pr_all, color = "Fitted Rolling LPPL")) + geom_line(aes (y=Yfit_eth_pr, color = "Fitted LPPL")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Ethereum Prediction") + xlab(label='Date') + ylab(label='Fitted VS Actual') + labs(x = "Date", y = "Fitted VS Actual", color = " ") + scale_color_manual(values = colrs_pr)+ # coord_cartesian(ylim = c(-0.01, 0.048)) + theme(legend.position="bottom", legend.direction="horizontal")+ scale_x_date(labels=date_format("%Y-%m"))+ themePlot #RIPPLE ripple_subset<-subset(ripple, Date>= "2017-08-22" & Date<= "2018-01-01")# 23.03.2017-25.06.2017,13.12.2017-13.01.2018 lppl_estimate_rob_3all_ripple<-lppl_estimate_rob_3all(ripple_subset$XRP_Close, par_start = c(bet=0.5, ome=6, A=log(ripple_subset$XRP_Close[NROW(ripple_subset$XRP_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) lppl_estimate_rob_3all_ripple$param.JLS[2] RMSE(lppl_estimate_rob_3all_ripple$resids) AIC_ripple<-nrow(data.frame(lppl_estimate_rob_3all_ripple$resids))*log((sum(lppl_estimate_rob_3all_ripple$resids^2))/nrow(data.frame(lppl_estimate_rob_3all_ripple$resids)))+2*7 print(AIC_ripple) kpss.test(lppl_estimate_rob_3all_ripple$resids) RMSE(lppl_estimate_rob_3all_ripple$resids) ripple_subset$Date[1]+lppl_estimate_rob_3all_ripple$param.JLS[7] n_fit_ripple<-round(lppl_estimate_rob_3all_ripple$param.JLS[7]) sdum_ripple=rep(1,n_fit_ripple) tt_sim_ripple=seq(1, n_fit_ripple, 1) f_t_ripple=(lppl_estimate_rob_3all_ripple$param.FS[7] - tt_sim_ripple)^lppl_estimate_rob_3all_ripple$param.FS[1] g_t_ripple=( (lppl_estimate_rob_3all_ripple$param.FS[7] - tt_sim_ripple)^lppl_estimate_rob_3all_ripple$param.FS[1] )*cos( lppl_estimate_rob_3all_ripple$param.FS[2]*log(lppl_estimate_rob_3all_ripple$param.FS[7] - tt_sim_ripple) ) h_t_ripple=( (lppl_estimate_rob_3all_ripple$param.FS[7] - tt_sim_ripple)^lppl_estimate_rob_3all_ripple$param.FS[1] )*sin( lppl_estimate_rob_3all_ripple$param.FS[2]*log(lppl_estimate_rob_3all_ripple$param.FS[7] - tt_sim_ripple) ) Y_ripple=log(ripple$XRP_Close) #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_ripple = sdum_ripple*lppl_estimate_rob_3all_ripple$param.FS[3] + lppl_estimate_rob_3all_ripple$param.FS[4] *f_t_ripple + lppl_estimate_rob_3all_ripple$param.FS[5]*g_t_ripple + lppl_estimate_rob_3all_ripple$param.FS[6] *h_t_ripple Yfit_ripple_df=data.frame(subset(ripple, Date>= "2017-08-22"& Date<=round(ripple_subset$Date[1]+lppl_estimate_rob_3all_ripple$param.JLS[7])-1),Yfit_ripple ) Y_ripple<-subset(ripple, Date>= "2017-08-22" & Date<="2019-01-15") df_ripple = list(Date=Y_ripple$Date, Yfit_ripple=Yfit_ripple, Y_ripple=log(Y_ripple$XRP_Close)) attributes(df_ripple) = list(names = names(df_ripple), row.names=1:max(length(Y_ripple$Date), length(Yfit_ripple)), class='data.frame') df_ripple colors_r<-c("LPPL Ripple Fit"="red", "Log Ripple price"="blue") Y_fitted_actual_ripple<-ggplot(data = na.omit(df_ripple), aes(x = Date) )+ geom_line(aes(y=Y_ripple, color = "Log Ripple price")) + geom_line(aes (y=Yfit_ripple, color = "LPPL Ripple Fit")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Ripple") + # xlab(label='Date') + # ylab(label='Fitted VS Actual') + labs(x = "Date", y = "Fitted VS Actual", color = "") + scale_color_manual(values = colors_r)+ scale_x_date(labels=date_format("%y-%m"))+ theme(legend.position="bottom", legend.direction="vertical")+ # coord_cartesian(ylim = c(-0.01, 0.048)) + themePlot Y_fitted_actual_ripple #TETHER tether_subset<-subset(tether, Date<= "") lppl_estimate_rob_3all_tether<-lppl_estimate_rob_3all(tether_subset$_Close, par_start = c(bet=0.5, ome=6, A=log(tether_subset$_Close[NROW(tether_subset$_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) ##lppl_simulate_FS_ethereum<-lppl_simulate_FS(T=1500, lppl_3step) #BITCOIN CASH bitcoin_cash_subset<-subset(bitcoin_cash, Date>= "2017-09-15" & Date<= "2017-12-18") #15.09.2017-20.06.2018, 08.02.2019-01.07.2019 15.09.2017 21.12.2017 lppl_estimate_rob_3all_bitcoin_cash<-lppl_estimate_rob_3all(bitcoin_cash_subset$BCH_Close, par_start = c(bet=0.5, ome=6, A=log(bitcoin_cash_subset$BCH_Close[NROW(bitcoin_cash_subset$BCH_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) ##lppl_simulate_FS_ethereum<-lppl_simulate_FS(T=1500, lppl_3step) lppl_estimate_rob_3all_bitcoin_cash AIC_bch<-nrow(data.frame(lppl_estimate_rob_3all_bitcoin_cash$resids))*log((sum(lppl_estimate_rob_3all_bitcoin_cash$resids^2))/nrow(data.frame(lppl_estimate_rob_3all_bitcoin_cash$resids)))+2*7 print(AIC_bch) kpss.test(lppl_estimate_rob_3all_bitcoin_cash$resids) RMSE(lppl_estimate_rob_3all_bitcoin_cash$resids) bitcoin_cash_subset$Date[1]+lppl_estimate_rob_3all_bitcoin_cash$param.JLS[7] n_fit_bch<-round(lppl_estimate_rob_3all_bitcoin_cash$param.JLS[7]) sdum_bch=rep(1,n_fit_bch) tt_sim_bch=seq(1, n_fit_bch, 1) f_t_bch=(lppl_estimate_rob_3all_bitcoin_cash$param.FS[7] - tt_sim_bch)^lppl_estimate_rob_3all_bitcoin_cash$param.FS[1] g_t_bch=( (lppl_estimate_rob_3all_bitcoin_cash$param.FS[7] - tt_sim_bch)^lppl_estimate_rob_3all_bitcoin_cash$param.FS[1] )*cos( lppl_estimate_rob_3all_bitcoin_cash$param.FS[2]*log(lppl_estimate_rob_3all_bitcoin_cash$param.FS[7] - tt_sim_bch) ) h_t_bch=( (lppl_estimate_rob_3all_bitcoin_cash$param.FS[7] - tt_sim_bch)^lppl_estimate_rob_3all_bitcoin_cash$param.FS[1] )*sin( lppl_estimate_rob_3all_bitcoin_cash$param.FS[2]*log(lppl_estimate_rob_3all_bitcoin_cash$param.FS[7] - tt_sim_bch) ) Y_bch=log(bitcoin_cash) #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_bch = sdum_bch*lppl_estimate_rob_3all_bitcoin_cash$param.FS[3] + lppl_estimate_rob_3all_bitcoin_cash$param.FS[4] *f_t_bch + lppl_estimate_rob_3all_bitcoin_cash$param.FS[5]*g_t_bch + lppl_estimate_rob_3all_bitcoin_cash$param.FS[6] *h_t_bch Yfit_bch_df=data.frame(subset(bitcoin_cash, Date>="2017-09-15" & Date<=round(bitcoin_cash_subset$Date[1]+lppl_estimate_rob_3all_bitcoin_cash$param.JLS[7])-1),Yfit_bch ) Y_bch<-subset(bitcoin_cash, Date>="2017-09-15" & Date<="2019-01-15") df_bch = list(Date=Y_bch$Date, Yfit_bch=Yfit_bch, Y_bch=log(Y_bch$BCH_Close)) attributes(df_bch) = list(names = names(df_bch), row.names=1:max(length(Y_bch$Date), length(Yfit_bch)), class='data.frame') df_bch colors_bch<-c("LPPL Bitcoin Cash Fit"="red", "Log Bitcoin Cash price"="blue") Y_fitted_actual_bch<-ggplot(data = na.omit(df_bch), aes(x = Date)) + geom_line(aes(y = Y_bch, color = "Log Bitcoin Cash price") )+ geom_line(aes (y=Yfit_bch, color = "LPPL Bitcoin Cash Fit")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Bitcoin Cash") + xlab(label='Date') + ylab(label='Fitted VS Actual') + labs(x = "Date", y = "Fitted VS Actual", color = "") + scale_x_date(labels=date_format("%y-%m"))+ scale_color_manual(values = colors_bch)+ # coord_cartesian(ylim = c(-0.01, 0.048)) + theme(legend.position="bottom", legend.direction="vertical")+ # coord_cartesian(ylim = c(-0.01, 0.048)) + themePlot Y_fitted_actual_bch grid.arrange(Y_fitted_actual_ripple, Y_fitted_actual_bch, ncol=2) #BITCOIN CASH Prediction bitcoin_cash_pr<-subset(bitcoin_cash, Date>= "2019-02-08" & Date<="2019-05-31") #15.09.2017-20.06.2018, 08.02.2019-01.07.2019 15.09.2017 21.12.2017 lppl_estimate_rob_3all_bitcoin_cash_pr<-lppl_estimate_rob_3all(bitcoin_cash_pr$BCH_Close, par_start = c(bet=0.5, ome=6, A=log(bitcoin_cash_pr$BCH_Close[NROW(bitcoin_cash_pr$BCH_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) ##lppl_simulate_FS_ethereum<-lppl_simulate_FS(T=1500, lppl_3step) lppl_estimate_rob_3all_bitcoin_cash_pr AIC_bch<-nrow(data.frame(lppl_estimate_rob_3all_bitcoin_cash_pr$resids))*log((sum(lppl_estimate_rob_3all_bitcoin_cash_pr$resids^2))/nrow(data.frame(lppl_estimate_rob_3all_bitcoin_cash_pr$resids)))+2*7 print(AIC_bch) kpss.test(lppl_estimate_rob_3all_bitcoin_cash_pr$resids) RMSE(lppl_estimate_rob_3all_bitcoin_cash_pr$resids) bitcoin_cash_pr$Date[1]+lppl_estimate_rob_3all_bitcoin_cash_pr$param.JLS[7] n_fit_bch_pr<-round(lppl_estimate_rob_3all_bitcoin_cash_pr$param.JLS[7]) sdum_bch_pr=rep(1,n_fit_bch_pr) tt_sim_bch_pr=seq(1, n_fit_bch_pr, 1) f_t_bch_pr=(lppl_estimate_rob_3all_bitcoin_cash_pr$param.FS[7] - tt_sim_bch_pr)^lppl_estimate_rob_3all_bitcoin_cash_pr$param.FS[1] g_t_bch_pr=( (lppl_estimate_rob_3all_bitcoin_cash_pr$param.FS[7] - tt_sim_bch_pr)^lppl_estimate_rob_3all_bitcoin_cash_pr$param.FS[1] )*cos( lppl_estimate_rob_3all_bitcoin_cash_pr$param.FS[2]*log(lppl_estimate_rob_3all_bitcoin_cash_pr$param.FS[7] - tt_sim_bch_pr) ) h_t_bch_pr=( (lppl_estimate_rob_3all_bitcoin_cash_pr$param.FS[7] - tt_sim_bch_pr)^lppl_estimate_rob_3all_bitcoin_cash_pr$param.FS[1] )*sin( lppl_estimate_rob_3all_bitcoin_cash_pr$param.FS[2]*log(lppl_estimate_rob_3all_bitcoin_cash_pr$param.FS[7] - tt_sim_bch_pr) ) #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_bch_pr = data.frame(sdum_bch_pr*lppl_estimate_rob_3all_bitcoin_cash_pr$param.FS[3] + lppl_estimate_rob_3all_bitcoin_cash_pr$param.FS[4] *f_t_bch_pr + lppl_estimate_rob_3all_bitcoin_cash_pr$param.FS[5]*g_t_bch_pr + lppl_estimate_rob_3all_bitcoin_cash_pr$param.FS[6] *h_t_bch_pr) names(Yfit_bch_pr)<-c("Fitted") names(Yfit_bch_pr_all)<-c("Fitted") # Yfit_bch_pr_all<-data.frame(Yfit_bch_pr[1:16,]) bind_bch<-data.frame(Yfit_bch_pr[129:167,1]) names(bind_bch)<-c("Fitted") Yfit_bch_pr_all<-rbind(Yfit_bch_pr_all, bind_bch) names(Yfit_bch_pr)<-c("Fitted") dates_bch<-data.frame(seq(as.Date("2019/7/2"), as.Date("2019/7/25"), "day")) names(dates_bch)<-c("Date") Y_bch_pr<-subset(bitcoin_cash, Date>="2019-02-08" & Date<="2019-07-25", select=c("Date")) names(Y_bch_pr)<-c("Date") Y_bch_pr<-rbind(Y_bch_pr, dates_bch) Y_bch_pr_2<-subset(bitcoin_cash, Date>="2019-02-08" & Date<="2019-07-25") Yfit_bch_df_pr = data.frame(Y_bch_pr$Date, Y_bch_pr) df_bch_pr <-list(Date=Y_bch_pr$Date, Yfit_bch_pr_all=Yfit_bch_pr_all$Fitted,Yfit_bch_pr=Yfit_bch_pr$Fitted, Y_bch=log(Y_bch_pr_2$BCH_Close)) attributes(df_bch_pr) = list(names = names(df_bch_pr), row.names=1:max(length(Y_bch_pr$Date), length(Yfit_bch_pr)), class='data.frame') df_bch_pr colrs_pr<-c("Actual Log Bicoin Cash Price"="blue", "Fitted Rolling LPPL"="red", "Fitted LPPL"="green" ) Y_fitted_actual_bch_pr<-ggplot(data = na.omit(df_bch_pr), aes(x = Date)) + geom_line(aes(y = Y_bch, color="Actual Log Bicoin Cash Price")) + geom_line(aes (y=Yfit_bch_pr_all, color = "Fitted Rolling LPPL") )+ geom_line(aes (y=Yfit_bch_pr, color = "Fitted LPPL")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Bitcoin Cash Prediction") + xlab(label='Date') + ylab(label='Fitted VS Actual') + labs(x = "Date", y = "Fitted VS Actual", color = "") + scale_color_manual(values = colrs_pr)+ # coord_cartesian(ylim = c(-0.01, 0.048)) + scale_x_date(labels=date_format("%Y-%m"))+ theme(legend.position="bottom", legend.direction="horizontal")+ themePlot #LITECOIN litecoin_subset<-subset(litecoin, Date>= "2017-11-01" & Date<="2017-12-13") #30.03.2017-13.09.2017,16.11.2017-15.01.2018,20.11.2018-16.12.2018,07.03.2019-20.04.2019,11.05.2019-01.07.2019 lppl_estimate_rob_3all_litecoin<-lppl_estimate_rob_3all(litecoin_subset$LTC_Close, par_start = c(bet=0.5, ome=6, A=log(litecoin_subset$LTC_Close[NROW(litecoin_subset$LTC_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) ##lppl_simulate_FS_ethereum<-lppl_simulate_FS(T=1500, lppl_3step) lppl_estimate_rob_3all_litecoin$param.JLS[2] RMSE(lppl_estimate_rob_3all_litecoin$resids) AIC_litecoin<-nrow(data.frame(lppl_estimate_rob_3all_litecoin$resids))*log((sum(lppl_estimate_rob_3all_litecoin$resids^2))/nrow(data.frame(lppl_estimate_rob_3all_litecoin$resids)))+2*7 print(AIC_litecoin) kpss.test(lppl_estimate_rob_3all_litecoin$resids) RMSE(lppl_estimate_rob_3all_litecoin$resids) litecoin_subset$Date[1]+lppl_estimate_rob_3all_litecoin$param.JLS[7] n_fit_litecoin<-round(lppl_estimate_rob_3all_litecoin$param.JLS[7]) sdum_litecoin=rep(1,n_fit_litecoin) tt_sim_litecoin=seq(1, n_fit_litecoin, 1) f_t_litecoin=(lppl_estimate_rob_3all_litecoin$param.FS[7] - tt_sim_litecoin)^lppl_estimate_rob_3all_litecoin$param.FS[1] g_t_litecoin=( (lppl_estimate_rob_3all_litecoin$param.FS[7] - tt_sim_litecoin)^lppl_estimate_rob_3all_litecoin$param.FS[1] )*cos( lppl_estimate_rob_3all_litecoin$param.FS[2]*log(lppl_estimate_rob_3all_litecoin$param.FS[7] - tt_sim_litecoin) ) h_t_litecoin=( (lppl_estimate_rob_3all_litecoin$param.FS[7] - tt_sim_litecoin)^lppl_estimate_rob_3all_litecoin$param.FS[1] )*sin( lppl_estimate_rob_3all_litecoin$param.FS[2]*log(lppl_estimate_rob_3all_litecoin$param.FS[7] - tt_sim_litecoin) ) Y_litecoin=log(litecoin) #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_litecoin = sdum_litecoin*lppl_estimate_rob_3all_litecoin$param.FS[3] + lppl_estimate_rob_3all_litecoin$param.FS[4] *f_t_litecoin + lppl_estimate_rob_3all_litecoin$param.FS[5]*g_t_litecoin + lppl_estimate_rob_3all_litecoin$param.FS[6] *h_t_litecoin Yfit_litecoin_df=data.frame(subset(litecoin, Date>= "2017-11-01" & Date<=round(litecoin_subset$Date[1]+lppl_estimate_rob_3all_litecoin$param.JLS[7])-1),Yfit_litecoin ) Y_litecoin<-subset(litecoin, Date>="2017-11-01" & Date<="2018-10-01") df_litecoin = list(Date=Y_litecoin$Date, Yfit_litecoin=Yfit_litecoin, Y_litecoin=log(Y_litecoin$LTC_Close)) attributes(df_litecoin) = list(names = names(df_litecoin), row.names=1:max(length(Y_litecoin$Date), length(Yfit_litecoin)), class='data.frame') df_litecoin colors_l<-c("LPPL Litecoin Fit"="red", "Log Litecoin price"="blue") Y_fitted_actual_litecoin<-ggplot(data = na.omit(df_litecoin), aes(x = Date)) + geom_line(aes(y = Y_litecoin, color = "Log Litecoin price")) + geom_line(aes (y=Yfit_litecoin, color = "LPPL Litecoin Fit")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Litecoin") + xlab(label='Date') + ylab(label='Fitted VS Actual') + labs(x = "Date", y = "Fitted VS Actual", color = "") + scale_color_manual(values = colors_l)+ # coord_cartesian(ylim = c(-0.01, 0.048)) + theme(legend.position="bottom", legend.direction="vertical")+ # coord_cartesian(ylim = c(-0.01, 0.048)) + scale_x_date(labels=date_format("%y-%m"))+ themePlot Y_fitted_actual_litecoin #LITECOIN PREDICTION litecoin_pr<-subset(litecoin, Date>= "2019-05-11" & Date<="2019-06-30") #30.03.2017-13.09.2017,16.11.2017-15.01.2018,20.11.2018-16.12.2018,07.03.2019-20.04.2019,11.05.2019-01.07.2019 lppl_estimate_rob_3all_litecoin_pr<-lppl_estimate_rob_3all(litecoin_pr$LTC_Close, par_start = c(bet=0.5, ome=6, A=log(litecoin_pr$LTC_Close[NROW(litecoin_pr$LTC_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) ##lppl_simulate_FS_ethereum<-lppl_simulate_FS(T=1500, lppl_3step) lppl_estimate_rob_3all_litecoin_pr$param.JLS[2] RMSE(lppl_estimate_rob_3all_litecoin_pr$resids) AIC_litecoin<-nrow(data.frame(lppl_estimate_rob_3all_litecoin_pr$resids))*log((sum(lppl_estimate_rob_3all_litecoin_pr$resids^2))/nrow(data.frame(lppl_estimate_rob_3all_litecoin_pr$resids)))+2*7 print(AIC_litecoin) kpss.test(lppl_estimate_rob_3all_litecoin_pr$resids) RMSE(lppl_estimate_rob_3all_litecoin_pr$resids) litecoin_pr$Date[1]+lppl_estimate_rob_3all_litecoin_pr$param.JLS[7] n_fit_ltc_pr<-round(lppl_estimate_rob_3all_litecoin_pr$param.JLS[7]) sdum_ltc_pr=rep(1,n_fit_ltc_pr) tt_sim_ltc_pr=seq(1, n_fit_ltc_pr, 1) f_t_ltc_pr=(lppl_estimate_rob_3all_litecoin_pr$param.FS[7] - tt_sim_ltc_pr)^lppl_estimate_rob_3all_litecoin_pr$param.FS[1] g_t_ltc_pr=( (lppl_estimate_rob_3all_litecoin_pr$param.FS[7] - tt_sim_ltc_pr)^lppl_estimate_rob_3all_litecoin_pr$param.FS[1] )*cos( lppl_estimate_rob_3all_litecoin_pr$param.FS[2]*log(lppl_estimate_rob_3all_litecoin_pr$param.FS[7] - tt_sim_ltc_pr) ) h_t_ltc_pr=( (lppl_estimate_rob_3all_litecoin_pr$param.FS[7] - tt_sim_ltc_pr)^lppl_estimate_rob_3all_litecoin_pr$param.FS[1] )*sin( lppl_estimate_rob_3all_litecoin_pr$param.FS[2]*log(lppl_estimate_rob_3all_litecoin_pr$param.FS[7] - tt_sim_ltc_pr) ) #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_ltc_pr = data.frame(sdum_ltc_pr*lppl_estimate_rob_3all_litecoin_pr$param.FS[3] + lppl_estimate_rob_3all_litecoin_pr$param.FS[4] *f_t_ltc_pr + lppl_estimate_rob_3all_litecoin_pr$param.FS[5]*g_t_ltc_pr + lppl_estimate_rob_3all_litecoin_pr$param.FS[6] *h_t_ltc_pr) names(Yfit_ltc_pr)<-c("Fitted") names(Yfit_ltc_pr_all)<-c("Fitted") # Yfit_ltc_pr_all<-data.frame(Yfit_ltc_pr[1:16,]) bind_ltc<-data.frame(Yfit_ltc_pr[45:50,]) names(bind_ltc)<-c("Fitted") Yfit_ltc_pr_all<-rbind(Yfit_ltc_pr_all, bind_ltc) names(Yfit_ltc_pr)<-c("Fitted") dates_ltc<-data.frame(seq(as.Date("2019/7/2"), as.Date("2019/7/03"), "day")) names(dates_ltc)<-c("Date") Y_ltc_pr<-subset(litecoin, Date>="2019-05-11" & Date<="2019-07-01", select=c("Date")) names(Y_ltc_pr)<-c("Date") Y_ltc_pr<-rbind(Y_ltc_pr, dates_ltc) Y_ltc_pr_2<-subset(litecoin, Date>="2019-05-11" & Date<="2019-07-03") Yfit_ltc_df_pr = data.frame(Y_ltc_pr$Date, Y_ltc_pr) df_ltc_pr <-list(Date=Y_ltc_pr$Date, Yfit_ltc_pr_all=Yfit_ltc_pr_all$Fitted,Yfit_ltc_pr=Yfit_ltc_pr$Fitted, Y_ltc=log(Y_ltc_pr_2$LTC_Close)) attributes(df_ltc_pr) = list(names = names(df_ltc_pr), row.names=1:max(length(Y_ltc_pr$Date), length(Yfit_ltc_pr)), class='data.frame') df_ltc_pr colrs_pr<-c("Actual Log Litecoin Price"="blue", "Fitted Rolling LPPL"="red", "Fitted LPPL"="green" ) Y_fitted_actual_ltc_pr<-ggplot(data = na.omit(df_ltc_pr), aes(x = Date)) + geom_line(aes(y = Y_ltc, color="Actual Log Litecoin Price")) + geom_line(aes (y=Yfit_ltc_pr_all, color = "Fitted Rolling LPPL"))+ geom_line(aes (y=Yfit_ltc_pr, color = "Fitted LPPL")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Litecoin Prediction") + xlab(label='Date') + ylab(label='Fitted VS Actual') + labs(x = "Date",p y = "Fitted VS Actual", color = "") + scale_color_manual(values = colrs_pr)+ theme(legend.position="bottom", legend.direction="horizontal")+ # coord_cartesian(ylim = c(-0.01, 0.048)) + scale_x_date(labels=date_format("%Y-%m"))+ themePlot #BITCOIN SV bitcoin_sv_subset<-subset(bitcoin_sv) lppl_estimate_rob_3all_bitcoin_sv<-lppl_estimate_rob_3all(bitcoin_sv_subset$BSV_Close, par_start = c(bet=0.5, ome=6, A=log(bitcoin_sv_subset$BSV_Close[NROW(bitcoin_sv_subset$BSV_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) ##lppl_simulate_FS_ethereum<-lppl_simulate_FS(T=1500, lppl_3step) lppl_estimate_rob_3all_bitcoin_sv AIC_bitcoin_sv<-nrow(data.frame(lppl_estimate_rob_3all_bitcoin_sv$resids))*log((sum(lppl_estimate_rob_3all_bitcoin_sv$resids^2))/nrow(data.frame(lppl_estimate_rob_3all_bitcoin_sv$resids)))+2*7 print(AIC_bitcoin_sv) kpss.test(lppl_estimate_rob_3all_bitcoin_sv$resids) RMSE(lppl_estimate_rob_3all_bitcoin_sv$resids) bitcoin_sv_subset$Date[1]+lppl_estimate_rob_3all_bitcoin_sv$param.JLS[7] n_fit_bsv<-round(lppl_estimate_rob_3all_bitcoin_sv$param.JLS[7]) sdum_bsv=rep(1,n_fit_bsv) tt_sim_bsv=seq(1, n_fit_bsv, 1) f_t_bsv=(lppl_estimate_rob_3all_bitcoin_sv$param.FS[7] - tt_sim_bsv)^lppl_estimate_rob_3all_bitcoin_sv$param.FS[1] g_t_bsv=( (lppl_estimate_rob_3all_bitcoin_sv$param.FS[7] - tt_sim_bsv)^lppl_estimate_rob_3all_bitcoin_sv$param.FS[1] )*cos( lppl_estimate_rob_3all_bitcoin_sv$param.FS[2]*log(lppl_estimate_rob_3all_bitcoin_sv$param.FS[7] - tt_sim_bsv) ) h_t_bsv=( (lppl_estimate_rob_3all_bitcoin_sv$param.FS[7] - tt_sim_bsv)^lppl_estimate_rob_3all_bitcoin_sv$param.FS[1] )*sin( lppl_estimate_rob_3all_bitcoin_sv$param.FS[2]*log(lppl_estimate_rob_3all_bitcoin_sv$param.FS[7] - tt_sim_bsv) ) Y_bitcoin_sv=log(bitcoin_sv) #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_bsv = sdum_bsv*lppl_estimate_rob_3all_bitcoin_sv$param.FS[3] + lppl_estimate_rob_3all_bitcoin_sv$param.FS[4] *f_t_bsv + lppl_estimate_rob_3all_bitcoin_sv$param.FS[5]*g_t_bsv + lppl_estimate_rob_3all_bitcoin_sv$param.FS[6] *h_t_bsv Yfit_bsv_df=data.frame(subset(bitcoin_sv),Yfit_bsv[1:nrow(bitcoin_sv_subset)]) Y_bsv<-subset(bitcoin_sv) df_bsv = list(Date=Y_bsv$Date, Yfit_bsv=Yfit_bsv, Y_bsv=log(Y_bsv$BSV_Close)) attributes(df_bsv) = list(names = names(df_bsv), row.names=1:max(length(Y_bsv$Date), length(Yfit_bsv)), class='data.frame') df_bsv colors_bsv<-c("LPPL Bitcoin SV Fit"="red", "Log Bitcoin SV price"="blue") Y_fitted_actual_bsv<-ggplot(data = na.omit(df_bsv), aes(x = Date)) + geom_line(aes(y = Y_bsv,color = "Log Bitcoin SV price")) + geom_line(aes (y=Yfit_bsv, color = "red")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Bitcoin SV") + xlab(label='Date') + ylab(label='Fitted VS Actual') + labs(x = "Date", y = "Fitted VS Actual", color = "") + scale_color_manual(values = colors_bsv)+ # coord_cartesian(ylim = c(-0.01, 0.048)) + theme(legend.position="bottom", legend.direction="horizontal")+ scale_x_date(labels=date_format("%Y-%m"))+ scale_x_date(labels=date_format("%Y-%m"))+ # coord_cartesian(ylim = c(-0.01, 0.048)) + themePlot Y_fitted_actual_bsv #EOS eos_subset<-subset(eos, Date>= "2017-11-13" & Date<= "2018-01-13") #01.11.2017 15.01.2018 03.11.2017-29.01.2018,23.04.2018-10.05.2018,20.11.2018-27.12.2018,02.04.2019-20.04.2019,14.05.2019-02.06.2019 lppl_estimate_rob_3all_eos<-lppl_estimate_rob_3all(eos_subset$EOS_Close, par_start = c(bet=0.5, ome=6, A=log(eos_subset$EOS_Close[NROW(eos_subset$EOS_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) ##lppl_simulate_FS_ethereum<-lppl_simulate_FS(T=1500, lppl_3step) lppl_estimate_rob_3all_eos$param.JLS[2] RMSE(lppl_estimate_rob_3all_eos$resids) AIC_eos<-nrow(data.frame(lppl_estimate_rob_3all_eos$resids))*log((sum(lppl_estimate_rob_3all_eos$resids^2))/nrow(data.frame(lppl_estimate_rob_3all_eos$resids)))+2*7 print(AIC_eos) kpss.test(lppl_estimate_rob_3all_eos$resids) RMSE(lppl_estimate_rob_3all_eos$resids) eos_subset$Date[1]+lppl_estimate_rob_3all_eos$param.JLS[7] n_fit_eos<-round(lppl_estimate_rob_3all_eos$param.JLS[7]) sdum_eos=rep(1,n_fit_eos) tt_sim_eos=seq(1, n_fit_eos, 1) f_t_eos=(lppl_estimate_rob_3all_eos$param.FS[7] - tt_sim_eos)^lppl_estimate_rob_3all_eos$param.FS[1] g_t_eos=( (lppl_estimate_rob_3all_eos$param.FS[7] - tt_sim_eos)^lppl_estimate_rob_3all_eos$param.FS[1] )*cos( lppl_estimate_rob_3all_eos$param.FS[2]*log(lppl_estimate_rob_3all_eos$param.FS[7] - tt_sim_eos) ) h_t_eos=( (lppl_estimate_rob_3all_eos$param.FS[7] - tt_sim_eos)^lppl_estimate_rob_3all_eos$param.FS[1] )*sin( lppl_estimate_rob_3all_eos$param.FS[2]*log(lppl_estimate_rob_3all_eos$param.FS[7] - tt_sim_eos) ) Y_eos=log(eos) #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_eos = sdum_eos*lppl_estimate_rob_3all_eos$param.FS[3] + lppl_estimate_rob_3all_eos$param.FS[4] *f_t_eos + lppl_estimate_rob_3all_eos$param.FS[5]*g_t_eos + lppl_estimate_rob_3all_eos$param.FS[6] *h_t_eos Yfit_eos_df=data.frame(subset(eos, Date>= "2017-11-13" & Date<=round(eos_subset$Date[1]+lppl_estimate_rob_3all_eos$param.JLS[7])-1),Yfit_eos) Y_eos<-subset(eos, Date>="2017-11-13" & Date<="2019-01-01") df_eos = list(Date=Y_eos$Date, Yfit_eos=Yfit_eos, Y_eos=log(Y_eos$EOS_Close)) attributes(df_eos) = list(names = names(df_eos), row.names=1:max(length(Y_eos$Date), length(Yfit_eos)), class='data.frame') df_eos colors_eos<-c("LPPL EOS Fit"="red", "Log EOS price"="blue") Y_fitted_actual_eos<-ggplot(data = na.omit(df_eos), aes(x = Date)) + geom_line(aes(y = Y_eos, color = "Log EOS price")) + geom_line(aes (y=Yfit_eos, color = "LPPL EOS Fit")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL EOS") + xlab(label='Date') + ylab(label='Fitted VS Actual') +labs(x = "Date", y = "Fitted VS Actual", color = "") + scale_color_manual(values = colors_eos)+ # coord_cartesian(ylim = c(-0.01, 0.048)) + theme(legend.position="bottom", legend.direction="vertical")+ scale_x_date(labels=date_format("%y-%m"))+ # coord_cartesian(ylim = c(-0.01, 0.048)) + themePlot Y_fitted_actual_eos grid.arrange(Y_fitted_actual_litecoin, Y_fitted_actual_eos, ncol=2) #BINANCE COIN binance_coin_subset<-subset(binance_coin, Date>= "2017-11-10" & Date<= "2018-01-10" ) #04.12.2017-15.01.2018, 17.11.2018-17.12.2018,09.02.2019-01.07.2019 lppl_estimate_rob_3all_binance_coin<-lppl_estimate_rob_3all(binance_coin_subset$BNB_Close, par_start = c(bet=0.5, ome=6, A=log(binance_coin_subset$BNB_Close[NROW(binance_coin_subset$BNB_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) ##lppl_simulate_FS_ethereum<-lppl_simulate_FS(T=1500, lppl_3step) lppl_estimate_rob_3all_binance_coin$param.JLS[2] AIC_binance<-nrow(data.frame(lppl_estimate_rob_3all_binance_coin$resids))*log((sum(lppl_estimate_rob_3all_binance_coin$resids^2))/nrow(data.frame(lppl_estimate_rob_3all_binance_coin$resids)))+2*7 print(AIC_binance) kpss.test(lppl_estimate_rob_3all_binance_coin$resids) RMSE(lppl_estimate_rob_3all_binance_coin$resids) binance_coin_subset$Date[1]+lppl_estimate_rob_3all_binance_coin$param.JLS[7] n_fit_binance<-round(lppl_estimate_rob_3all_binance_coin$param.JLS[7]) sdum_binance=rep(1,n_fit_binance) tt_sim_binance=seq(1, n_fit_binance, 1) f_t_binance=(lppl_estimate_rob_3all_binance_coin$param.FS[7] - tt_sim_binance)^lppl_estimate_rob_3all_binance_coin$param.FS[1] g_t_binance=( (lppl_estimate_rob_3all_binance_coin$param.FS[7] - tt_sim_binance)^lppl_estimate_rob_3all_binance_coin$param.FS[1] )*cos( lppl_estimate_rob_3all_binance_coin$param.FS[2]*log(lppl_estimate_rob_3all_binance_coin$param.FS[7] - tt_sim_binance) ) h_t_binance=( (lppl_estimate_rob_3all_binance_coin$param.FS[7] - tt_sim_binance)^lppl_estimate_rob_3all_binance_coin$param.FS[1] )*sin( lppl_estimate_rob_3all_binance_coin$param.FS[2]*log(lppl_estimate_rob_3all_binance_coin$param.FS[7] - tt_sim_binance) ) Y_binance=log(binance_coin) #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_binance = sdum_binance*lppl_estimate_rob_3all_binance_coin$param.FS[3] + lppl_estimate_rob_3all_binance_coin$param.FS[4] *f_t_binance + lppl_estimate_rob_3all_binance_coin$param.FS[5]*g_t_binance + lppl_estimate_rob_3all_binance_coin$param.FS[6] *h_t_binance Yfit_binance_df=data.frame(subset(binance_coin, Date>= "2017-11-10"& Date<=round(binance_coin_subset$Date[1]+lppl_estimate_rob_3all_binance_coin$param.JLS[7])-1),Yfit_binance) Y_binance<-subset(binance_coin, Date>="2017-11-10" & Date<="2019-01-15" ) df_binance = list(Date=Y_binance$Date, Yfit_binance=Yfit_binance, Y_binance=log(Y_binance$BNB_Close)) attributes(df_binance) = list(names = names(df_binance), row.names=1:max(length(Y_binance$Date), length(Yfit_binance)), class='data.frame') df_binance colors_bnb<-c("LPPL Binance Fit"="red", "Log Binance price"="blue") Y_fitted_actual_binance<-ggplot(data = na.omit(df_binance), aes(x = Date)) + geom_line(aes(y = Y_binance,color = "Log Binance price") )+ geom_line(aes (y=Yfit_binance, color = "LPPL Binance Fit")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Binance Coin") + xlab(label='Date') + ylab(label='Fitted VS Actual') + labs(x = "Date", y = "Fitted VS Actual", color = "") + scale_color_manual(values = colors_bnb)+ # coord_cartesian(ylim = c(-0.01, 0.048)) + theme(legend.position="bottom", legend.direction="vertical")+ scale_x_date(labels=date_format("%y-%m"))+ # coord_cartesian(ylim = c(-0.01, 0.048)) + themePlot Y_fitted_actual_binance #BINANCE COIN PREDICTION binance_coin_pr<-subset(binance_coin, Date>= "2019-02-09" & Date<="2019-06-15") #04.12.2017-15.01.2018, 17.11.2018-17.12.2018,09.02.2019-01.07.2019 lppl_estimate_rob_3all_binance_coin_pr<-lppl_estimate_rob_3all(binance_coin_pr$BNB_Close, par_start = c(bet=0.5, ome=6, A=log(binance_coin_pr$BNB_Close[NROW(binance_coin_pr$BNB_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) ##lppl_simulate_FS_ethereum<-lppl_simulate_FS(T=1500, lppl_3step) lppl_estimate_rob_3all_binance_coin_pr$param.JLS[2] AIC_binance<-nrow(data.frame(lppl_estimate_rob_3all_binance_coin_pr$resids))*log((sum(lppl_estimate_rob_3all_binance_coin_pr$resids^2))/nrow(data.frame(lppl_estimate_rob_3all_binance_coin_pr$resids)))+2*7 print(AIC_binance) kpss.test(lppl_estimate_rob_3all_binance_coin_pr$resids) RMSE(lppl_estimate_rob_3all_binance_coin_pr$resids) binance_coin_pr$Date[1]+lppl_estimate_rob_3all_binance_coin_pr$param.JLS[7] n_fit_bnb_pr<-round(lppl_estimate_rob_3all_binance_coin_pr$param.JLS[7]) sdum_bnb_pr=rep(1,n_fit_bnb_pr) tt_sim_bnb_pr=seq(1, n_fit_bnb_pr, 1) f_t_bnb_pr=(lppl_estimate_rob_3all_binance_coin_pr$param.FS[7] - tt_sim_bnb_pr)^lppl_estimate_rob_3all_binance_coin_pr$param.FS[1] g_t_bnb_pr=( (lppl_estimate_rob_3all_binance_coin_pr$param.FS[7] - tt_sim_bnb_pr)^lppl_estimate_rob_3all_binance_coin_pr$param.FS[1] )*cos( lppl_estimate_rob_3all_binance_coin_pr$param.FS[2]*log(lppl_estimate_rob_3all_binance_coin_pr$param.FS[7] - tt_sim_bnb_pr) ) h_t_bnb_pr=( (lppl_estimate_rob_3all_binance_coin_pr$param.FS[7] - tt_sim_bnb_pr)^lppl_estimate_rob_3all_binance_coin_pr$param.FS[1] )*sin( lppl_estimate_rob_3all_binance_coin_pr$param.FS[2]*log(lppl_estimate_rob_3all_binance_coin_pr$param.FS[7] - tt_sim_bnb_pr) ) #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_bnb_pr = data.frame(sdum_bnb_pr*lppl_estimate_rob_3all_binance_coin_pr$param.FS[3] + lppl_estimate_rob_3all_binance_coin_pr$param.FS[4] *f_t_bnb_pr + lppl_estimate_rob_3all_binance_coin_pr$param.FS[5]*g_t_bnb_pr + lppl_estimate_rob_3all_binance_coin_pr$param.FS[6] *h_t_bnb_pr) names(Yfit_bnb_pr)<-c("Fitted") names(Yfit_bnb_pr_all)<-c("Fitted") # Yfit_bnb_pr_all<-data.frame(Yfit_bnb_pr[1:15,]) bind_bnb<-data.frame(Yfit_bnb_pr[106:nrow(Yfit_bnb_pr),]) names(bind_bnb)<-c("Fitted") Yfit_bnb_pr_all<-rbind(Yfit_bnb_pr_all, bind_bnb) Yfit_bnb_pr_all<-data.frame(Yfit_bnb_pr_all[1:146,]) names(Yfit_bnb_pr)<-c("Fitted") dates_bnb<-data.frame(seq(as.Date("2019/7/2"), as.Date("2019/7/15"), "day")) names(dates_bnb)<-c("Date") Y_bnb_pr<-subset(binance_coin, Date>="2019-02-09" & Date<="2019-07-15", select=c("Date")) names(Y_bnb_pr)<-c("Date") Y_bnb_pr<-rbind(Y_bnb_pr, dates_bnb) Y_bnb_pr_2<-subset(binance_coin, Date>="2019-02-09" & Date<="2019-07-15") Yfit_bnb_df_pr = data.frame(Y_bnb_pr$Date, Y_bnb_pr) df_bnb_pr <-list(Date=Y_bnb_pr$Date, Yfit_bnb_pr_all=Yfit_bnb_pr_all$Fitted,Yfit_bnb_pr=Yfit_bnb_pr$Fitted, Y_bnb=log(Y_bnb_pr_2$BNB_Close)) attributes(df_bnb_pr) = list(names = names(df_bnb_pr), row.names=1:max(length(Y_bnb_pr$Date), length(Yfit_bnb_pr)), class='data.frame') df_bnb_pr colrs_pr<-c("Actual Log Binance Price"="blue", "Fitted Rolling LPPL"="red", "Fitted LPPL"="green" ) Y_fitted_actual_bnb_pr<-ggplot(data = na.omit(df_bnb_pr), aes(x = Date)) + geom_line(aes(y = Y_bnb, color="Actual Log Binance Price")) + geom_line(aes (y=Yfit_bnb_pr_all, color = "Fitted Rolling LPPL")) + geom_line(aes (y=Yfit_bnb_pr, color = "Fitted LPPL")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Binance Prediction") + xlab(label='Date') + ylab(label='Fitted VS Actual') + labs(x = "Date", y = "Fitted VS Actual", color = "") + scale_color_manual(values = colrs_pr)+ # coord_cartesian(ylim = c(-0.01, 0.048)) + theme(legend.position="bottom", legend.direction="horizontal")+ scale_x_date(labels=date_format("%Y-%m"))+ themePlot colrs_pr<-c("Actual-Log Bitcoin Price"="blue", "Fitted Rolling LPPL"="red", "Fitted LPPL"="green" ) Y_fitted_actual_bitcoin_pr<-ggplot(data = na.omit(df_pr), aes(x = Date)) + geom_line(aes(y = Y_bitcoin, color="Actual-Log Bitcoin Price")) + geom_line(aes (y=Yfit_bitcoin_pr_all, color = "Fitted Rolling LPPL")) + geom_line(aes (y=Yfit_bitcoin_pr, color = "Fitted LPPL")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Bitcoin Prediction") + xlab(label='Date') + ylab(label='Fitted VS Actual') + labs(x = "Date", y = "('Fitted VS Actual')", color = "") + scale_color_manual(values = colrs_pr)+ theme(legend.position="bottom", legend.direction="horizontal")+ # coord_cartesian(ylim = c(-0.01, 0.048)) + scale_x_date(labels=date_format("%Y-%m"))+ themePlot #STELLAR stellar_subset<-subset(stellar, Date>= "2017-09-30" & Date<="2018-01-01") #01.05.2017-22.07.2017,27.11.2017-11.06.2018,05.12.2018-27.12.2018,28.01.2019-18.02.2019 lppl_estimate_rob_3all_stellar<-lppl_estimate_rob_3all(stellar_subset$XLM_Close, par_start = c(bet=0.5, ome=6, A=log(stellar_subset$XLM_Close[NROW(stellar_subset$XLM_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) ##lppl_simulate_FS_ethereum<-lppl_simulate_FS(T=1500, lppl_3step) lppl_estimate_rob_3all_stellar AIC_stellar<-nrow(data.frame(lppl_estimate_rob_3all_stellar$resids))*log((sum(lppl_estimate_rob_3all_stellar$resids^2))/nrow(data.frame(lppl_estimate_rob_3all_stellar$resids)))+2*7 print(AIC_stellar) kpss.test(lppl_estimate_rob_3all_stellar$resids) RMSE(lppl_estimate_rob_3all_stellar$resids) stellar_subset$Date[1]+lppl_estimate_rob_3all_stellar$param.JLS[7] n_fit_stellar<-round(lppl_estimate_rob_3all_stellar$param.JLS[7]) sdum_stellar=rep(1,n_fit_stellar) tt_sim_stellar=seq(1, n_fit_stellar, 1) f_t_stellar=(lppl_estimate_rob_3all_stellar$param.FS[7] - tt_sim_stellar)^lppl_estimate_rob_3all_stellar$param.FS[1] g_t_stellar=( (lppl_estimate_rob_3all_stellar$param.FS[7] - tt_sim_stellar)^lppl_estimate_rob_3all_stellar$param.FS[1] )*cos( lppl_estimate_rob_3all_stellar$param.FS[2]*log(lppl_estimate_rob_3all_stellar$param.FS[7] - tt_sim_stellar) ) h_t_stellar=( (lppl_estimate_rob_3all_stellar$param.FS[7] - tt_sim_stellar)^lppl_estimate_rob_3all_stellar$param.FS[1] )*sin( lppl_estimate_rob_3all_stellar$param.FS[2]*log(lppl_estimate_rob_3all_stellar$param.FS[7] - tt_sim_stellar) ) Y_stellar=log(stellar) #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_stellar = sdum_stellar*lppl_estimate_rob_3all_stellar$param.FS[3] + lppl_estimate_rob_3all_stellar$param.FS[4] *f_t_stellar + lppl_estimate_rob_3all_stellar$param.FS[5]*g_t_stellar + lppl_estimate_rob_3all_stellar$param.FS[6] *h_t_stellar Yfit_stellar_df=data.frame(subset(stellar, Date>= "2017-09-30" & Date<=round(stellar_subset$Date[1]+lppl_estimate_rob_3all_stellar$param.JLS[7])-1),Yfit_stellar) Y_stellar<-subset(stellar, Date>= "2017-09-30" & Date<="2019-01-15") df_stellar = list(Date=Y_stellar$Date, Yfit_stellar=Yfit_stellar, Y_stellar=log(Y_stellar$XLM_Close)) attributes(df_stellar) = list(names = names(df_stellar), row.names=1:max(length(Y_stellar$Date), length(Yfit_stellar)), class='data.frame') df_stellar colors_st<-c("LPPL Stellar Fit"="red", "Log Stellar price"="blue") Y_fitted_actual_stellar<-ggplot(data = na.omit(df_stellar), aes(x = Date)) + geom_line(aes( y = Y_stellar, color = "Log Stellar price")) + geom_line(aes (y=Yfit_stellar, color = "LPPL Stellar Fit")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Stellar") + xlab(label='Date') + ylab(label='Fitted VS Actual') + labs(x = "Date", y = "Fitted VS Actual", color = "") + scale_color_manual(values = colors_st)+ # coord_cartesian(ylim = c(-0.01, 0.048)) + theme(legend.position="bottom", legend.direction="vertical")+ scale_x_date(labels=date_format("%y-%m"))+ # coord_cartesian(ylim = c(-0.01, 0.048)) + themePlot Y_fitted_actual_stellar grid.arrange(Y_fitted_actual_binance,Y_fitted_actual_stellar, ncol=2) #TRON tron_subset<-subset(tron, Date>="2017-12-01" & Date<= "2018-01-08") # 08.12.2017-07.01.2018,24.04.2018-09.05.2018,20.11.2018-07.12.2018 lppl_estimate_rob_3all_tron<-lppl_estimate_rob_3all(tron_subset$TRX_Close, par_start = c(bet=0.5, ome=6, A=log(tron_subset$TRX_Close[NROW(tron_subset$TRX_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) ##lppl_simulate_FS_ethereum<-lppl_simulate_FS(T=1500, lppl_3step) lppl_estimate_rob_3all_tron AIC_tron<-nrow(data.frame(lppl_estimate_rob_3all_tron$resids))*log((sum(lppl_estimate_rob_3all_tron$resids^2))/nrow(data.frame(lppl_estimate_rob_3all_tron$resids)))+2*7 print(AIC_tron) kpss.test(lppl_estimate_rob_3all_tron$resids) RMSE(lppl_estimate_rob_3all_tron$resids) tron_subset$Date[1]+lppl_estimate_rob_3all_tron$param.JLS[7] n_fit_tron<-round(lppl_estimate_rob_3all_tron$param.JLS[7]) sdum_tron=rep(1,n_fit_tron) tt_sim_tron=seq(1, n_fit_tron, 1) f_t_tron=(lppl_estimate_rob_3all_tron$param.FS[7] - tt_sim_tron)^lppl_estimate_rob_3all_tron$param.FS[1] g_t_tron=( (lppl_estimate_rob_3all_tron$param.FS[7] - tt_sim_tron)^lppl_estimate_rob_3all_tron$param.FS[1] )*cos( lppl_estimate_rob_3all_tron$param.FS[2]*log(lppl_estimate_rob_3all_tron$param.FS[7] - tt_sim_tron) ) h_t_tron=( (lppl_estimate_rob_3all_tron$param.FS[7] - tt_sim_tron)^lppl_estimate_rob_3all_tron$param.FS[1] )*sin( lppl_estimate_rob_3all_tron$param.FS[2]*log(lppl_estimate_rob_3all_tron$param.FS[7] - tt_sim_tron) ) Y_tron=log(tron) #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_tron = sdum_tron*lppl_estimate_rob_3all_tron$param.FS[3] + lppl_estimate_rob_3all_tron$param.FS[4] *f_t_tron + lppl_estimate_rob_3all_tron$param.FS[5]*g_t_tron + lppl_estimate_rob_3all_tron$param.FS[6] *h_t_tron Yfit_tron_df=data.frame(subset(tron, Date>= "2017-12-01"& Date<=round(tron_subset$Date[1]+lppl_estimate_rob_3all_tron$param.JLS[7])-1),Yfit_tron) Y_tron<-subset(tron, Date>="2017-12-01" & Date<="2019-01-15") df_tron = list(Date=Y_tron$Date, Yfit_tron=Yfit_tron, Y_tron=log(Y_tron$TRX_Close)) attributes(df_tron) = list(names = names(df_tron), row.names=1:max(length(Y_tron$Date), length(Yfit_tron)), class='data.frame') df_tron colors_tr<-c("LPPL Tron Fit"="red", "Log Tron price"="blue") Y_fitted_actual_tron<-ggplot(data = na.omit(df_tron), aes(x = Date)) + geom_line(aes(y = Y_tron, color = "Log Tron price"))+ geom_line(aes (y=Yfit_tron, color = "LPPL Tron Fit")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Tron") + xlab(label='Date') + ylab(label='Fitted VS Actual') + labs(x = "Date", y = "Fitted VS Actual", color = "") + scale_color_manual(values = colors_tr)+ # coord_cartesian(ylim = c(-0.01, 0.048)) + theme(legend.position="bottom", legend.direction="vertical")+ scale_x_date(labels=date_format("%y-%m"))+ # coord_cartesian(ylim = c(-0.01, 0.048)) + themePlot Y_fitted_actual_tron #CARDANO cardano_subset<-subset(cardano, Date>= "2017-11-30" & Date<= "2018-01-02") lppl_estimate_rob_3all_cardano<-lppl_estimate_rob_3all(cardano_subset$ADA_Close, par_start = c(bet=0.5, ome=6, A=log(cardano_subset$ADA_Close[NROW(cardano_subset$ADA_Close)]), B=0, C1=0, C2=0), max.win.tc=0.1) ##lppl_simulate_FS_ethereum<-lppl_simulate_FS(T=1500, lppl_3step) lppl_estimate_rob_3all_cardano AIC_cardano<-nrow(data.frame(lppl_estimate_rob_3all_cardano$resids))*log((sum(lppl_estimate_rob_3all_cardano$resids^2))/nrow(data.frame(lppl_estimate_rob_3all_cardano$resids)))+2*7 print(AIC_cardano) kpss.test(lppl_estimate_rob_3all_cardano$resids) RMSE(lppl_estimate_rob_3all_cardano$resids) cardano_subset$Date[1]+lppl_estimate_rob_3all_cardano$param.JLS[7] n_fit_cardano<-round(lppl_estimate_rob_3all_cardano$param.JLS[7]) sdum_cardano=rep(1,n_fit_cardano) tt_sim_cardano=seq(1, n_fit_cardano, 1) f_t_cardano=(lppl_estimate_rob_3all_cardano$param.FS[7] - tt_sim_cardano)^lppl_estimate_rob_3all_cardano$param.FS[1] g_t_cardano=( (lppl_estimate_rob_3all_cardano$param.FS[7] - tt_sim_cardano)^lppl_estimate_rob_3all_cardano$param.FS[1] )*cos( lppl_estimate_rob_3all_cardano$param.FS[2]*log(lppl_estimate_rob_3all_cardano$param.FS[7] - tt_sim_cardano) ) h_t_cardano=( (lppl_estimate_rob_3all_cardano$param.FS[7] - tt_sim_cardano)^lppl_estimate_rob_3all_cardano$param.FS[1] )*sin( lppl_estimate_rob_3all_cardano$param.FS[2]*log(lppl_estimate_rob_3all_cardano$param.FS[7] - tt_sim_cardano) ) Y_cardano=log(cardano) #et=Y-sdum*A- B*f_t - C1*g_t - C2*h_t Yfit_cardano = sdum_cardano*lppl_estimate_rob_3all_cardano$param.FS[3] + lppl_estimate_rob_3all_cardano$param.FS[4] *f_t_cardano + lppl_estimate_rob_3all_cardano$param.FS[5]*g_t_cardano + lppl_estimate_rob_3all_cardano$param.FS[6] *h_t_cardano Yfit_cardano_df=data.frame(subset(cardano, Date>= "2017-11-30"& Date<=round(cardano_subset$Date[1]+lppl_estimate_rob_3all_cardano$param.JLS[7])-1),Yfit_cardano) Y_cardano<-subset(cardano, Date>= "2017-11-30" & Date<="2019-01-15") df_cardano = list(Date=Y_cardano$Date, Yfit_cardano=Yfit_cardano, Y_cardano=log(Y_cardano$ADA_Close)) attributes(df_cardano) = list(names = names(df_cardano), row.names=1:max(length(Y_cardano$Date), length(Yfit_cardano)), class='data.frame') df_cardano colors_c<-c("LPPL Cardano Fit"="red", "Log Cardano price"="blue") Y_fitted_actual_cardano<-ggplot(data = na.omit(df_cardano), aes(x = Date)) + geom_line(aes(y = Y_cardano, color = "Log Cardano price") )+ geom_line(aes (y=Yfit_cardano, color = "LPPL Cardano Fit")) + #scale_x_discrete(na.translate = FALSE)+ ggtitle("LPPL Cardano") + xlab(label='Date') + ylab(label='Fitted VS Actual') + labs(x = "Date", y = "Fitted VS Actual", color = "") + scale_color_manual(values = colors_c)+ # coord_cartesian(ylim = c(-0.01, 0.048)) + theme(legend.position="bottom", legend.direction="vertical")+ scale_x_date(labels=date_format("%y-%m"))+ # coord_cartesian(ylim = c(-0.01, 0.048)) + themePlot Y_fitted_actual_cardano grid.arrange(Y_fitted_actual_tron,Y_fitted_actual_cardano, ncol=2)