The stock market is ending a remarkable year, with the S&P 500 index returning 17%, as investors see an end to the pandemic in 2021 and corporate earnings rapidly improving.