Stocks rose on the last day of 2018 as investors try to end the year on a high note following the worst year for equities since 2008.

All three major indices gained, with the Dow Jones Industrial Average up 1% at 23,295.87, the S&P 500 up 0.82% to 2506.04 and the Nasdaq gaining 0.84% to 6639.59 as of 1:30 p.m. ET.

Growing optimism in U.S.-China trade talks fueled the gains. President Donald Trump said he had a "very good call" about trade with Chinese President Xi Jinping over the weekend and said they made "big progress" to reach an agreement on the issue. 

Despite the Monday rally, U.S. stock indices will see their first annual loss since the 2008 financial crisis once markets close at 4 p.m. They are also on track to have the worst December performance since 1931, during the Great Depression.

The S&P 500 is on track for a loss of 6.5% in 2018, or 5.2% with dividends included. The S&P 500 posted very small losses in 2011 and 2015, but gained in both years with dividends included, according to the Associated Press.

The Dow Jones is down 8.3% for the year and down 14% since an all-time high of 26,828.39 reached on Oct. 3.

The tech-heavy Nasdaq is down 5.9% for the year. After reaching an all-time high of 8,133.30 in August, the stock is down more than 18%.

FAANG stocks led markets to all-time highs for the first half of the year, while corporate tax cuts from tax reform boosted corporate profits and unleashed a wave of stock buybacks. However, emerging markets struggled through the year due to a higher dollar as the Fed continued raising rates and U.S. stock markets seemed to be insulated from what was happening throughout the world.

Crude oil scared the markets in the second half of 2018, plunging 25% on concerns of excess supply. OPEC, the oil cartel made of 15 oil-exporting nations that regulate the price of Brent crude through production constraints and incentives, is losing power. The cartel failed to control production constraints and Qatar announced it would leave the cartel earlier this month, leaving oil prices vulnerable to the supply glut.

By the third quarter, a 10-year treasury yield above 3%, fear of a global slowdown due to a high dollar and trade tariffs and a fizzle of the tax law sent stocks tumbling in October. That started a highly volatile second-half of the year, culminating with all three major indexes entering a bear market, when losses are 20% or more.

The fourth week of December was the first positive week of the month after the Dow saw its worst Christmas Eve performance ever, falling 653 points, or 2.9%, then having its highest point gain in its history the next day, rising 1,086.25 points.

Heading into 2019, investors are concerned about the Fed raising rates too much too soon. The Fed is expected to raise rates twice in 2019. Companies in 2019 won't have 2018's tax reform boost and investors are expecting slower growth. Lower oil prices and China's struggling stock market have investors expecting a global slowdown in 2019.