If there's much going for Caterpillar Inc. (CAT 1.58%) lately, it has been strikingly quiet on the Illinois Tool Works (ITW 0.27%) front. But you wouldn't guess so looking at the two stocks right now: Shares of both industry stalwarts are racing to the top, up double-digit percentages in the past six months and currently trading close to their respective 52-week highs. The stories behind Illinois Tool Works' and Caterpillar's rise, however, have few similarities, which is what makes both stocks so interesting. So, before you decide which stock to buy today, you need to know why they're soaring and which one suits your risk appetite.

Caterpillar: Riding the wave of expectations

Bulls have been chasing Caterpillar for about a year now, encouraged by a recovery in commodity prices and hopes of America's infrastructure gaining priority under Donald Trump's presidency. The funny thing is that the company itself doesn't expect to see any benefits from higher potential infrastructure spending until at least 2018. Management even lowered its guidance for 2017 when it last reported numbers, projecting full-year earnings of only about $2.30 per share on revenue worth $37.5 billion at midpoint. That might impress when you pitch it against its 2016 losses of $0.11 per share, but if you strike out the goodwill impairment and restructuring charges, Caterpillar took in an adjusted earnings per share of $3.42 last year.

Mining trucks

Image source: Getty Images.

None of it matters to Caterpillar bulls, however. To be fair, Caterpillar's prospects are looking brighter after several years of struggle. Manufacturing activity has picked up pace, prices of commodities like iron ore have shot through the roof, and oil prices, though volatile, have bounced back from multiyear lows hit earlier this year. Each of these factors has a strong bearing on the fortunes Caterpillar's three businesses of construction industries, resource industries (mining), and energy and transportation (E&T).

Then there's the surprisingly strong retail machine sales statistics that Caterpillar recently released: It reported an astounding 39% jump in its machine retail sales from the Asia-Pacific region for the three months through February. Sales from every other region, including North America, EAME, and Latin America also declined at a lower clip versus the comparable period last year as well as the three-month rolling period through January. Overall, Caterpillar's total retail sales were down only a percentage point during the period. The last time the company reported single-digit percentage declines was early 2014.

As it turns out, you can't really blame the market for overlooking Caterpillar's own cautious stance or the ongoing IRS probe regarding possible tax fraud. Investors have, after all, waited several years for the company's fortunes to turn around, so even the tiniest positive sign was bound to send shares soaring.

Illinois Tool Works' bull run, on the other hand, is backed more by facts than expectations.

Illinois Tool Works: Delivering where it matters

Much like Caterpillar, Illinois Tool Works' shares, too, have had bulls backing them for a year or so. Unlike Caterpillar, though, the company is growing like gangbusters: Its EPS grew 11% in 2016, operating margin hit a record high of 22.5%, and it is targeting 5%-9% growth in EPS for 2017. Each of its seven businesses -- yes, Illinois Tool Works is a heavily diversified company -- ended 2016 with double-digit operating margins, the lowest being 18.9% for its test and measurement and electronics segment.

A chart showing Iliinois Tool Works' segment-wise operating margins for 2016.

Data source: Illinois Tool Works. Chart by author.

In another contrasting element, while Caterpillar skipped its traditional annual dividend increase last year, Illinois Tool Works bumped up its dividends by 18% in 2016. So while Illinois Tool Works is among the strongest Dividend Aristocrats today, with a more than 50-year history of annual dividend increases, Caterpillar might have just missed the bus to making it to the list.

That's not to say Caterpillar's financials are in a dire state, though. In fact, the company has done a tremendous job of generating free cash flows over the years, and its FCF comfortably covered its dividend payments even in a challenging year like 2016. The only concern is that while Illinois Tool Works' FCF has been fairly stable and is trending upward, Caterpillar's has been volatile and has spiraled downward in recent years.

ITW Free Cash Flow (TTM) Chart

ITW free cash flow (TTM). Data source: YCharts.

Another thing I like about Illinois Tool Works is that management has a clear line of sight. Again, much of it might have to do with the company's diversity, which allows it to offset pockets of weakness with strength elsewhere. Caterpillar's pure cyclical business makes it a wee difficult for management to set out goals for the future. That said, Illinois Tool Works isn't entirely a defensive company and has substantial exposure to cyclical sectors, so I must give credit to its management for its foresight.

Illinois Tool Workk's operational goals exiting 2018

Image source: Illinois Tool Works' Q4 earnings presentation.

Foolish bottom line

Frankly, neither of the two stocks is a value play right now, but if Illinois Tool Works looks cheaper on a price-to-earnings basis, Caterpillar is downright cheap if you look at price to cash flow. 

ITW PE Ratio (TTM) Chart

ITW P/E ratio (TTM). Data source: YCharts.

As tempting as Caterpillar might appear, though, I'd be wary of putting money in a business that relies so heavily on macro factors to grow and is yet commanding a high premium despite the lack of concrete signs of improving end markets. Illinois Tool Works' premium is pretty much justified going by its operational performance, and I see more upside potential in the stock than downside risk -- something I can't really say for Caterpillar.