Pattern matching Cryptocurrencies

Bitcoin, Ethereum and some other cryptocurrencies seem to be in the spotlight again due to their most recent acceleration.
C_y2pGfXoAApvdI

Source: CEOTechnician

Ethereum is up multiples since January. I thought we could take a look at importing Etherum price data in R and then seeing if we can draw any parallels between Ethereum and Bitcoin using the pattern matching algorithm we’ve looked at here before.

But first we will load Bitcoin data in R, since it can be more easily accessed through the Quandl API.

library(Quandl)
library(SIT)
library(quantmod)
library(ggplot2)

BTCUSD = Quandl("BCHAIN/MKPRU",type="xts")
head(BTCUSD)
colnames(BTCUSD)[1] =  'avg_price'
BTCUSD.Avg = BTCUSD[,1]

par(mfrow=c(2,1))
ggplot(data=fortify.zoo(BTCUSD), aes(x=Index, y=avg_price))+
  geom_line(aes()) + scale_y_log10() + ggtitle("Bitcoin in USD (Log10)")


ggplot(data=fortify.zoo(BTCUSD), aes(x=Index, y=avg_price))+
  geom_line(aes()) + ggtitle("Bitcoin in USD ")

bitcoin1

As you can see Bitcoin is undergoing another run-up in prices. It’s difficult to see previous runs in the price, so we will also plot bitcoin prices on a log scale, as to better see the percentage gains.

bitcoin_log10

The price acceleration looks more tame in this view relative to previous ones, but the market capitalization of bitcoin has grown much larger than when it had its initial run.

Lets take a look at Ethereum now. We will pull in data via the Poloniex API, process the JSON object and convert the dates. Finally we will look at the linear and log price graphs.

url_m = 'https://poloniex.com/public?command=returnChartData&currencyPair=USDT_ETH&start=1435699200&end=9999999999&period=86400'

library(jsonlite)
mkt_data <- fromJSON(url_m)


ETH <- as.xts(mkt_data[,5],order.by=as.Date(as.POSIXct(mkt_data[,1], origin="1970-01-01")))
colnames(ETH) <- 'ETH'
head(ETH)

ggplot(data=fortify.zoo(ETH), aes(x=Index, y=ETH))+
  geom_line(aes()) + scale_y_log10() + ggtitle("Ethereum in USD (Log10)")


ggplot(data=fortify.zoo(ETH), aes(x=Index, y=ETH))+
  geom_line(aes()) + ggtitle("Ethereum in USD ")

etheth2

What a run!

Lets take a look at the bitcoin data again and see what the closest matches are for the most recent run up. We will be using code similar to a previous post.

bitcoin_Match1

Using a 63 day period for pattern matching and dynamic time warping, we get these results. The prices highlighted in blue are the most recent prices we are matching, and the prices in red are the 10 closest matches.

matching_new

It looks as though most of the upside in the price gains has already been had, as the forward week, month, quarter returns are all negative. Having said this, there was also one run (Match 5) that had a 1,044.7% run.

In the future, we may look at pattern matching log prices, or cross-market pattern matching, for example Ethereum’s recent price run on Bitcoin’s history.

*Not investment advice

If you are trading this parabolic spike, be careful and always use stops. I found this idealized image of stop placement fascinating. stops

Source: “Stop Techniques – The Implications From Inconsistent Forecasting Skills ” Nordea