The first half of 2022 was a challenge for the stock market, as the S&P 500 got off to its worst start in 52 years. Conditions seem to have improved over the last two months, but there are still opportunities to buy great companies at good prices.

The capital markets industry is one area where you can find companies on sale with good long-term prospects. Companies in this industry have seen their earnings take a hit due to market volatility, and now you can buy stocks like Goldman Sachs (GS 0.44%) and Morgan Stanley (MS 0.58%) at dirt cheap prices.

Professionals shake hands in a conference room.

Image source: Getty Images.

1. Goldman Sachs

Goldman Sachs provides investment banking services to its clients and helps them raise money through capital markets through initial public offerings (IPOs) and debt issuance.

The investment bank was a big winner in 2021, posting record revenue thanks to a torrid pace of IPOs and mergers and acquisitions (M&A). According to data from FactSet, 1,073 companies went public through IPOs last year.

This year hasn't been as favorable to the investment bank. That same FactSet data shows that only 92 companies have gone public this year, and Goldman's investment banking unit saw revenue decline by 38% in the first half of the year. 

Companies were nervous about making their public debut, only to see their stock prices plummet. One of the primary causes of market volatility was aggressive interest rate hikes from the Federal Reserve.

This year, the federal funds rate went from about 0.25% to 2.5% in just five months. This had markets nervous that the Fed would continue to increase interest rates aggressively. However, traders anticipate less aggressive rate increases in the back half of this year into next year, which could help markets stabilize. 

Investment banks are cyclical businesses, meaning they trade at a lower valuation because investors don't expect good times to continue forever. At the end of last year, Goldman traded at a price-to-earnings ratio of 6.5, and at one point this year, it traded at its cheapest valuation in 11 years. Now Goldman trades at a P/E ratio of 7.8, but I would argue it's a better value after its business took a hit.

Better stock market performance in July and August has investors optimistic that we may have turned a corner. Goldman Sachs is consistently one of the top investment banks in the world, and with a robust backlog of deals yet to be made, the investment bank could be in an excellent position to capitalize -- making the stock a bargain at its current price.

2. Morgan Stanley

Morgan Stanley also provides investment banking services, but the company has worked hard to diversify its revenue away from investment banking.

In 2009, one year before James Gorman became CEO, 66% of Morgan Stanley's revenue came from investment banking and trading. Today, 50% of the company's revenue comes from these sources. The remainder comes from wealth management and investment management. 

Morgan Stanley's most significant move in recent years was acquiring trading platform E*TRADE and asset manager Eaton Vance for $20 billion in total. These acquisitions make Morgan Stanley's earnings more resilient, helping it avoid some of the cyclical nature of investment banks.

Slow IPO activity dragged Morgan Stanley's earnings down, with investment banking revenue in the first six months falling 46% from last year. However, the firm's other sources of revenue grew, including net interest income and asset management, and its total revenue fell by just 8%.

Morgan Stanley trades at a P/E ratio of 12.1. While this is in line with where the stock has traded historically, I would argue that the stock is cheap because of management's moves to make the business less cyclical.

CEO James Gorman has contended that Morgan Stanley deserves a P/E ratio closer to that of Charles Schwab, which has a P/E ratio of 24.3. Given Morgan Stanley's moves to grow its investment and wealth management businesses, this could be an excellent stock to buy at today's cheap valuation.