Algorithmic Trading Python

Hierarchical Clustering on STI Component Stocks

Previously we did a K-Means clustering on STI component stocks. It is interesting to compare the clustering with another popular clustering method – hierarchical clustering. In this video, we will demonstrate hierarchical clustering on STI component stocks.
The first few steps are identical to my previous video on k-means clustering, so I will not repeat it over here.
We jump straight to look at the Dendrogram of the dataset. If we choose a distance of about 20-30 for clustering criteria, we can get about 5 clusters. We see that SATS is in one cluster by itself. It is interesting to note that DBS and UOB seem to be in different clusters.
Next we perform the hierarchical clustering using scikit learn package for 5 clusters. Again we see that Jardine Matheson Holdings Limited is the only one in cluster 2 and SATS is the only one in cluster 3. This is similar to k-means clustering. Unlike the denogram, now DBS and UOB are in the same cluster 4.
Next, we visualize the clusters on the 2D plots of eps vs beta. We see the hierarchical clustering yield slightly different results as compared to k-means clustering. In k-means clustering, ventures belonged to the orange cluster, and OCBC belonged to the blue cluster. Now they were both in the same cluster as DBS and UOB.

The code can be downloaded below

Recommended trading platforms


Recommended courses on Algorithmic Trading

1. Basic Algorithmic Trading with Python

2. Machine Learning for Algorithmic Trading

Other training courses from Tertiary Courses

June 14, 2022