Don't look now, but oil prices are at heights we haven't seen in over seven years. With oil hovering close to that $80 per barrel level, many investors are asking whether they should jump into oil stocks after avoiding the sector altogether. 

Oil investing over the past decade has been...unpredictable. But through those unpredictable times, two oil stocks have stood out as great investments: Marathon Petroleum (MPC -3.67%) and Valero Energy (VLO -2.86%). Here's why these two have done so well over the years and why now may be a good time to invest in both. 

An oil refinery at sunset.

Image source: Getty Images.

The most resilient wealth creation machines in the oil business

The oil and gas business is a tough one to pin down. The business is capital intensive and tends to move from boom and bust cycles in a quick fashion. Free cash flow is one of the hardest things to come by because of the fleeting nature of oil prices and the ripple effects that can have across the industry. 

This past decade has, arguably, been one of the worst for oil and gas. In 2010-2012, energy represented between 9% to 12% of the S&P 500. Today, the sector's weight has dropped to only 2.67% of the broader index, the lowest weighting for the sector since 1967, and that's only because it's the furthest back I could track down sector weightings; it could be worse than that. 

And yet, through all the turmoil of the oil and gas industry this past decade, there have been two oil & gas companies that have beat the S&P 500 on a total return basis: Marathon Petroleum and Valero Energy. 

It's no coincidence that the two of the best performers in the oil business over the past decade are refiners. It is a business that can make money when oil prices are high or when oil is dirt cheap. After all, their profit margin comes from the difference in price between crude oil and the refined products they produce rather than the absolute price of any product.

A well-maintained refinery can last decades, so refiners don't need to spend billions year in, year out to replace production as exploration and production companies do. This frees up capital and allows them to generate loads of free cash flow along the way. They are by no means high-growth businesses, but a smartly run refiner can use all that excess cash to pay a generous dividend and repurchase shares to grow shareholder value. 

Over the past decade, Valero has bought back 25.9% of shares outstanding and grown its dividend by 880%. Even including Marathon's $23 billion merger with Andeavor in 2018 and the shares it issued for that monster deal, its shares outstanding are 9% lower than a decade ago, and its dividend payment is 321% higher. Furthermore, Marathon has a plan to purchase $7.5 billion worth of shares in 2022 alone. Those dividend increases came as so many other companies in this industry cut or suspended dividends due to COVID lockdowns or crashing oil prices. 

^SPXTR Chart

^SPXTR data by YCharts

The long-term concern for refiners is the demand for refined products getting displaced by alternative energy. Adoption of electric vehicles is one of the faster-growing components of the energy transition right now. Fortunately for both companies, there is a long runway before we're likely to see refined product demand decline on an absolute basis, and both companies are investing to transition to renewable fuels for a life after oil.

Despite being the most resilient wealth creators in the industry, shares of both Marathon and Valero trade at attractive valuations. Valero's dividend yield is 4.89% and Marathon's is 3.31%. Valero's share buyback program isn't as robust as Marathon's, but management is still targeting to return 40% to 50% of cash from operations in the form of dividends and share repurchases annually. 

Buy, avert your eyes, and hold

Investing in refiners isn't easy. Even though both Valero and Marathon have returned market-beating total returns, you would have had to remain invested through several declines of more than 30% and even a 75% drawdown in March 2020. If you have the stomach to handle that kind of volatility, though, you would be hard-pressed to find better long-term investments in the oil patch.