Investing is a marathon, not a sprint. If you understand the fundamental factors that drive margins and profits, then you can gain an advantage over shortsighted traders. Right now such a situation is shaping up in the oil and gas industry. Over the next two to three years new infrastructure is going to boost the margins of many smaller producers and hurt many refiners. 

New pipelines galore
Through fancy permit schemes Enbridge has already started work on its Flanagan South Pipeline, which will have initial capacity of 600,000 barrels of oil per day (bpd). The project will help bring more crude from the Midwest down to refineries. The company has also proposed the Sandpiper project from North Dakota to Wisconsin and recently increased its Bakken export capacity to 415,000 bpd. There is so much new capacity coming online that some firms have cancelled new pipeline plans due to a lack of producer interest. 

KOG Operating Margin TTM Chart

KOG Operating Margin TTM data by YCharts

The winners
The biggest beneficiaries of new pipeline capacity are smaller exploration and production firms in North Dakota's Bakken region. Their margins will expand as they pay less to bring their oil to market. Some new pipelines are being built eastward, giving producers like Kodiak Oil & Gas (NYSE: KOG) the ability to sell oil closer to lucrative international prices. 

Kodiak expects to produce around 30 Mboepd (thousand barrels of oil equivalent per day) to 34 Mboepd in 2013. The company is a great way to play North America's increasing midstream capacity due to its heavy concentration in the Bakken. The company continues to drive down costs and improve its operations. From 2011 to 2012 it managed to shave off seven days from its average drilling time per well. Based on recent numbers, its quarterly cash margin has increased year over year from $54.59 per barrel of oil equivalent to $61.15. Increased margins from new pipeline capacity is only icing on the cake. 

Continental Resources (CLR) is a bigger producer than Kodiak, but it is nowhere near the size of multinationals like Shell. Continental produced 135.7 Mboepd in the second quarter of 2013. The majority of its production came from the Bakken, but it is also exploring in Oklahoma's SCOOP field. This field is not as developed as the Bakken, and the company is figuring out where the best place is to drill to produce more crude oil and less natural gas. 

In 2013, the company expects to pay just $5.20 to $6.00 per Boe in production expenses. Just like Kodiak, falling inventories in Oklahoma and new pipelines heading out of the Midwest will boost how much Continental makes on every barrel of oil.

The losers

Brent WTI Spread Chart

Brent WTI Spread data by YCharts

Every story has two sides, and this one is no different. While exploration and production firms will see their margins rise over the next two years, many refiners face the opposite trend. The U.S. does not allow for raw crude exports, so refiners have been making a pretty penny by buying cheap American oil and selling refined products internationally.  

HollyFrontier (HFC) has played the market very well with refineries in Wyoming, Kansas, Oklahoma, Utah and New Mexico. In the coming years the placement of its refineries close to shale producers will continue to be an advantage for the company, but expect its margins to fall. The above chart shows how its operating margin follows the Brent WTI spread very closely, and there is no reason for the relation to break down. 

HollyFrontier's balance sheet is healthy with a total debt to equity ratio of 0.16. It is highly unlikely that falling margins would bankrupt the company, but it is likely that its special dividends and any future share repurchase programs will be scaled back.

While the majority of refiners are looking at painful years ahead, Tesoro (ANDV) is a different story. It has refineries in Alaska, North Dakota, Utah, Washington, California and Hawaii. The company has a relativity difficult time acquiring substantial supplies of cheap Midwest oil.

In 2012, 55% of Tesoro's Washington refinery's input was expensive Alaskan North Slope, or ANS, crude. Thanks to improved rail links and better transportation from Canada and the Bakken, the refiner hopes to replace a significant portion of ANS with cheaper Midwest crude. While many refinery dividends have questionable futures, Tesoro's 2.1% yield is a different story thanks to future changes in its crude oil consumption. 

Conclusion
Right now infrastructure is being built that will boost Bakken drillers like Continental and Kodiak and bring down the margins of Midwest refiners like HollyFrontier. It would be tempting to simply downgrade Tesoro with the rest of the refining industry, but it is just starting to take advantage of cheaper crude. Fundamental changes are reshaping the industry, and this is a great time to reshuffle your portfolio or watchlist.