The Chase Tower in downtown Dallas, Texas. Image source: Wikimedia Commons.

It was a good year for shareholders of JPMorgan Chase (NYSE:JPM). The nation's biggest bank by assets saw its shares gain 31% in 2016, outpacing both the S&P 500 and the KBW Bank Index, which tracks two dozen blue-chip bank stocks.

JPM Chart

JPM data by YCharts.

A rough start to the year

If you look at a chart of JPMorgan Chase's stock price throughout 2016, there are a number of things that stick out. The first is that the year got off to a rough start.

When oil prices dipped below $30 a barrel in January, analysts and investors became concerned that banks would have to write off billions of dollars' worth of loans to energy companies. This made sense given that low oil and gas prices made it difficult for energy companies to service their debts.

For its part, JPMorgan Chase CFO Marianne Lake estimated at the beginning of the year that the bank would have to set aside $750 million in additional loan-loss reserves if oil prices stayed below $30 a barrel for 18 months. That's a lot of money, though it's hardly fatal for a bank like JPMorgan Chase that earns $6 billion or more a quarter.

Nevertheless, JPMorgan Chase's stock suffered along with the rest of the industry to start out the year. Before shares of the New York-based bank mounted a comeback in February, they were 20% lower than where they began the year.

Brexit shocks bank stocks

The second shock came in June, when voters in the United Kingdom voted to separate from the European Union, known as Brexit. This hit JPMorgan Chase hard, causing its shares to lose 10% of their value between the beginning and middle of June.

Investors and analysts were worried about a number of issues. First, it was feared that the uncertainty brought about by the vote would weigh on business investment, which is often financed by bank loans. It would also give the Federal Reserve another reason to delay raising interest rates, thereby prolonging the bank industry's pain under the historically low interest rates they've faced since the financial crisis.

There was concern as well that universal banks such as JPMorgan Chase, with sizable European operations based in London, would have to spend money relocating a portion of their staff and facilities to the continent. JPMorgan Chase CEO Jamie Dimon said as much earlier in the year.

And for a bank with a large trading operation, it seemed at the time that the added uncertainty as a result of the vote could cause institutional investors to stay on the sidelines. This would deprive JPMorgan Chase of commissions it earns from serving as a market maker in the equity and fixed-income markets.

The point being, the vote in the United Kingdom seemed to have implications for both revenue and expenses, depressing the former while raising the latter.

Post-election rally

But even though these were significant shocks, they were more than offset by the trajectory of bank stocks following the presidential election in November. If you look back at the chart of JPMorgan Chase's stock price, the election is what sparked the steep climb on the right-hand side of the chart.

The main source of optimism for bank stocks stems from the incoming administration's promise to roll back regulations in the bank industry -- Donald Trump went so far on the campaign trail to say that he wanted to "dismantle" the 2010 Dodd-Frank Act.

If the White House and Congress are able to accomplish this, it could enable JPMorgan Chase to increase the size of its loan portfolio, generate more income from its trading units, operate with more leverage, and cut compliance costs.

The president-elect has also outlined a number of fiscal policies designed to accelerate economic growth, including tax cuts and government-financed infrastructure projects. If these have the desired effect, they could boost inflation, which, in turn, would incentivize the Federal Reserve to raise rates more aggressively.

Finally, the icing on the cake came in December, when the Fed did in fact boost the fed funds rate, albeit by only 25 basis points. This helped to consolidate the recent gains in bank stocks, including shares of JPMorgan Chase, as banks make more money when interest rates rise.

In sum, while it's easy to look at JPMorgan Chase's 31% gain this year and think it was smooth sailing for banks, the multiple bumps along the way made such an outcome far from inevitable at many points throughout 2016.