Calculating Number of Trades

Course Name: Unsupervised Learning in Trading, Section No: 20, Unit No: 5, Unit type: Notebook

How are the number of trades calculated within the clusters?


Hi Ronak, 
No. of trades within a cluster is nothing but the length of the cluster. 

In the model solution given, we have divided the entire dataset into 17 clusters. The number of trades in each cluster would be equal to no. of rows in the cluster i.e. the length of the cluster.
In cell 11, we have calculated the no. of trades in a cluster using the following code.
clusters_trades = goog_train.groupby(['Cluster'])['fut_ret5_days'].count()
Here, we grouped the dataframe 'goog_train' by 'Cluster'. To find the length of the cluster (no. of trades within a cluster), we selected 'fut_ret5_days' column (can select any column) and calculated the number of elements in the column.  
The number of elements in any column of a cluster would be equal to the number of trades within a cluster.

Hope this helps!
Thank you