Hierarchical clustering for optimal portfolios