With oil at an all-time high, Big Oil should be making big money. Instead, a handful of energy companies have issued profit warnings. Why? Refining margins have collapsed while the cost of extracting new resources has surged.

The fundamentals of the oil market, however, suggest this profit squeeze should be short-lived.

BP Plc. chief Tony Hayward kicked off the gloomy round of profit warnings when he said the third quarter was going to be “dreadful."

ConocoPhillips Co., Chevron Corp. and now, the largest US refiner, Valero Energy Corp., have followed suit. The explanation lies in the refining business, one of the industry’s chief profit generators.

Refineries make money by turning crude oil into products such as petrol. Oil majors such as Chevron derive around 25% of their profits from this business. In the past few years, refiners have been minting money due to rising demand for products, a constraint on refining capacity and higher environmental standards.

In the second quarter, refinery outages sent profit margins through the roof. Producers averaged $24 (Rs943) of profit per barrel of crude—50% higher than the same time a year earlier. Investors expected some carry-over of these record prices. Instead, it appears that refining profits will be more or less in line with the $12 per barrel of a year ago.

The problem was that crude prices, buoyed by speculative fervour, rose faster than the price of refined products, such as petrol and heating fuel. The refiners were unable to pass on the increased cost of their primary commodity in short order.

Fundamentally, this disparity between crude and refined products makes no sense. Crude stocks remain above five-year highs, while product stocks are far below average levels, while demand has not fallen materially. Furthermore, an expected seasonal increase in demand for heating oil, combined with a drop in refining capacity due to maintenance turnarounds, should boost product prices.

In addition, the futures market is suggesting that crude oil prices will fall in the coming months. All of this suggests that refining margins should return to more robust levels. Of course, that’s only the case in a perfect market driven by fundamentals. Given the increasingly speculative nature of the oil market, anything goes.