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
https://github.com/tertiarycourses/Algorithmic-Trading/blob/main/hierarchical_clustering_clustering.ipynb

Recommended trading platforms

MooMoo https://j.moomoo.com/00i5px

Recommended courses on Algorithmic Trading

1. Basic Algorithmic Trading with Python
https://www.tertiarycourses.com.sg/python-algorithmic-trading-course.html https://www.tertiarycourses.com.my/python-quantitative-analysis-and-algorithmic-trading-malaysia.html
https://www.tertiarycourses.com.gh/python-quantitative-analysis-and-algorithmic-trading-ghana.html

2. Machine Learning for Algorithmic Trading
https://www.tertiarycourses.com.sg/machine-learning-for-algorithmic-trading.html https://www.tertiarycourses.com.my/machine-learning-for-algorithmic-trading-malaysia.html https://www.tertiarycourses.com.gh/machine-learning-for-algorithmic-trading-ghana.html

Other training courses from Tertiary Courses

https://www.tertiarycourses.com.sg/
https://www.tertiarycourses.com.my/
https://www.tertiarycourses.com.gh/

June 14, 2022