Clustering Cryptocurrencies with Affinity Propagation
By: Sebastian Quintero
Tags: Machine Learning, Crypto, Venture Capital, Blockchain, Bitcoin

With the problem well defined, we deployed an Affinity Propagation algorithm to find three distinct clusters of crypto assets, at the top end of the market capitalization table, with similar movements. The rest of this paper discusses the theoretical and practical rationale for our approach, details the results, and wraps up with some brief concluding remarks.

Before continuing it must be stressed, as always, that statistical methods, no matter how exhaustive, will only ever provide a probabilistic view of the world. They do not declare causal relationships nor absolute truth. Still, this gave us plenty to think about. Hopefully you’ll agree.

Why Affinity Propagation?

From the beginning, we identified some essential desiderata that the algorithm needed to maintain in order to produce scientifically diligent results. Overall, we found that Affinity Propagation not only met all our desiderata but is also just generally a very powerful algorithm in theory and in practice.

Affinity Propagation, published in Science by Frey and Dueck, takes as input measures of similarity between data points and exchanges real-valued messages between data points until high-quality clusters naturally emerge. While exchanging messages the algorithm identifies exemplars, which are observations that do a good job of describing a cluster. You can basically think of exemplars as centroids, with the exception that they are not the average value of all objects in each group, but rather a real observed data point that describes its closest neighbors. For our purposes, that implies that our exemplars will be some real crypto asset. That said, after running the algorithm we still computed centroid “trend” lines and show them in the plots below to facilitate interpretation.

With the exemplars identified, the algorithm itself teases out how many natural clusters exist in the data. The only hyperparameter that really needs to be carefully tuned, according to the creators, is the damping factor, which is set to avoid numerical oscillations as messages are being passed between data points. The creators recommend setting the damping factor to 0.9. In our task, values between 0.5 and 0.83 resulted in the identification of four clusters. Increasing it above 0.83 resulted in three clusters. More specifically, setting a higher damping factor combined clusters three and four from the lower damping set, with the first two clusters being completely unchanged. In the end, we set the damping factor above 0.83 because the results where marginally more intuitive.

We considered a few other algorithms for the task, however, none fulfilled one or more of our desiderata. We knew that identifying cryptocurrencies that are very similar for only a few months out of the year, but completely dissimilar the rest of the year, would be undesirable. Equally important, we wanted to measure, and therefore isolate, as much as possible, the daily impact of the news cycle on market capitalizations; ignoring any delayed effects. Therefore, similarity needed to be evaluated exclusively at each date index, but across the entire array. Dynamic Time Warping, which is a popular approach for measuring the similarity of time series data with varying lengths and with out-of-phase similarities would not work–exactly because it attempts to find out-of-phase similarities. We have the luxury of a problem where the data is intentionally in-phase and of the same length. And as described above, k-means clustering and its many variants would not work because we don’t want to tell the robot how many clusters there should be.

For the distance measure, it was determined that standard negative Euclidean distance would do the job well if we could standardize the power law distributed data. And to do just that, each vector was first log transformed and then standardized by subtracting its mean and dividing by its standard deviation; producing a clean and comparable dataset.

Conveniently, all of the above implied that sci-kit learn’s Affinity Propagation implementation would do just fine, for our purposes. We pulled historical data for the top 50 crypto assets, in terms of market capitalization, from Coinmarketcap.com in early February. Of those 50, only 26 have been around sufficiently long enough for effective clustering (at least a year).

Results

The side-by-side plots below correspond to each of the three identified clusters. On the left, we present the clusters in time series form, with the exemplar in white and the centroid line of all objects in the cluster in bright yellow. The other constituents in the space are shown in faint yellow. On the right, we present the corresponding box plot for each cluster, which effectively provides a look at the same data from a different perspective. The Affinity Propagation algorithm found three exemplars: Ripple, Tether, and DigixDAO. The first cluster consists of largely established crypto assets.