The wildest month in the history of Wall Street ended on Halloween with both scary and thrilling price movements.

October was the worst month for the Standard & Poor’s index of 500 stocks in 21 years — since the 1987 stock market crash.

But the final week was the best week for the market in 34 years.

As befits such a wild month, it was the most volatile in the 80-year history of the S.& P. 500.

The huge gains of the final week were reminiscent of the sharp recoveries from bear market lows in 1974 and 1982. Both of those moves came while the economy was mired in recession, as it almost certainly is now.