Valero Energy Corporation (VLO -2.09%) continues to trade near its 52-week high following its impressive earnings for the first quarter of 2014. Valero, which is the largest U.S. oil refiner, posted a 27% year-on-year increase in quarterly profit to $838 million, or $1.54 a share. This was its best first-quarter per-share profit since 2007. This performance shored up its share price, allowing it to maintain the gains it has made over the past several years. Over the last five years, shares of Valero have gained over 160%. The chart below is testimonial to this assertion.

Valero's share price movement over the last five years; Source: Yahoo! Finance

While Valero's overall performance in the past five years is irrefutably strong, long-term investors should remain cautiously optimistic. Even as its share price inches closer to pre-recession highs, there are some prominent sticking points in the broader refining industry that could weigh on its long-term performance.

Going beyond the numbers
Typical earnings numbers rarely provide any deep insight for long-term investors, especially those invested in oil stocks. Investors should take into account the industry structure as well as the company's underlying fundamentals before committing to any investing decision.

The high WTI/Brent spread allows U.S. refiners to get their feedstock at cheaper prices relative to their international counterparts. This gives U.S. refiners a chance to price their finished products competitively in the international market. This cost advantage is declining, however. In contrast, the WTI/Brent spread in 2012 and most of 2011 was for the most part higher than $15, again with a few exceptions.

The gradual narrowing of the WTI/Brent spread over the years has been triggered primarily by gains in WTI that were induced by domestic crude supply constraints due to insufficient transport infrastructure to match production, lower production by domestic oil producers due to profit margin pressures, and more recently, increased speculation that the U.S. will export crude oil to global markets. This speculation has been compounded by Russia's aggressive stance in conflict-stricken Ukraine.

Moreover, increased demand for midstream infrastructure to match current production has prompted the relocation of financial resources to midstream players. One study by Deloitte says that around $200 billion will be needed in additional midstream investment by 2035. Naturally, such high-level investments demand high returns. This will be achieved through upward adjustments in logistic fees, disrupting cost structures for oil refiners and compelling them to make do with lower margins.

As the WTI spread continues to decline and transport costs increase, costs for most U.S. refiners will increase. This will lead to a decline in profitability. These complexities will inject a certain level of risk into the oil refining sector.

Valero's risk-aversion technique is compelling
After considering the risks in the overall refining industry, a rational investor would pull out of Valero at current highs while he still can. However, Valero has factored in these industry risks and has a risk-aversion technique that will allow it to overcome and multiply its value in the wake.

First, Valero's refinery footprint in the Gulf Coast comes as a great strength in view of shifts in the midstream segment. Before, Valero had to import expensive Brent for its Gulf Coast operations because of the lack of sufficient transport infrastructure to bring cheaper crude from inland sources such as Oklahoma. Now, new pipelines such as the southern leg of TransCanada Corp.'s Keystone XL project are bringing oil from inland sources such as Oklahoma to the Gulf. This is reducing Valero's reliance on expensive Brent, and consequently lowering its overall production costs.

Second, Valero's heavier involvement in logistics will allow it to get cheaper transportation fees in the coming years. Its 69% stake in Valero Energy Partners LP (NYSE: VLP) is testimonial to its commitment to securing cheaper logistics fees. Similarly, by its own projections, 45% of an estimated $1.52 billion budget labeled as growth investments for 2014 will go to logistics. By achieving lower transportation and storage costs relative to the broader industry, Valero will get cost advantages that allow for competitive pricing of refined products, increasing turnover and cash flow relative to the broader market, and allowing for continued expansion in core areas. 

Third, Valero is overhauling its refineries by adding specialized equipment. This equipment will allow it to process light crude into unfinished components that pass the legal threshold for export but require further processing in their destination markets to get final products like diesel. This means that when crude costs rise due to uncontrollable factors such as pipeline congestion, political risks, and supply constraints, Valero will still be able to offset increased feedstock costs by spending less on the refining process. This will preserve the product's final profit margin.

Foolish bottom line
Valero has had a great run. It is perfectly natural for investors to assume that this gravy train will derail in view of the risks in the broader refining industry. Valero, however, has a compelling risk aversion strategy that will not only enable it to overcome industry difficulties, but allow it to do so while its peers will be struggling. This will compound its value and multiply returns for patient long-term investors.