U.S. stocks rose Friday, capping the best week of the year, amid speculation that Spain will request a bailout for its troubled banking sector over the weekend.

The Dow Jones industrial average rose 93 points, or 0.7%, to end at 12,554. The S&P 500 gained 11 points, or 0.8%, to 1,326. The Nasdaq was up by 27 points, or 1%, to 2,858.

The major gauges all posted the largest weekly gain of 2012. The Dow rose 3.6%, the S&P gained 3.5% and the Nasdaq was 3.9% higher for the week.

Overall, the gains were driven by hopes for a coordinated intervention by global central banks to support the economy. On Thursday, China's central bank announced a surprise interest rate cut. The European Central Bank held rates steady at its meeting Wednesday, but many analysts expect the ECB to cut rates next month.

Federal Reserve chairman Ben Bernanke told lawmakers Wednesday that the U.S. central bank stands ready to act, but he offered no hint that additional stimulus measures are imminent. Bernanke's comments came after other Fed officials suggested the bank could extend a policy of reinvesting proceeds from assets on its balance sheet into the Treasury market, known as Operation Twist.

"There's a lot of uncertainty out there," said Bernard Kavanagh, vice president of portfolio management for St. Louis-based broker Stifel Nicolaus. "I'm surprised we didn't see more selling given the strong week we've had."

Investors gravitated towards stocks that are considered defensive, including consumer staples such as Walmart and Coca-Cola.

Spain could formally request bailout funds from the European Union as soon as this weekend, according to Reuters. But EU officials and the Spanish government say a request for help will not be made until a full assessment of the banking sector is complete.

On Thursday, Fitch slashed Spain's credit rating three notches to 'BBB' from 'A.' The ratings agency pointed to the estimated cost of a Spanish bank bailout, which it said is likely to cost between €60 billion and €100 billion. Fitch also said it expects a prolonged recession in Spain that will run throughout 2013.

The yield on 10-year Spanish bonds rose to a high of 6.6% last week, prompting a warning from the nation's Treasury minister that the government is in danger of being priced out of the market. But yields eased this week following a successful bond auction on Thursday and are now around 6.2%.

Joseph Saluzzi, co-head of equity trading at Themis Trading, said traders do not want to bet the market will fall Monday in case EU leaders announce a rescue plan for Spain over the weekend.

"The shorts have been burned time and again," he said. "No one wants to come in here and take a stand."

U.S. stocks ended mixed Thursday, trimming gains from earlier in the day. Investor sentiment remains in the "extreme fear" range on CNNMoney's Fear & Greed index, although it has eased in the last few days.

Economy: The U.S. trade deficit for April came in at $50.1 billion, roughly in line with forecasts of analysts by Briefing.com, and down from the revised $52.6 billion in March.

Wholesale inventories for April rose by 0.6%, after increasing by 0.3% in the month prior.

Companies: Shares of International Game Technology edged up after the gaming firm announced late Thursday that it had received a recommendation for an online gaming license from the Nevada Gaming Control Board.

Shares of Molina Healthcare jumped after the company announced late Thursday that Ohio had endorsed its bid to continue as a health care provider for the state's Medicaid beneficiaries.

Shares of McDonald's and KFC-owner Yum! Brands declined Friday amid growing fears about slowing economic growth in China. McDonald's announced that its sales at stores open at least a year in Asia, the Middle East and Africa regions declined 1.7% in May, with particular weakness in Japan and China.