Depending on your perspective, we're either in a stock market rally or a wider downturn today. The S&P 500 is up 18% so far in 2023 but is lower by 5% since early 2022.

Zooming into certain sectors can reveal more aggressive discounts, too. While many growth stocks are soaring this year, retailers and some dividend payers are trailing the market in 2023. That's created some compelling buy opportunities for investors willing to stomach some short-term volatility on the way toward a richer portfolio in several years.

Let's take a look at a few especially attractive stocks to buy when indexes go south.

1. Costco

Costco Wholesale (COST 1.01%) stock is rarely available at a discount. That's true this year, too, as shares are up 30%, trouncing the wider market and easily surpassing retailing peers like Walmart and Target.

Several key factors support the warehouse retailer's premium over those other national chains. Costco gets most of its earnings from subscription fees, for one, which makes its profit highly stable through the ups and downs of the economic cycle.

Costco has a long track record of winning market share, as well. It's enjoying rising customer traffic in 2023, while Target has taken a step backward in this regard. A record 91% of members are renewing their memberships, too, indicating plenty of customer loyalty.

Shares are priced at a premium today of 1 times annual sales. You can own Walmart for 0.7 times sales or Target for 0.6 times sales. Keep Costco on your watch list, though, as a better value might be available during the next stock-market decline.

2. Lululemon

Lululemon Athletica's (LULU 1.31%) valuation is a stretch for most investors today. The athleisure-apparel specialist has jumped over 30% in 2023 and is approaching the all-time highs that were set during the rally days of the pandemic.

There are good reasons for that Wall Street enthusiasm. The chain announced in late August that Q2 sales were up a blazing 20% after accounting for currency-exchange rate swings. That growth came from a healthy balance between rising sales in the core U.S. market (up 11%) and booming demand internationally (up 50%).

Investors see much more room for growth in outside markets and as Lululemon pushes into new product categories like outerwear. It's already expanding its influence in additional demographics, like men and kids wear, too.

Lululemon will announce Q3 results by early December. That report might contain some cautious words from the management team as we approach the holiday-shopping sales period. Investors should take any subsequent drop in the stock as a potential discount offering on this high-performing growth stock.

3. Shopify

Shopify (SHOP 1.11%) stock has been on a tear this year. Its business trends are essentially the opposite of what investors saw through late 2022 as sales growth accelerates, even as costs decline. Shopify is winning market share in an expanding e-commerce niche, building out its portfolio of services and booking savings as it exits the costly logistics business.

The result of all these shifts will likely be a quick return to sustainable profitability following the losses that shareholders saw through most of the past year. Management is also prioritizing cash flow for this software-as-a-service business. That trend is highly positive, as well.

SHOP Cash from Operations (TTM) Chart

SHOP Cash from Operations (TTM) data by YCharts.

Shopify stock isn't cheap today as its valuation eclipses even better-diversified software giants like Microsoft. Fears of slowing consumer spending patterns might change that narrative at some point over the next year, though, potentially giving investors a more attractive entry point on this rallying stock.