Optimal rebalancing of portfolios with transaction costs