What happened

Union Pacific (UNP -1.15%) shares soared 11% in the month of August, according to data provided by S&P Global Market Intelligence. Investor sentiment, in fact, ran high for the entire transportation sector last month driven by macro factors. Investors in Union Pacific appeared to be doubly optimistic thanks to the railroad's recently released strong performance metrics.

So what

Union Pacific stock's performance mirrored that of the Dow Jones Transportation Average in August -- the index took off in the first week of the month and held up firm throughout to hit multi-week highs, with railroad stocks leading the pack.

While airline stocks jumped as air travel volumes hit five-month highs, the gradual reopening of the economy lifted hopes for rail companies given the significant role they play in moving goods across the United States. Economic data further buoyed investor sentiment, with jobless claims in the first week of August dropping to their weekly lowest since mid-March.

Rail freight cars.

Image source: Getty Images.

With logistics giants like United Parcel Service also confirming a boom in e-commerce deliveries during the pandemic as online shopping surged, investors further anticipated a rise in demand for railroad services.

Expectations were bang on: The Association of American Railroads (AAR) reported a strong recovery in U.S. rail traffic in the past couple of months. August was, in fact, "the best month in terms of intermodal loadings since October 2018 and the fifth best intermodal month ever" for U.S. railroads, according to AAR senior vice president John T. Gray. Intermodal trains carry goods over the last lap of the journey, delivering them directly either to end stores or end consumers via e-commerce merchants.

As one of the largest railroads in North America, Union Pacific is bound to benefit from any uptick in trade, commerce, and freight activity in the economy. During its second-quarter earnings call, Union Pacific management said the rebound in volumes, particularly the restocking of inventory by automotive and intermodal supply chains, was encouraging. In late July, Union Pacific reported strong performance metrics for Q2, with locomotive productivity hitting a quarterly record and freight car velocity, or the average daily miles a car moved, rising 11% year over year as the railroad used fewer locomotives more efficiently.

Now what

Further wild swings in the stock market like the ones we've already witnessed so far this year cannot be ruled out as long as the coronavirus pandemic rages on. But with the economy reopening and hopes of a coronavirus vaccine ringing high, transportation stocks could continue to find favor with investors. Either way, long-term investors in Union Pacific needn't be concerned.