All you need is a working Twitter account to know that President Donald Trump tries to take credit every time the stock market hits a record high.

It's a routine that has played out in 2017 as the S&P 500 has stretched well into the ninth year of a bull market that has brought it back to unprecedented highs.

And Trump was back at it again Wednesday morning, with a series of tweets playing up his role in the stock market's latest ascent to record levels:

So is Trump right?

Not most of the time. While there have been times this year when the so-called Trump trade — or the promise of business-friendly policies — has undoubtedly been responsible for the gains, there have also been long stretches when other factors were driving returns.

To best assess Trump's fluctuating influence on stocks, we've looked at the S&P 500 on a periodic basis and zeroed in on which bullish element was actually most responsible for strength. When tied together, they provide a pretty good idea of how the benchmark has gone from one high to the next over time — and it hasn't always involved the president.

Methodology

At the beginning of each section is a chart showing the performance of an index of stocks tracking highly taxed companies, relative to the S&P 500. The measure is intended to serve as a proxy for the effect of Trump's proposed policies on the benchmark, with the thinking being that a lowering of the corporate tax rate has long been seen as the campaign promise most likely to be passed.

If the high-tax index is outperforming, that implies a high degree of overall confidence in the Trump trade and therefore outsize influence being exerted on the S&P 500. If the gauge is underperforming (in negative territory), that implied a low degree of confidence and minimal influence.

And bear in mind that if the line veers into negative territory (which — spoiler alert — it does), that isn't reflective of the broader stock market — it's just the most actionable part of the Trump trade. The S&P 500 as a standalone entity has repeatedly hit record highs this year.

In the end, hopefully, we'll have given you enough information to conclude for yourself whether Trump has, in fact, been as indispensable to the stock rally as he claims to be.