Historical data shows the stock market could be in for more gains given its strong run thus far. The fact that it’s an election year also bodes well. The S & P 500 has climbed more than 15% year to date, as the artificial intelligence craze has driven megacap technology names higher and investors hold on to hope that the Federal Reserve will start cutting interest rates later this year. With the exception of real estate, all sectors that comprise the index are tracking to end the first half in the green. History offers reason for optimism looking forward, according to data analyzed by CFRA Research’s Sam Stovall. Anytime the first half of the year was positive for the S & P 500 between 1945 and 2023, the second half brought an average rise of 5.3%. The broad index was higher in the second half in more than 3 out of every 4 years that it ended the first 6 months in the green. Even better: the fact that the S & P 500 has performed so well this year makes the outlook sweeter. In years with the S & P 500 climbing more than 10% in the first 6 months, it jumped 7.9% in the typical second half. The index was positive in the latter half in more than 4 out of every 5 of these years. Presidential election years also typically bring returns in the second half of the year, according to Stovall’s data. Looking at all election years since World War II, the S & P 500 added 0.9% and 2.4% in the average third and fourth quarters, respectively. For the entire second half, the S & P 500 has climbed 3.5% on average. Things look even more rosy for presidential election years with a winning first half. In these instances, the S & P 500 adds 1% in the third quarter and 3.8% in the fourth quarter on average. That comes out to a rally of 4.9% for the half in total. To be sure, some investors are wondering how much farther the S & P 500 can run up after notching all-time highs this year. The median market strategist’s forecast implies the index will end 2024 less than 1% higher than where it closed Thursday, according to CNBC Pro’s exclusive survey .