Fear about the impact of high inflation and rising interest rates on consumer spending crushed Macy's (M -2.68%) shares in the first few weeks of May. However, Macy's stock recouped nearly all of its losses last week, surging 29%.

A better-than-expected earnings report drove most of this gain, as Macy's stock surged 19% on Thursday alone. But even after the stock's strong performance last week, Macy's still looks like a great buy for long-term investors. Let's take a look.

Another excellent margin performance

During fiscal 2021, Macy's sales recovered to around pre-pandemic levels, following a sharp drop a year earlier. Even more remarkably, adjusted earnings per share (EPS) jumped 82% compared to fiscal 2019, reaching $5.31. Strong demand combined with tight inventory enabled Macy's (and most of its competitors) to cut back on discounting, contributing to the strong margin performance.

These trends continued in the first quarter of 2022. Sales reached $5.35 billion, up 13.6% year over year on a 12.4% comparable sales increase. This still fell a bit short of the retailer's Q1 2019 net sales of $5.5 billion.

However, gross margin reached 39.6%, compared with 38.6% a year earlier and 38.2% in the first quarter of fiscal 2019. Meanwhile, operating costs decreased significantly as a percentage of sales compared with both Q1 2019 and Q1 2021, thanks to cost cuts that Macy's made during the depths of the pandemic.

As a result, adjusted EPS surged to $1.08 from $0.39 a year ago and $0.44 in Q1 2019. This EPS result easily beat guidance of $0.77 to $0.85 and the analyst consensus of $0.82.

Guidance rising

In conjunction with the earnings report, Macy's raised its full-year earnings forecast. The company now anticipates posting adjusted EPS between $4.53 and $4.95 in fiscal 2022, up from its previous guidance range of $4.13 to $4.52.

The exterior of Macy's Manhattan flagship store.

Image source: Macy's.

Interestingly, management attributed the entire guidance increase to two factors: higher expected revenue from its credit card program and the impact of first-quarter share repurchases. In other words, the company hasn't increased its full-year net income projection for the core retail business. Given that Q1 results outperformed management's initial expectations, this implies a modest decrease to the outlook for the core business for the rest of 2022.

That's not too surprising, considering the volatility of the current environment. For example, demand recently shifted abruptly away from active and casual apparel toward dressier clothing, leading to an inventory imbalance that could affect sales and gross margin in the near term. In addition, inflation has already started to pinch discretionary spending in lower income brackets. Looking ahead, rising interest rates could potentially impact luxury spending later this year by reining in asset prices.

For the second quarter, Macy's expects adjusted EPS between $0.84 and $0.94. That would be down from $1.29 last year but far above Macy's Q2 2019 adjusted EPS of $0.28. This guidance reflects the margin impact of needing to clear out excess inventory in the active, casual, and soft home merchandise categories.

Thus, the recent guidance increase doesn't seem like a case of irrational management exuberance. Macy's executives seem well aware of the challenges the company is likely to face this year and are planning appropriately.

The exterior of a Macy's store.

Image source: Macy's.

A better-run company

Even after its recent rally, Macy's stock trades for just five times forward earnings. This indicates that most investors still think the company's recent success is unsustainable.

To be sure, Macy's operates in a cutthroat and volatile industry. Investors can't expect that earnings will grow in a straight line from year to year. But management has created a much more defensible business over the past few years. Macy's has branched out beyond the traditional department store model by acquiring the Bluemercury beauty chain, scaling the Macy's Backstage off-price banner, and investing in a variety of small-format store concepts. Last but not least, the company continues to invest aggressively in its thriving digital business.

This gives Macy's a good chance to grow its sales gradually in the years ahead while maintaining its profit margin near today's level. And the longer Macy's stock trades at depressed levels, the more the company will be able to shrink its share count through its active stock buyback program -- driving EPS higher.

Finally, the company's massive real estate holdings represent a valuable hedge against the risk of deterioration in the company's core business. That makes Macy's stock less risky than it would be otherwise -- and a fantastic bargain at just five times earnings.