The S&P 500 has been doing well this year, rising by 20%. But in reality it's just a small minority of stocks that have been responsible for the index's strong recent performance. Many other stocks aren't doing all that well.

Two investments that are down this year but could be poised for better performances in 2024 are PayPal Holdings (PYPL 2.90%) and Dollar Tree (DLTR 0.04%). For investors looking for some deals heading into next year, here's a closer look at why these are two of the best stocks to buy right now.

1. PayPal Holdings

Shares of PayPal have been underperforming -- down 16% so far this year -- and there are valid reasons investors may be feeling down about the business.

Among the concerns are a downturn in the economy, which would affect the outlook for PayPal. The company's growth rate has also been slowing as it faces growing competition -- not just from other payment processors, but buy-now-pay-later services as well.

Plus, with e-commerce marketplace eBay also using its own payment system and no longer relying on PayPal, that has also hindered PayPal's growth.

PYPL Revenue (Quarterly YoY Growth) Chart

PYPL Revenue (Quarterly YoY Growth) data by YCharts

That's the bad news. But the good news is that investors are getting a pretty decent bargain with PayPal's stock right now. Trading at less than 11 times its estimated future earnings, it's relatively cheap -- the average stock on the S&P 500 trades at a multiple of 20.

There is also renewed hope of a soft landing for the economy next year, meaning that a full-blown recession wouldn't take place. That should inspire some investor confidence in such stocks as PayPal, which rely on a strong economy for growth. According to Digital Commerce 360, more than 76% of top retail chains offered PayPal as a payment option in 2021.

Even though PayPal's growth rate may not be in double digits, it can still accelerate in the future. This would be particularly true as economic conditions improve (inflation slows and people have more spending money), as this is still a big player in e-commerce.

PayPal's low valuation, combined with a potentially more favorable outlook on the economy next year, could make this a great stock to own in 2024.

2. Dollar Tree

Another stock that hasn't been doing well this year is Dollar Tree. Down 11%, this is a stock that investors may have expected more from by now. After all, its low-priced items may have given price-conscious shoppers a bit of a reprieve amid inflation.

However, the situation is more complex than that. The company's customers are struggling, and even though Dollar Tree's items are not expensive, many of them may not be essential purchases, either. It has also been battling higher levels of "shrink" (that is, theft or loss of goods) this year, with the issue being so bad that Dollar Tree has contemplated not carrying certain items in its stores.

But there is reason for optimism. The company reported earnings on Nov. 29, and same-store sales for the period ending Oct. 28 topped 3.9%. Same-store sales are a key indicator for retailers like Dollar Tree, as they tell investors how much more shoppers are spending at stores which were open a year ago; it excludes the effect of new store openings and closures. And while earnings were down 21% this past quarter, the company could be in much better shape next year, particularly if inflation continues to cool and demand from low-income shoppers strengthens.

Dollar Tree has also been opening more Dollar Tree Plus locations, which feature products at higher price points and which can appeal to a broader customer base. As of the close of last quarter, the company had 4,500 Dollar Tree Plus stores. That's up from 2,350 locations a year ago. By reaching a broader group of consumers, Dollar Tree may be in better shape to generate more growth as economic conditions improve. And at 18 times its estimated future earnings, this is another decent growth stock to buy right now.