What happened

Shares of North American oil and gas producers APA (APA -0.63%), Centennial Resource Development (PR 0.20%), and Obsidian Energy (OBE -2.94%) were surging this week, up 10.9%, 12.6%, and 11.1%, respectively as of noon ET on Friday.

Each of these companies is a North American shale producer, although APA has some offshore and international operations as well in the U.K., Egypt, and off Suriname, while Centennial is a pure play on the Delaware Basin of the Permian shale, and Obsidian operates in western Canada.

There wasn't a lot of new news from any of these companies, although APA did announce a discovery of oil in its leased block off the coast of Suriname.

The synchronous moves suggest broader events in the oil and gas markets were the primary reasons for the week-long outperformance. On that front, oil prices stabilized on comments by Saudi Arabia that OPEC+ could cut back production if prices went down too much; meanwhile, Russia limited its supply of natural gas to Germany, causing natural gas prices to spike. Finally, China announced fresh stimulus measures meant to boost economic activity. 

So what

On Monday, oil rose as Saudi Arabia's energy minister said it was possible OPEC+ could cut output amid falling prices, and that spare capacity was actually quite tight. The minister basically said the recent fall in oil prices wasn't substantiated by the physical markets but rather low liquidity, volatility, and fears over demand destruction within financial markets.

The prospect of OPEC+ actually reversing its recent production increase to curtail production was helping sentiment earlier in the week. Oil prices had fallen since June, from over $120 to close to $90 today.

Also likely helping sentiment were new stimulus measures out of China on Thursday. Amid flailing growth that seems set to come in well below its annual target, Chinese authorities authorized another $117 billion in stimulus, primarily aimed at infrastructure spending and consumption. That also helped sentiment on the demand side, as Chinese lockdowns have no doubt played some part in oil's recent decline.

Finally, Russia announced it would be shutting off gas flows through the Nord Stream natural gas pipeline to Germany for three days at the end of August, claiming it was for maintenance purposes. However, it is strongly suspected the cutoff is politically motivated. U.S. natural gas competes with the price of exports, so with natural gas prices soaring in Europe, U.S. natural gas prices actually touched a 14-year high this week before backing off.

All three of these companies drill for a combination of oil and natural gas. While oil is still the majority output for each, investors shouldn't ignore natural gas's strong contributions to each company's results.

Finally, APA announced it had struck oil and gas off the coast of Suriname. CEO John J. Christmann said in a press release, "Our success at Baja marks the sixth oil discovery we have participated in offshore Suriname, and the first on Block 53... This result confirms our geologic model for the Campanian in the area and helps to derisk other prospects in the southern portion of both Blocks 53 and 58."

Now what

The energy sector is incredibly important to the overall global economy, and prices are quite volatile right now. At the same time, many energy-related companies look quite cheap, trading a single-digit P/E ratios.

Therefore, it is probably a good idea to have some exposure to the sector, as energy companies provide somewhat of a hedge against supply shocks, while most also pay out handsome dividends. This week provided an example of the energy sector doing well, even as tech and other economically sensitive sectors fell.

Investors would probably do well to keep their energy exposure fixed as a percentage of a diversified portfolio due to these attractive attributes.