Stock markets ended 2012 with a bang, with shares climbing on reports that the Senate had reached an agreement to avert the fiscal cliff. The Dow Jones Industrial Average broke a five-day losing streak to climb 166 points on the last trading day of the year, its best-ever performance on New Year's Eve. The larger S&P 500 posted its biggest final-day gain since 1974. And overall, 2012 was a good year for stocks: The Dow was up 7.3 percent for 2012, its fourth straight year of gains; the S&P 500 climbed 13 percent, its best year since 2009; and the tech-heavy Nasdaq index surged 16 percent.

What's behind the stock market's rise? For one thing, the markets are still recovering from their nadirs in 2009, when the country was grappling with the financial crisis. The Dow is up 100.15 percent since then; the S&P 500, 111 percent; and the Nasdaq, 138 percent.

In terms of government policy, investors were heartened by the progress Congress is making on the fiscal cliff. "As you remove little bits of uncertainty, investors can then once again return to focusing on the fundamentals," Joseph Tanious, a strategist at J.P. Morgan Funds, tells The Associated Press. In addition, markets were boosted in 2012 by the Federal Reserve's decision to continue supporting the economy with loose monetary policies, as well as the European Union finally getting its arms around a long-running debt crisis.

A look at individual companies offers a more nuanced picture of the economy. The Dow's best performers were Home Depot (up 48.5 percent) and Bank of America (up 107.3 percent). "Home Depot’s big gains came in a comeback year for the U.S. housing market," says Steve Schaefer at Forbes. Bank of America continues its recovery from the housing market crash, and, since it's still trading at a lowly $12 per share, some investors think it stands to make further gains in 2013. J.P. Morgan Chase also had a solid year (despite a scandal stemming from a massive trading loss), while Disney benefited from its recent acquisition of the Star Wars franchise from George Lucas.

Caterpillar and McDonald's ended the year in the red, largely due to slowing growth in China. The Dow's worst performer was Hewlett-Packard, whose stock price dove 44 percent over concerns that the world's largest PC maker has fallen perilously behind in the new world of tablets and smartphones. HP also suffered an embarrassing setback when it wrote down $8.8 billion from its acquisition of Autonomy, due to improper accounting.

Apple had another banner year, climbing 31 percent in 2012. However, some investors were disappointed with the results, largely because Apple was up 73 percent for the year in September. "It felt like the most disappointing 31 percent jump ever," says Jay Yarow at Business Insider.