What happened

Shares of U.S. oil and gas producers Diamondback Energy (FANG 0.43%) and Centennial Resource Development (PR 0.47%), along with deepwater drilling rig provider Transocean (RIG -2.69%) all rallied big on Monday, rising 5.8%, 5.5%, and 7%, respectively, as of 3:50 p.m. ET.

Oil stocks found their footing as oil prices rose more than 2% Monday. The rise in oil has come after a month-long decline from the June peaks; however, it appears as though prices may be stabilizing in this area, which would still enable producers to make handsome profits while also incentivizing new drilling.

A huge heatwave, along with more tensions in the Russia-Ukraine war over the weekend, may be helping to put a floor under oil and gas prices today. In addition, a prominent analyst published a bullish note on U.S. oil stocks, citing Diamondback specifically as a favorite. 

So what

There wasn't a specific catalyst for oil and natural gas prices to rise today, but it could have something to do with Russia's bombing of the port of Odessa this weekend. Last week, Russia and Ukraine signed an agreement to unblock the Black Sea port to get Ukraine grain out of the country, but just after the agreement was signed, Russia bombed the Odessa port. In addition, Russia has also reduced the gas flowing through the Nord Stream pipeline to about 20% of capacity. While Russia has cited equipment issues, Germany believes the arresting of gas flows is deliberate.

In any case, increased geopolitical tensions typically raise concerns over the supply of oil and gas worldwide. Given that oil prices had fallen back near where they were prior to the Russian invasion of Ukraine, it's no wonder oil and gas prices have found their footing.

Additionally, Goldman Sachs analysts maintained their bullish longer-term outlook on U.S. oil and gas stocks, despite the recent sell-off from highs, in a note published Monday.

In that note, Diamondback was named one of Goldman's five favorite oil and gas names.  Tighter global supplies, the renewed strategic importance of the U.S. oil industry, as well as the shift toward returns on investment over growth from leading U.S. players all feed into Goldman's optimism.

Now what

Just when you thought oil and gas stocks were headed lower on looming recession fears, they are outperforming today on a down day for most indexes. Ironically, the lower near-term price may help alleviate stress across the economy, since high fuel prices play such a key role in the price of every good.

Thus, if prices don't spike out of control, the U.S. may be able to avoid a recession. If that happens, demand may not fall as much as it would in a bad economic downturn.

So there appears to be a happy medium for oil and gas prices out there that will enable energy stocks to earn profits, while also not pushing the global economy into a downturn. We may be nearing that price today.

As always, given the importance of energy to the overall economy and inflation readings, especially today, investors should try to keep a certain allocation to the energy sector and adjust their portfolio to keep that allocation constant, trimming on increases or adding on declines. This mathematical approach should allow you to keep a cool head in this volatile sector in a volatile economy. As it's showing today, that allocation can act as a helpful hedge when fuel prices spike.