The stars aligned for the defense sector in 2017, and shareholders of Raytheon (RTN) were among the top beneficiaries. Raytheon shares are up 31.5% year to date as of mid-December, one of the best-performing defense primes and well above gains made by the S&P 500.

Raytheon is surging because it, perhaps more than any other company, is positioned to capitalize on a growing Pentagon budget and the threats the United States and its allies are facing. Here's a look back at what went right for Raytheon in 2017, and a look forward to what investors can expect next year.

A Patriot missile blasting off over a deserted field

A Raytheon Patriot missile launched during testing. Image source: Raytheon.

The Trump bump

The defense rally began before New Year's, sparked by Donald Trump's presidential victory. Trump on the campaign trail called for a buildup at the Pentagon, promising additional funds to fight terrorism and respond to foreign threats, and his initial budget proposals have followed through on the promise for increased funding. The November elections also left Republicans in control of both the White House and Congress, offering hope that years of budget battles that led to the Budget Control Act of 2011 and a freeze in spending levels might finally be in the past.

Raytheon has particular attributes that investors find appealing. The company's core businesses include missiles and missile defense, sensors, and secure communications, areas of particular interest at the Pentagon. Over the last decade-plus, the company's Tomahawk missiles have been deployed faster than the Department of Defense can replenish them, a situation the Pentagon will address with a request for $3.5 billion in preferred munitions contained in its fiscal 2018 budget.

RTN Chart

Raytheon share price, year to date. data by YCharts.

The company is also benefiting from efforts earlier in the decade to diversify the pipeline, moving into new cyber defense and related markets and expanding its areas of expertise so it can bid on multiple different contract awards and lessen its reliance on the multibillion-dollar major contracts that once meant the difference between a good year and a bad one for a contractor. As of July, Raytheon said it had about a dozen potential opportunities in the range of $200 million and $500 million in revenue going into the second half of the year.

Global business

Stung by budget battles in Washington, U.S. contractors are increasingly looking overseas to diversify their revenue. Raytheon so far has done better than anyone. About one-third of Raytheon sales and bookings in recent quarters have come from international customers, beating out rivals including Lockheed Martin and Northrop Grumman.

Raytheon's Patriot air defense missile system is deployed by about a dozen U.S. allies, with new customers continuing to come online. The company also plays an important subcontractor role on the Lockheed Martin-built Terminal High Altitude Area Defense (THAAD) missile system that will be the first line of defense for South Korea and Guam should North Korea launch a missile strike.

Can it continue?

Raytheon's board in November provided some ammunition for a continued rally, authorizing the repurchase of $2 billion in additional shares on top of the $900 million available under the company's 2015 repurchase program. Investors are also expecting a dividend hike in March, which would mark the 14th consecutive year Raytheon has raised its payout.

Given investor enthusiasm for defense, and the seemingly endless headlines concerning global conflicts that reinforce that enthusiasm, it's unwise to assume Raytheon's surge will not continue. But the shares, after a great 2017 and up more than 200% over the last five years, seem nearly fully valued. Wall Street is getting similar vibes: The shares have come under pressure this month after a handful of valuation-related downgrades.

Raytheon's a well-run company poised for long-term success. But odds are, the shares will not repeat the gains enjoyed in 2017 next year.