The second half of the year is well underway. And while things aren't looking fabulous, they seem to be better than in the first half. For instance, the S&P 500 index rallied about 13% from June 30 through mid-August. It's since retreated, but is still in positive territory. That's after the index's worst first half in 52 years.

At the same time, companies are speaking about brighter days ahead. Some that have been hurt by rising inflation are making progress on dealing with the costs. Amazon (AMZN 3.43%) and Target (TGT 0.18%) are two examples. Is now the moment to buy stocks and bet on recovery, or is it better to wait?

Interest rates and economic growth

Soaring inflation hurt companies' earnings earlier in the year. Since then, central banks have raised interest rates to get inflation under control. That movement isn't over. In fact, the Federal Reserve probably will keep lifting rates, its chairman recently said. At the same time, there's concern higher rates could weigh on economic growth.

So companies and consumers still face challenges. You might immediately think it's best to wait on buying stocks. After all, they could fall more in such an environment.

That's true; it's impossible to time your investments so that you buy at the very lowest and sell at the very highest. But if you invest for the long term, that won't really matter. There's still plenty of opportunity to generate solid returns.

As I mentioned above, some companies that struggled earlier in the year are seeing improvement. Amazon has made progress on controlling costs and better using its fulfillment network.

Target's move to mark down inventory hurt recent earnings, but the company says the worst is behind it. And it predicts its operating margin will improve toward the end of the year.

Defying the downturn

Other companies such as Home Depot (HD 0.94%) and Lululemon Athletica (LULU 1.31%) have actually defied the downturn. Home Depot reported its highest quarterly sales and earnings ever in the second quarter. And Lululemon's quarterly sales climbed in the double digits as shoppers flocked to buy its yoga-inspired apparel.

Here, we have examples of companies that are recovering and companies that have continued strong growth during these difficult times. Now is a good time to get in on these kinds of stories -- they have what it takes to perform well over the long term.

And these players are ready for gains. If they take off in the coming weeks, you'll benefit right away. But if they don't, that's OK. There's still plenty of room for upside in the years to come.

In general, many companies with track records of revenue and profit and fantastic prospects have declined. That means prices are reasonable, even if they aren't at their very lowest. Central banks are making the necessary efforts to rein in inflation. And history tells us that even if the economy slows, it will recover. And so will the stock market.

It's key to look at each individual company, its progress so far during this downturn, its price, and its outlook. If the price today looks reasonable in relation to future revenue prospects, now might be the right moment to hit the "buy" button.

So, you might be wondering: "What happens if I wait?" That's fine, too. There always are opportunities in the stock market, especially if you take a long-term view. But buying now probably will get you some great bargains -- and put you in the perfect position to benefit when the market recovers.