# Which are useful applications of clustering in quantitative finance?

Several machine learning algorithms have been applied in finance/trading. Focusing on clustering (k-means, k-medoids) what are useful and successful applications in quantitative finance? What is used by practitioners? Are there references or reports available?

EDIT: After those very good remarks and answers I wanted to insert this link where clustering and the development of clusters of asset classes (gold, stocks, bonds and much more) is presented.

• Any time you want any kind of dimension reduction, clustering could be a tool worth using. For instance, grouping companies into buckets based on financial characteristics. Not sure of any good survey articles. The tricky part with clustering is that a lot of the literature is focused on the cross-section, whereas finance can exploit time series data as well. – John Mar 4 '16 at 15:03
• As specific example, some people use clustering in Portfolio Optimization. Instead of using a correlation matrix, they use clustering to group stocks in groups with similar behaviour, as a first step in building a diversified portfolio. I have seen article claiming this works well. – noob2 Mar 4 '16 at 17:14

One potential use I could imagine would be identifying paradigm shifts / regime change. Just as a quick toy example, maybe you're interested in how gold is often considered a hedge against downturns in the stock market. Say you are building a trading strategy based on that intuition, but want your model to be more flexible by identifying different regimes for which different approaches might work better. Clustering methods might help in that analysis. Here's a quick example of how one might visualize that type of thing.

I also found a few resources on the web after a quick search that you might find interesting.

1. Dynamical analysis of clustering on financial market data
2. Cluster Analysis for Evaluating Trading Strategies
3. Survey of Deep Learning Techniques Applied to Trading (more general ML but still a good read)

R code used to make the plot:

library(Quandl)
syms = c(SP500="YAHOO/INDEX_GSPC.4", Gold="CHRIS/CME_GC1.6")
nmeans = 3
prices = na.omit(Quandl(syms, type='xts'))
df = as.data.frame(prices)
clusters = kmeans(df, centers=nmeans)\$cluster
par(mar=c(2.5,2.5,0.5,0.5), mgp=c(1.5,0.5,0), family='mono', cex=0.7)
x = as.numeric(prices[,1])
y = as.numeric(prices[,2])
plot(x, y, pch=-1, xlab=names(syms)[1], ylab=names(syms)[2])
for (i in 1:nmeans){
xx = df[clusters==i,1]
yy = df[clusters==i,2]
points(xx, yy, pch=19, col=rgb(t(col2rgb(i)/255), alpha=0.2))
f = lm(yy~poly(xx, 3))
lines(x=xx, y=predict.lm(f, data.frame(x=xx)), col=i, lwd=2)
}
grid(lty=1, col=rgb(0,0,0,0.2))

• Very good answer and thank you very much for the code. I also stumbled upons somehing similar here. systematicinvestor.wordpress.com/2013/01/12/… – Ric Mar 7 '16 at 7:16
• This post was recently featured on Quantopian if you're still looking for more fodder :) – Jacob Amos Mar 29 '16 at 22:27