Editor’s Note: Mark Zandi is chief economist of Moody’s Analytics. The opinions expressed in this commentary are his own.

Consumer inflation figures for May will be out Friday, and the report is sure to be disquieting. Gasoline prices are seemingly breaking new record highs on almost a daily basis, food costs are soaring, and housing is becoming increasingly unaffordable.

The persistence of high inflation in the US has been a surprise, certainly to me. But so too has been the ongoing pandemic — the vaccines that became available more than a year ago still have not ended it. And a Russian invasion was barely on the radar screen when troops crossed the Ukraine border earlier this year.

Indeed, the quickly rising prices are due mostly to badly scrambled global supplies resulting from the ongoing pandemic and war in Ukraine, and much will depend on how these two shocks play out. Yet while predicting the course of events from here is intrepid, there are reasons to be optimistic. I’m confident that inflation will be meaningfully lower by this time next year and back to something we will feel comfortable with not too long thereafter.

To be sure, the pandemic continues to weigh on the global economy. China, a major part of many supply chains, shut down big parts of the economy as it has grappled with the Omicron variant. It is tough to resolve supply chain bottlenecks when the biggest link has been all but broken.

And in May, a still consequential 1.8 million Americans said that they were unable to work due to their employer closing down or losing business because of the pandemic. Meanwhile, businesses continue to struggle with labor shortages and must jack up pay to find and keep workers, adding to their costs, which they pass along in higher prices to their customers.

Russia’s invasion of Ukraine has further disrupted global supplies of oil, agricultural products and other commodities, causing prices to spike. US gasoline prices are headed to over $5 per gallon, and diesel prices, a big contributor to food prices — as much of what we pay for in the grocery store is the cost of getting the product from farm to store shelf — have risen even more.

Nonetheless, the pandemic appears to be winding down. There surely will be more waves of the virus, but since the pandemic hit, each wave has been less disruptive to the economy than the one that preceded it. The virus is becoming less virulent, our vaccines and therapies more effective, and our economy’s ability to manage around the virus is improving.

Further, the worst of the economic fallout from Russia’s aggression also appears at hand. Oil prices have pushed higher again, this time on the European Union’s decision to partially ban Russian oil. However, any country that is going to sanction Russian oil has likely now done so, and other global oil producers have strong economic incentives to produce more, which they have announced they’d do. Oil prices, and thus gasoline prices, should decline later this year.

It is also encouraging that, for the most part, high inflation is not about outsized demand. Spending on goods — home improvement and consumer electronics, for example — is up strongly since the pandemic hit and we sheltered in place. But spending on services — think travel and elective surgery — has been diminished. However, the net of this is that consumers are spending about as much today as they would have if not for the pandemic.

This consumer spending is testament to the massive support that the Federal Reserve and lawmakers provided to the economy. Without the record low interest rates and trillions in aid from the federal government, the economy would be much diminished from where it is today. Uncomfortably low inflation would still be the problem, as it had been in the decade leading up to the pandemic.

My optimism does depend on the Federal Reserve getting monetary policy roughly right. That means raising interest rates fast enough and high enough to slow down the strongly growing economy and contain inflation expectations, but not too fast and high to push us into recession. This will require some deft policymaking, but so far so good.

The Biden administration and Congress should agree on legislation that helps ease inflationary pressures, whether it’s reducing prescription drug prices or increasing tax incentives to spur the construction of more affordable housing. Unfortunately, legislation seems a big political stretch in the leadup to the midterm elections.

But legislation isn’t necessary for my optimistic inflation outlook to come to pass. Now all we need is a bit of good fortune and for the pandemic and Russia’s invasion of Ukraine to take a turn for the better.