In this paper we investigate the performance of the threshold accepting heuristic for the index tracking problem. The index tracking problem consists in minimizing the tracking error between a portfolio and a benchmark. The objective is to replicate the performance of a given index upon the condition that the number of stocks allowed in the portfolio is smaller than the number of stocks in the benchmarking index. The quantities of stocks in the portfolio are integers. Transaction costs have to be faced each time that the portfolio is rebalanced. We find the composition of a portfolio that best tracks the performance of the benchmark during a given period in the past and then look at the performance of the portfolio in the subsequent period. We report computational results in the cases where the benchmarks are market indices tracked by a small number of assets. We find that the threshold accepting is a very suitable and efficient optimization technique for this problem.