President Trump has routinely celebrated, and taken credit for, the stock market’s record-setting climb during his first year in office.

Optimism around the new tax code, as well as a relaxed regulatory climate, has helped drive the Standard & Poor’s 500-stock index’s 21 percent rise since Mr. Trump took office. But that performance falls short of the market’s gains during the first years of the presidencies of Barack Obama and the elder George Bush.

The stock market rose higher in two previous terms.

+40 % S.& P. 500-Stock Index Obama Percentage change in the closes of the first 243 trading days of each president’s term, compared with President Trump’s, through Thursday. +33.7% +30 H.W. Bush +22.8% +20 Trump +21.2% +10 Clinton +7.3% Reagan –10 –8.7% W. Bush –14.7% –20 –30 1 50 100 150 200 243 Number of trading days +40 % S.& P. 500-Stock Index Obama Percentage changes in the closes of the first 243 trading days of each president’s term, compared with President Trump’s, through Friday. +33.7% +30 H.W. Bush +22.8% +20 Trump +21.2% +10 Clinton +7.3% 0 Reagan –10 –8.7% W. Bush –14.7% –20 –30 1 50 100 150 200 243 Number of trading days +40 % S.& P. 500-Stock Index Obama +33.7% Percentage changes in the closes of the first 243 trading days of each president’s term, compared with President Trump’s, through Friday. +30 H.W. Bush +22.8% +20 Trump +21.2% +10 Clinton +7.3% 0 Reagan –8.7% –10 W. Bush –14.7% –20 –30 1 Number of trading days 50 100 150 200 243 +40 % S.& P. 500-Stock Index Obama +33.7% Percentage change in the closes of the first 243 trading days of each president’s term, compared with President Trump’s, through Friday. +30 H.W. Bush +22.8% +20 Trump +21.2% +10 Clinton +7.3% Reagan –10 –8.7% W. Bush –14.7% –20 –30 1 50 100 150 200 243 Number of trading days Source: Thomson Reuters

Mr. Obama took office amid the financial crisis. Stocks were in a freefall and hit bottom nearly two months after his inauguration. Equities then rebounded and finished Mr. Obama’s first year up more than 30 percent.

Mr. Trump, by contrast, became president during one of the longest sustained bull markets in history, and stocks have continued to set record highs during his tenure.

This run is a continuation of one of the longest bull markets ever.

3,000 S.& P. 500-stock index Scale is logarithmic to show comparable percentage changes 2,000 1,000 800 H.W. Bush W. Bush Trump 600 Reagan Clinton Obama 400 200 1981 1989 1993 2001 2009 2017 3,000 2,000 S.& P. 500-stock index Scale is logarithmic to show comparable percentage changes 1,000 800 600 Reagan H.W. Bush Clinton W. Bush Obama Trump 400 200 1981 1989 1993 2001 2009 2017 3,000 2,000 S.& P. 500-stock index Scale is logarithmic to show comparable percentage changes 1,000 800 600 Reagan H.W. Bush Clinton W. Bush Obama Trump 400 200 1981 1989 1993 2001 2009 2017 3,000 S.& P. 500-stock index Scale is logarithmic to show comparable percentage changes 2,000 1,000 800 600 Reagan H.W. Bush Clinton W. Bush Obama Trump 400 200 1981 1989 1993 2001 2009 2017 Source: Thomson Reuters

At more than 3,200 days and counting, this nearly nine-year bull market run trails only the boom from 1987 to 2000. And the momentum suggests the market could climb further upward.

It’s unusual for any president to take credit (or blame) for stock market performance, but in Twitter posts and speeches, Mr. Trump has continually trumpeted the success of the market as a direct result of his actions.