The stock market is generally going like gangbusters, reaching all-time highs. Stocks like Nvidia and Microsoft are forging the path. But with price-to-earnings (P/E) ratios of 73 and 39, respectively, value investors are looking beyond these tech titans.

The intelligent investor is a realist who sells to optimists and buys from pessimists.

-Famed investor Benjamin Graham.

What Graham is saying in a nutshell is buy low, sell high. We all know this, but it's tough to pull the trigger when a stock is plunging. However, this can be the best time to buy quality companies for the long term. Ulta Beauty (ULTA -0.15%) offers one of these opportunities right now.

What happened?

Ulta stock plummeted after fiscal 2023 fourth-quarter earnings and dipped again after the following report, as shown below.

ULTA Chart

ULTA data by YCharts.

The reason: Consumer spending on higher-end products is slowing. This is a predictable result of the Federal Reserve's interest rate policy, which keeps rates high to rein in inflation. This has been largely successful, and many expect the Fed to loosen monetary policy soon, accelerating economic growth and consumer spending.

Ulta's first-quarter comparable-store sales grew 1.6% this year, well below the 9.3% growth in the first quarter last year. Even worse, the company lowered its fiscal 2024 revenue guidance from $11.8 billion to $11.6 billion. But the news isn't all bad.

Ulta is on solid financial footing. The company is profitable, posting $400 million in operating income and $6.47 diluted earnings per share (EPS) in the first quarter.

It is also buying back stock. The lower price will allow Ulta to take more shares off the table for the same investment. And $1.8 billion (10% of its current market cap) remains on its current share repurchase plan. This could significantly benefit investors over the long haul.

Another reason for optimism is Ulta's loyal customer base. As shown below, 95% of sales come from its rewards-program members.

Ulta reward membership sales

Source: Ulta

Membership is steadily rising, except for the 2020 pandemic year. Having a consistent, loyal customer base is terrific for a retailer.

Is Ulta stock a buy now?

The stock currently trades near historic lows, with the price-to-earnings (P/E) ratio just under 15. As shown below, this is well off its 10-year average and the lowest it has been other than at the depth of the March 2020 pandemic crash.

ULTA PE Ratio Chart

ULTA PE ratio data by YCharts.

The company's average P/E for the last three years is over 21, which puts its current valuation more than 40% off its recent average. The stock is priced like a distressed business; however, despite challenging times, it is still viable and profitable.

The ultra-low valuation suggests that the market is extremely pessimistic. Results could indeed get worse before turning around if consumers rein in spending more.

However, investors are getting terrific value over the long term for a very profitable company. I am following Benjamin Graham's advice and picking up shares of Ulta while sentiment is low.