A few weeks remain on the calendar for this year, but 2018 is shaping up to be a banner year for big pharma stocks. At least, that's the case for most of them.

Of the 10 largest pharma stocks by market cap, eight of them are beating the S&P 500 index so far in 2018. And three big pharma stocks are enjoying such a great year that they're up by more than 28% and recently hit 52-week highs: Merck (MRK -0.94%), Eli Lilly (LLY 1.53%), and Pfizer (PFE 0.91%). Here's why these three stocks have performed so well and whether they're still smart picks to buy.

Man watching three line charts going up with skyscrapers in background.

Image source: Getty Images.

1. Merck

Merck ranks as the biggest year-to-date winner among big pharma stocks with a gain of 40%. You might not have thought that the drugmaker would have such a great year in the first quarter, though, with Merck's share price sinking at that time. But things turned around dramatically in April.

It's easy to identify the key driver behind Merck's big comeback: Keytruda. The company reported a boatload of good news for the drug in April, including positive clinical results in treating non-small cell lung cancer (NSCLC) as a monotherapy and in combination with chemotherapy and in treating advanced melanoma.

The good news didn't stop there. More great results for Keytruda kept on coming throughout the following months for treatments of multiple types of cancer. It's not surprising that Keytruda is projected to become the No. 2 best-selling drug in the world by 2024 with annual sales of $12.7 billion.

2. Lilly

Lilly is running neck and neck with Merck so far in 2018, with Lilly's shares up nearly 40%. But nearly all of the company's gains have come in the second half of the year.

The big spark came in July with Lilly reporting solid Q2 results and boosting its full-year 2018 revenue and earnings guidance. Lilly also announced plans to spin off its animal health unit Elanco into a separate publicly traded entity. The drugmaker filed for an initial public offering (IPO) of Elanco in early August.

Lilly kept up its winning ways into the fall season. It posted solid results again in the third quarter. In addition, the pharma company announced positive results from a couple of phase 3 clinical studies of Taltz in treating ankylosing spondylitis as well as great results from a phase 3 study of pain drug tanezumab and a cardiovascular outcomes study for diabetes drug Trulicity.

3. Pfizer

The trajectory for Pfizer in 2018 was similar to that of Lilly. All of the stock's 27% year-to-date gain has come since July.

There were a couple of big developments for Pfizer in July. First, the company announced that it planned to reorganize into three business segments: innovative medicines, established medicines, and consumer healthcare. Pfizer is still evaluating the possibility of selling or spinning off its consumer healthcare business. Second, the drugmaker beat Wall Street estimates for revenue and earnings in its Q2 results.

Although Pfizer subsequently reported mixed results in the third quarter, the company enjoyed a string of other good news that kept its momentum from suffering too much. In November, Pfizer received FDA approvals for Lorbrena as a second-line treatment for NSCLC and for Daurismo in treating acute myeloid leukemia (AML). The company also won six-month pediatric exclusivity for Lyrica, which pushes the period of exclusivity for the drug out to June 30, 2019.

Are they buys?

The chief issue that can arise for stocks that have been on a roll like Merck, Lilly, and Pfizer is that their valuations can get ahead of their growth prospects. Is that the case for these three big pharma stocks?

Lilly's shares now trade at more than 20 times expected earnings. That's pretty pricey for a drugmaker that still faces headwinds from declining sales of older drugs like Cialis and Humalog. Merck's forward earnings multiple of below 17 looks better, although the company also has some older products that are weighing down growth. Pfizer is the cheapest of the three, with shares trading at 15 times expected earnings. But the drugmaker has its own challenges with legacy drugs.

My view is that all three of these big pharma stocks could continue to be winners over the long run. However, I'm concerned that Merck's reliance on Keytruda combined with its higher valuation thanks to the big gains this year could make it less likely to keep climbing over the near term. Lilly's share price is also a little too high, in my opinion, to make it a compelling buy right now despite the considerable promise for some of its newer drugs.

I do like Pfizer, though. The drugmaker should move past its biggest issues over the next couple of years. And Pfizer claims its best pipeline in years. It also doesn't hurt that Pfizer has the highest dividend yield of these three pharma stocks. Next year might not be as great for Pfizer as 2018 has been, but I think the long-term prospects for this big pharma stock look bright.