Since Brexit, shares in Royal Dutch Shell (LSE: RDSB) and BP (LSE: BP) have charged higher, outperforming the wider market by a significant percentage. Specifically, shares in BP and Shell have rallied by 18% and 12% respectively, outperforming the FTSE 100 that has chalked up a gain of only 5.1% over the same period.

The big question is, are these gains are sustainable or will the shares in these two oil giants return to the pre-referendum lows when reason returns to the financial markets? To understand whether or not Shell and BP’s recent performance is sustainable, we need to look at why these companies saw their shares rally in the first place.

Looking for the cause

The cause of the rally can be traced to the devaluation of sterling. As I wrote two weeks ago, over the three trading days following the result of the referendum, the price of oil fell from a little over $50 per barrel to $48/bbl, but in sterling terms the price of Brent crude jumped by around 8.4%. As both Shell and BP report results in US dollars, a weaker pound will translate into higher profits, and higher profits generally lead to higher share prices.

So the performance of shares in Shell and BP since the end of June can be traced almost exclusively to sterling’s weakness. At time of writing, the price of Brent crude is actually lower than it was before the referendum at $47/bbl.

You could attribute Shell and BP’s recent gains to an accounting benefit. Fundamentally nothing has changed regarding the operations of these companies and if anything, a lower oil price is bad for the businesses. As a result, it’s difficult to tell if it’s time to book gains with Shell and BP.

Take a long-term outlook 

For long-term investors, there’s no need to rush into anything. Nothing has changed operationally for these two oil giants, they offer investors extremely attractive dividend yields and are likely to generate significant returns for your portfolio over time. However in the near term, shares in Shell and BP might return to pre-referendum levels if sterling strengthens and the price of oil remains depressed.

Moreover, it’s unlikely that the shares will fall back to the lows seen in January. When the price of oil collapsed to a multi-decade low during January of this year, shares in Shell and BP slumped to five-year lows as investors fled the sector. But BP and Shell have been busy pruning operations over the last 24 months to cut costs and better cope with the low oil price. As a result, these companies are in a much stronger position than they were two or three years ago. Production costs have declined, unproductive assets have been sold off, and capital spending has been cut back sharply. All of which mean that Shell and BP are extremely well-positioned to weather low oil prices and continue to churn out a profit for investors.

Shares in Shell currently support a dividend yield of 6.7% and trade at a forward P/E of 27.2. BP’s shares support a yield of 6.6% and trade at a forward P/E of 30.9.

The worst mistake you could make

According to a study conducted by financial research firm DALBAR, the average investor realised an average annual return of only 3.7% a year over past three decades, underperforming the wider market by around 5.3% annually.

This underperformance can be traced back to several key mistakes that all investors make. To help you realise and understand the most common mis-steps, the Motley Fool has put together this new free report entitled The Worst Mistakes Investors Make.

The report is a collection of Foolish wisdom, which should help you avoid needlessly losing too many more profits. Click here to download your copy today.

Rupert Hargreaves owns shares of Royal Dutch Shell B. The Motley Fool UK has recommended BP and Royal Dutch Shell B. We Fools don't all hold the same opinions, but we all believe that considering a diverse range of insights makes us better investors.