What happened

Shares of Trex Company Inc. (NYSE:TREX) took off on Tuesday and were up 21% by 2:45 p.m. EDT after the company announced expectation-beating second-quarter results.

So what

Trex's strong second-quarter results consisted of revenue that rocketed 31% versus the year-ago quarter to $207 million, beating the consensus estimate by nearly $16 million. Driving that strong showing was its residential products segment, where sales increased 20% to $189 million. The company also benefited from the recent addition of its commercial products segment -- via last year's acquisition of SC Company -- which contributed $17 million in revenue during the quarter.

Lounge chairs on a deck at sunset.

Image source: Getty Images.

Earnings, meanwhile, surged 49% to $0.73 per share, which beat analysts' expectations by $0.08 per share. Driving the stronger-than-anticipated profit were improving margins in both segments. The biggest increase, though, came in the commercial products segment as its merger integration efforts continue to pay dividends.

Now what

Trex also provided optimistic guidance for the third quarter. It forecast $173 million in net sales, which would be 23% ahead of last year's third quarter, fueled by 18% organic sales growth in the residential products segment. With the company expected to maintain robust margins, 2018 should be a strong year.