CME Group will change the way it sets margins for gold, silver, platinum and palladium futures after a surge in prices and volatile trading.