UBS posted a loss in the third quarter on spiraling costs of merging with its rival Credit Suisse.