Why do stocks sometimes rise when the economy is in the ditch? They're not as tightly coupled as you might think.
First, GDP is a trailing measurement whereas stock indices are a speculative leading indicator, with all the uncertainty that implies.
Secondly, the interests of the general US economy and those of largish corporations are imperfectly aligned at best, with a number of factors impacting each unequally and at times in opposite directions.
This comes from an excellent discussion on Quora: How does QE translate to all-time highs of equity indices?