Investors will not be sad to put the first half of the year behind them, as the market has been absolutely crushed this year -- the S&P 500 is down more than 21% year to date and in bear market territory. High inflation, rising interest rates, Ukraine, and the possibility of a recession have put investors on edge and had them repositioning their portfolios and heading for the sidelines.

Still, there have been some stocks that have not only been able to beat the market handily through the first six months of the year but also stay in the green. Here are three in particular.

1. Coca-Cola

The large and historic beverage company Coca-Cola (KO 0.15%) is up more than 6% this year. As one of the most well-known brands in the world, Coca-Cola is a stock that investors frequently pour into when they start to sniff inflation or a recession, largely because of the company's strong brand power, which allows it to pass on higher costs associated with running its business to customers without too much pushback.

In recent years, Coca-Cola's CEO James Quincy has focused the company more on a franchising model and being less of a bottling business, putting more emphasis on branding and having a strong beverage portfolio. This has helped contribute to faster revenue growth in recent years.

Trading at more than 25 times forward earnings, Coca-Cola is not exactly cheap but has a solid dividend yield of roughly 2.75%, providing a nice source of passive income. It's not my favorite stock considering the current valuation, but as a defensive consumer stock, the company should continue to hold up and perform well in the uncertain environment.

2. Johnson & Johnson

The pharmaceutical giant Johnson & Johnson (JNJ 0.29%) tends to attract investors during difficult market conditions because of its rock-solid balance sheet and ability to drive profits even in the toughest of times. As a result, the stock is up nearly 3.5% this year. The company has not only an extremely strong pharma division but also a thriving medtech unit and a consumer health division, which will soon be spun off.

In the first quarter of 2022, the company generated roughly $3.4 billion of free cash flow and had $30 billion of cash and marketable securities. Johnson & Johnson has also done a good job of reducing net debt in recent years.

JNJ Net Financial Debt (Quarterly) Chart.

JNJ Net Financial Debt (Quarterly) data by YCharts.

Johnson & Johnson is one of just two publicly traded companies that has been assigned a AAA credit rating, meaning the rating agencies have the utmost faith in the company to repay its debt. At one point, Johnson & Johnson had a higher credit rating than the U.S. government. 

3. M&T Bank

Unlike most financials and banks this year, M&T Bank (MTB 0.81%), a roughly $200 billion asset bank based in Buffalo, has also managed to stay barely in the green this year. Now, part of this could simply be because M&T recovered from the pandemic at a slower pace than a lot of other banks. M&T had a lot of business in places like New York City that got hit very hard at the beginning of the pandemic and took a bit longer to recover.

But also, this year, M&T Bank completed its large acquisition of the regional bank People's United Financial, which will give it a very dense presence in the Northeast, making it one of the major players in the region.

The bank is also a huge beneficiary of rising interest rates, which have climbed much more than many might have guessed at the beginning of the year. At the end of the first quarter, the bank disclosed that a 2% increase in the federal funds rate would result in more than $421 million in additional income from loans, securities, and cash over the next year, which equates to 11% of the bank's total net interest income made in all of 2021.