Book Image

Mastering R for Quantitative Finance

Book Image

Mastering R for Quantitative Finance

Overview of this book

Table of Contents (20 chapters)
Mastering R for Quantitative Finance
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Separating investment targets


An alternative method to build an investment strategy could be to separate good investment targets and check what is common between them. A good way to find similarities among stocks that performed well could be to create groups based on the TRS values and compare low- and high-performer clusters. The first step to this should be to analyze the following code:

library(stats)
library(matrixStats)
h_clust <- hclust(dist(d[,19]))
plot(h_clust, labels = F, xlab = "")

The following dendogram is the output for the preceding code:

Based on the dendrogram, three clusters separate very well, but to cut the biggest of them into two subgroups, we may need to increase the number of clusters up until seven. To keep the overview, we should try to keep the number of cluster to the lowest possible, so first, we will try to create three clusters only using the k-means method:

k_clust <- kmeans(d[,19], 3)
K_means_results <- cbind(k_clust$centers, k_clust$size)
colnames...