This year has been a tough one for investors, with the S&P 500 index down 20% through June -- officially putting us in a bear market. Seeing your investment portfolio lose money is deeply unsettling. However, as uncomfortable as bear markets are, they are a necessary part of healthy markets. At some point, the market selling will come to an end.

Trying to time the end of a bear market is hard, so it's important to maintain a long-term investment mindset and focus on buying high-quality companies with durable competitive advantages. With that said, here are three excellent companies you can buy today that can continue to outperform long after the bear market ends.

A person reviews stock information on multiple monitors in an office setting.

Image source: Getty Images.

1. FactSet Research Systems

FactSet Research Systems (FDS -4.22%) provides investors with financial data and analytics to research investments, build portfolios, and manage risk. The company brings in cash through a subscription-based business model with products like portfolio analytics and market data.

2021 was a record year for the company, which shows no signs of slowing down despite volatile market conditions. In its latest earnings report (for the quarter ended May 31), the company said revenue totaled $489 million, a 22% increase from last year. Operating expenses increased faster than revenue, causing net income to drop 26% year over year. However, half of the increase in expenses was due to it vacating a leased office space as it transitioned to a hybrid work environment.  

What makes FactSet impressive is its consistent growth; the company has increased revenue for 41 consecutive years. Over the last decade, revenue has grown at an 8% compound annual growth rate (CAGR), and earnings per share (EPS) has grown at a 10.6% CAGR.

The company is on solid footing because of its vast data sets, which it has expanded into private markets, alternative markets, and environmental, social, and governance (ESG) data. Last year it acquired Cobalt Software for $50 million, a company that provides portfolio monitoring for private industry.  

FactSet does an excellent job of providing data solutions to investors through a subscription-based model, giving it a stable source of revenue and solid profit margins -- and is an excellent stock to buy in this bear market.

2. MSCI

MSCI (MSCI -13.43%) provides investors with tools that help them construct portfolios, manage risk, develop ESG solutions, and manage index products. It has 6,300 clients across 95 countries, including pension funds, central banks, asset managers, and other financial professionals.

The company is perhaps best known for its index products, which comprise 61% of its total revenue. Its largest client is BlackRock, accounting for 12.7% of revenue, and nearly all of this revenue comes from BlackRock's ETFs based on its indexes.  

MSCI recently put up its best first quarter ever, as operating revenue increased 17% year over year while EPS increased 18%. Impressively, its index product saw its 33rd consecutive quarter of double-digital year-over-year subscription growth.  

MSCI has been a huge winner in the push toward passive investing, and it currently updates 267,000 indexes daily. Over the last decade, MSCI's revenue has grown at an 8.6% CAGR, and its free cash flow has grown at a 10.8% CAGR with solid profit margins. MSCI is a vital player in developing index products, and its earnings show it -- making this another stellar stock to buy in this bear market and hold for the long haul.

3. S&P Global

When companies look to issue debt, credit rating agencies like S&P Global (SPGI -0.88%) analyze the business's risks and assign a rating that ultimately determines how much interest the company will pay to lenders.

S&P Global is an integral part of debt markets, and regulations cause high barriers to entry, giving S&P Global a considerable advantage. That's why S&P Global and Moody's have roughly 40% market share each. Thanks to high barriers to entry and an asset-light business model, S&P Global's gross profit margins have averaged nearly 70% over the last decade.

The company makes about 50% of its revenue from its credit rating business, which has slowed down considerably this year as debt issuance in the U.S. fell by 35%. However, S&P Global's other businesses, like research, analytics, and index products, grew 51% in the first quarter compared with last year.

S&P Global is another stellar business that has rewarded investors with 49 years of consecutive dividend increases -- making it one year away from exclusive Dividend King status. Given its built-in advantages and strong cash flow generation, S&P Global is another company you'll want to buy on sale before this bear market ends.