Subject:

To access the CryptoCompare public API in Python, we can use the following Python wrapper available on GitHub: cryCompare.

With the coinList() function we can fetch all the available cryptocurrencies (about 1450).

With the histoDay() function we can fetch the historical data (OHLC prices and volumes) for a given pair. We keep only coins which have a non-trivial history (about 1350).

We store all info in a dataframe with 2-level columns: the first level contains the coin names, the second one, the OHLC prices.

Since many coins are quite recent, many have relatively short time series of historical data.

We sort them by the decreasing length of their time series.

## Historical data for Bitcoin

BTC (Bitcoin) has the longest one, as expected.

For the following, we will only consider the 300 longest time series.

POT | TEK | BTC | ... | DGD | PIGGY | DIEM | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|

close | high | low | open | close | high | low | open | close | high | ... | low | open | close | high | low | open | close | high | low | open | |

time | |||||||||||||||||||||

2017-08-21 | 0.1282 | 0.1368 | 0.1265 | 0.1321 | 0.000120 | 0.000451 | 0.000079 | 0.000122 | 4005.10 | 4097.25 | ... | 74.14 | 78.93 | 0.000681 | 0.000696 | 0.000555 | 0.000610 | 0.000040 | 0.000041 | 0.000040 | 0.000041 |

2017-08-22 | 0.1267 | 0.1411 | 0.1089 | 0.1282 | 0.000123 | 0.000166 | 0.000108 | 0.000120 | 4089.70 | 4142.68 | ... | 67.84 | 78.34 | 0.000614 | 0.000704 | 0.000397 | 0.000681 | 0.000041 | 0.000041 | 0.000036 | 0.000040 |

2017-08-23 | 0.1245 | 0.1335 | 0.1191 | 0.1267 | 0.000124 | 0.000170 | 0.000081 | 0.000123 | 4141.09 | 4255.62 | ... | 76.57 | 78.85 | 0.000621 | 0.000809 | 0.000570 | 0.000614 | 0.000041 | 0.000043 | 0.000041 | 0.000041 |

2017-08-24 | 0.1289 | 0.1324 | 0.1211 | 0.1245 | 0.000130 | 0.000131 | 0.000082 | 0.000124 | 4318.35 | 4364.11 | ... | 80.01 | 89.70 | 0.000648 | 0.000698 | 0.000576 | 0.000621 | 0.000043 | 0.000044 | 0.000041 | 0.000041 |

2017-08-25 | 0.1335 | 0.1576 | 0.1266 | 0.1289 | 0.000133 | 0.000179 | 0.000086 | 0.000130 | 4442.46 | 4461.71 | ... | 90.69 | 93.97 | 0.000622 | 0.000669 | 0.000602 | 0.000648 | 0.000044 | 0.000045 | 0.000043 | 0.000043 |

5 rows × 1200 columns

All these 300 time series have at least 1000 days of observed prices.

We will only consider these days for the correlation study.

Below, we compute their daily log-returns.

Notice below that the scale is pretty huge compared to other financial assets (which are usually contained in a (-0.15,0.15) range, with some tails valued at ~2 or 3).

Now, we compute a correlation/distance matrix between all these coins.

Notice that we consider here the OHLC representation, and thus we have to compute a correlation between random vectors, and not random variables (which is usually done by considering only the ‘close’ price for example).

The *distance correlation* is a relevant measure of statistical dependence for that purpose.

We apply it between the 300x299/2 = 44850 pairs in parallel using the *joblib* library.

Then, using the dendrogram obtained from the Ward hierarchical clustering method, we can sort the coins so that their correlation/distance matrix is more readable.

We can observe that some coins do cluster together as they are correlated and uncorrelated to the rest of the coins in a similar way.

For example, we obtain the following clusters (if we ask for 30 groups).

We can use these clusters to average the values of the correlation-distances inside and in-between the clusters.

We obtain the following filtered matrix:

For example, below are the ‘close’ log-prices of one rather strong cluster: