What happened

Shares of semiconductor stocks ASML Holding (ASML -2.05%), Applied Materials (AMAT -2.79%), and Ambarella (AMBA -2.79%) rallied in July, up 21.8%, 16.5%, and 32.2%, respectively, according to data from S&P Global Market Intelligence.

The broader semiconductor sector did rather well in July, as it tends to be more sensitive to economic news, whether good or bad. As the sector fell more than the general indexes in the first half of the year, it's perhaps no wonder these three semi stocks did well as the economic picture seemed to improve last month.

In July, commodity inflation showed signs of easing, and market participants anticipated an end or at least slowing of Federal Reserve interest rate hikes. Given the highly sensitive nature of the chip industry to overall economic conditions, that boded well for most large-cap and diversified semi-related stocks. Applied Materials has the broadest portfolio in semiconductor equipment, so it rose even in the absence of much company-specific news.

Meanwhile, ASML reported second-quarter earnings that, while missing earnings estimates, contained a lot of positives in the outlook for this year and next year. Ambarella didn't report earnings, but as its low-power imaging system-on-chips (SoCs) target the automotive sector, strong earnings from other auto-related semiconductor stocks helped its cause as well.

Then toward the end of the month, the U.S. Congress passed the CHIPS Act, which has the potential to greatly benefit U.S. foundries and equipment makers, adding fuel to the rally in ASML and Applied Materials.

So what

In the second quarter, ASML reported revenue of 5.4 billion euros ($5.49 billion) and earnings per share of 3.54 euros. While management projected only 10% growth for this year, this was primarily due to the implementation of ASML's fast shipping policy amid booming demand for the company's extreme ultraviolet (EUV) and deep ultraviolet (DUV) lithography solutions.

Fast shipping means ASML ships machines to customers before they are fully tested and qualified, leading to a faster time to use. However, that also means ASML can't record the revenue until its machines are fully tested at the customer's site, so its revenue is delayed, but not lost.

Without this policy, shipments were projected to be up 20% this year as previously forecast, and management noted it is still supply constrained this year and next. ASML still took in a record 8.5 billion in orders, well above its revenue, and its backlog grew to a record 33 billion euros. That suggested that even though there is economic uncertainty, demand for lithography isn't slowing.

While ASML benefits from a monopoly on key EUV technology essential for leading-edge node production, all semiconductor manufacturing stocks got a boost when Congress passed the CHIPS Act toward the end of the month. The bill will provide $52.7 billion in funding for domestic semiconductor fabs, another $11 billion for advanced research and development, and another $80 billion for science education to build up America's technology capabilities.

Needless to say, the bill should be very positive for semiconductor equipment makers, as it should accelerate investment in U.S. fabs over the next decade. That has the potential to offset some of the softness feared in the current economic slowdown. Not only will that help ASML, but also Applied Materials, the most diversified of the semiconductor equipment companies. Of note, Applied reports earnings later this month.

Finally, positive earnings reports from auto chip-focused companies like Texas Instruments and NXP Semiconductors during the month likely led to optimism over auto-focused semiconductor designers. Since Ambarella is targeting the auto market with its AI-vision SoCs for autonomous driving, it rose in concert. Of note, Ambarella got a key design win with Chinese autonomous truck company Inceptio in late June, which may have helped as well.

Unlike ASML and Applied, which are solidly profitable, Ambarella is still losing money on its bottom line and is a smallish company, with just a $3.3 billion market cap. Those factors make the stock more sensitive to interest rates and the overall economic outlook, so it's no wonder it appreciated more than the others in an otherwise positive July.

Now what

The semiconductor sector looks attractive after the market's first-half swoon, given the strategic importance of the sector to so many evolving trends in artificial intelligence, the Internet of Things, autonomous vehicles, and advanced weaponry.

While the sector can be volatile, winners in the space seem set for years of solid returns, provided investors have a long time horizon and can handle substantial volatility. As we saw in July, when fears subside, these stocks can boom.