When Trex Company Inc. (NYSE:TREX) reported second-quarter earnings after market close on July 30, investors had high expectations that the company would once again deliver double-digit sales and earnings growth. Well, the green-focused decking and commercial railing maker did even better, growing sales by a huge 31%, and driving earnings 49% higher, with both metrics blowing Wall Street estimates out of the water. 

And when the market opened on July 31, investors voted heavily in favor of the blowout numbers, sending shares up more than 20% on the day. Let's look at Trex's results and three reasons the company continues to perform so well. 

Trex deck with aluminum railing.

Image source: Trex Company Inc.

1. Leveraging its scale and keeping costs low

Over the past five years, no other company in the wood-alternative decking industry has made the same inroads with growing distribution as Trex, establishing itself as a national brand with shelf placement in all the national home-improvement retailers, and with many regional distributors that supply smaller lumber and home-improvement retailers and contractors. 

But broad distribution is only part of the picture; Trex has turned sales growth into huge earnings expansion:

TREX Revenue (TTM) Chart

TREX revenue data by YCharts. TTM = trailing 12 months.

Earnings per share -- aided by share buybacks as well as profit growth -- have increased at more than eightfold the rate of sales over the past five years. 

Management has been rigorous in keeping costs under control, while also investing in increased manufacturing efficiency. The company actually operates fewer factories today than it did five years ago, while having increased its total capacity by focusing on higher throughput and better leverage of its existing facilities. 

The result is steadily higher margins as revenue and volumes have grown: 

TREX Gross Profit Margin (TTM) Chart

TREX gross profit margin data by YCharts.

One note on gross margin percent: As you can see in the chart above, Trex's gross margin percent has been relatively flat since the late 2017 acquisition of SC Company, now known as Trex Commercial Products. That segment generates lower margins than Trex's core residential decking business. Last quarter, the residential segment reported gross margin of 45.9%, up 0.3 percentage points, while the commercial products segment delivered 24.6% gross margin, which was up significantly from the first quarter. 

Back to the chart above: Trex's ability to turn new sales into higher margins -- incremental margins -- has been central to its outsized profit growth over the past few years. And management expects to deliver 45% to 50% incremental margins in the second half of 2018. 

And it's not just manufacturing expenses that Trex has controlled. Over the past five years, sales, general, and administrative (SG&A) expense has increased 50.2%, about half the rate of sales growth. In the second quarter, SG&A expense was up 23%, while sales were up 31%. 

2. A steady hand at capital allocation

This is very much tied to the first section, as much of the profit improvement Trex has seen is related to investments in higher throughput and other efficiency improvements in its manufacturing. In the first half of 2018, the company made $18 million in capital expenditures, which CFO Bryan Fairbanks described as "...primarily allocated to planned cost-reduction initiatives and other production improvements." 

Trex also isn't overpaying to acquire competitors to take market share, having instead chosen to diversify away from just residential home improvement when it acquired SC Company late last year. That $71 million acquisition positions Trex to expand its reach into commercial railing, a market with different levers and opportunities than residential decking. Last quarter, the commercial products segment generated $17 million in sales at 24.6% gross margin. At its current pace, Trex will have acquired SC Company for less than 1.1 times sales, not a bad deal for a steady cash-generating business with minimal capital investment needs and a strong position in the marketplace. 

Management has also emphasized share buybacks, spending $8 million last quarter to repurchase 150,000 shares. That works out to $53.33 per share, a 31% discount from the current price: around $77.74. 

3. Riding a healthy home improvement market

A huge part of Trex's success these past several years is the demand for its products in a strong housing and home improvement market. It's worth noting that Trex doesn't benefit quickly from increased home sales, since big-ticket home improvements like a deck tend to fall low on new homebuyers' lists -- as compared to inside projects like flooring, kitchen, and bathroom updates. 

But several years into a healthy housing market, decking projects have moved up on homeowners' lists, and Trex is profiting. This chart shows how Trex's sales have corresponded with increased existing-home sales over the past decade:

US Existing Home Sales Chart

U.S. existing-home sales data by YCharts. SAAR = seasonally adjusted annual rate.

For additional context, recent existing-home sales levels are viewed as a relatively healthy, sustainable number. It's still well below the 2006 peak of more than 7 million, which proved to be an unsustainable bubble, while current levels could be buoyed by millennials entering the home market for many years. 

Looking ahead

The tailwind won't last forever; housing has proven stubbornly cyclical, and at some point there will be another lull, before an eventual return to growth. But the big takeaway here is that, while Trex and its investors have profited wildly in recent years on the back of a strong housing market, management's steady hand at keeping costs in line, investing in expanded distribution and product innovation, and taking steps to strengthen and diversify the business without "diworsifying" should also pay off by reducing the downside risks during the next down cycle for housing. 

But management doesn't see a downturn happening overnight. The company set third-quarter guidance for $173 million in sales, which works out to 24% sales growth from last year. Commercial products sales are expected to grow 12% to $19 million, while the majority of its sales growth is expected to come from residential products in the strong home improvement market. 

Eventually the cycle will turn. But for now, Trex continues to take advantage of very strong demand, and its leading position in the marketplace. 

Jason Hall owns shares of Trex. The Motley Fool owns shares of and recommends Trex. The Motley Fool has a disclosure policy.