With the Nasdaq Composite Index up 36% in 2023, investors are excited that we are in a raging bull market. In fact, the broad index is slowly approaching its all-time high, as investor sentiment remains positive.

But this optimism doesn't mean that investors should be resting on their laurels. In my opinion, it's always a good idea to think about downside protection, looking at where to invest should the markets go south.

If you have $10,000 ready to invest in a bear market, it's a smart idea to consider buying shares of O'Reilly Automotive (ORLY -0.97%). This allocation should be in the context of a larger, diversified portfolio.

Posting strong growth

While many businesses are hurt by the current economy, O'Reilly keeps humming along. In the third quarter (ended Sept. 30), revenue and same-store sales (or comps) increased 11% and 8.7%, respectively, compared to a year ago. And so far this year, the company has opened 140 net new stores.

The bottom line is also getting a boost. Diluted earnings per share jumped 17% in the latest quarter. This figure was helped by ongoing share buybacks, something O'Reilly is known for. Because the business generates copious amounts of free cash flow, the leadership team is focused on constantly repurchasing stock. In the past 12 months, the outstanding share count has been reduced by 5%.

For the full year of 2023, management expects comps to increase by 7% to 8%. More impressively, it predicts a gross margin of 51% and an operating margin of 20%, both at the midpoint of the range of expectations. These are all fantastic metrics for investors to see.

Recession-resilient

Besides strong business momentum, a bear market is another smart reason to buy shares of O'Reilly. In such a situation, the broader economy might also take a hit, and investors would want to position their portfolios properly.

O'Reilly is a recession-insulated company. By selling automotive aftermarket parts through its network of nationwide stores, the business is essentially a mission-critical partner for its do-it-yourself and professional customers. Having a functioning car is something people can't live without.

This means that in a robust economy, when unemployment is low and consumer confidence is high, O'Reilly will experience strong demand because people will drive more, increasing the wear and tear on their vehicles. The result is a need for supplies to maintain their cars.

On the other hand, in recessionary periods, demand will also be durable. In this scenario, consumers will hesitate to buy new cars in favor of extending the useful lives of their existing vehicles. Here again, O'Reilly comes to the rescue.

In a bear market, investors should desire to own safe, steady, and predictable businesses that provide peace of mind. There's no doubt that O'Reilly fits this description.

What about the valuation?

In the trailing 5- and 10-year periods, O'Reilly shares have climbed 176% and 690%, respectively. These gains trounce the broad indexes by incredibly wide margins, and consistently strong fundamental performance is the key that has helped reward shareholders.

Consequently, the stock isn't exactly a screaming bargain at the moment, at a trailing price-to-earnings multiple of 26. However, if a bear market does end up happening, there's a high likelihood that O'Reilly's valuation will take a hit. And this would present investors with a wonderful opportunity to buy a great business.

If you don't have the patience to wait for a better entry price, it might also be a good idea to dollar-cost average into the stock. This means buying a small amount of shares every month, for example, to take advantage of different prices.