NEW YORK ( TheStreet ) -- Commodities funds are finally rallying.

This year, commodities broad-basket mutual funds have gained 5.7%, compared to 4.2% for the S&P 500 (SPY) - Get Report, according to Morningstar. The healthy showing represents a huge shift from the recent past. During the three years ending in 2013, commodities funds lost 6.2% annually, compared to a gain of 16.2% for the S&P 500.

Can commodities prices keep climbing? Probably. With economies growing in China and other emerging markets, demand should remain steady for oil, livestock and metals. "The global market for commodities is somewhat tight," says Darwei Kung, portfolio manager of DWS Enhanced Commodity Strategy (SKNRX) - Get Report, a mutual fund. "There is not a lot of spare capacity for many commodities."

Commodities seem likely to stay in the black this year, says Ryan Issakainen, ETF strategist for First Trust Advisors. He says that commodities prices tend to rise during the later stages of economic expansions. At such times, economies gain steam, and businesses bid up prices of materials. The economy has been recovering since 2009, and there is good reason to think that we are entering the second half of the recovery, a period that should favor commodities.

Many retail investors first noticed commodities funds a decade ago. Strong performance attracted the attention. From 1999 through 2005, commodities funds climbed steadily. With economies booming in Asia and Latin America, demand increased for such commodities as copper, agricultural products and precious metals.

As the rally progressed, some financial advisors argued that most portfolios should include at least some commodities because they offered diversification as well as solid returns. Proponents pointed to studies showing that prices of oil and other products sometimes rose when stocks were falling. But as the financial crisis unfolded, commodities funds tanked along with stocks. In recent years, slowing growth in China caused weakening prices for metals and other commodities.

Analysts argue that commodities can still offer some diversification -- though the amount has declined in recent years. To appreciate the role that commodities can play, consider that if two investments move in lockstep, they are said to have a correlation of 1.0. If they never move together, the correlation is 0. Morningstar analyst Timothy Strauts says that in the 1980s and 1990s, the correlation of commodities and stocks was 0. These days the correlation is about 0.5.

"Commodities still make sense because you get a relatively low correlation," he says.

Strauts says that the correlation has increased over the years because of the way that commodities trading has changed. Before 2000, most commodities traders were speculators or people in the industry who wanted to hedge their exposure to certain products. If stocks collapsed, traders had little reason to dump commodities. But in the past decade, many retail investors have begun buying commodities. When markets become volatile, these new traders tend to sell all their holdings -- including stocks and commodities.

As a result, the correlation has increased.

While some commodities funds focus on energy, others are more broadly diversified. Among the energy-heavy mutual funds is Goldman Sachs Commodity Strategy (GSCAX) - Get Report. During the past five years, the fund returned 4.0% annually, compared to 2.7% for its average peer. The fund's benchmark is the S&P GSCI Commodity Index, which weights commodities according to the amount of their production. Since there is considerable production of oil and natural gas, the fund has 71% of assets in energy. Precious metals, which are produced in smaller quantities, account for less than 3% of assets.

Investors should consider holding a stake in energy because it has a big impact on the global economy, says Michael Johnson, head of commodities portfolio management for Goldman Sachs Asset Management.

Energy holdings can protect portfolios against inflation. During periods when energy prices rise, inflation can climb and stocks may sink. "If cotton prices go up, there may not be much inflation," he says. "But if crude oil prices increase, there is a risk of general inflation."

DWS Enhanced Commodity Strategy is more diversified, holding 22% in energy, 38% in agriculture and 18% in industrial metals, including aluminum, zinc and nickel. During the past five years, the fund returned 3.7% annually. Actively managed, the fund aims to overweight attractively priced commodities. The fund is currently underweight energy because the sector has had strong performance in recent months.

A new ETF is First Trust Global Tactical Commodity Strategy (FTGC) - Get Report. The fund has 26% in energy, 26% in industrial metals, and 44% in agriculture products, including hogs, wheat and coffee.

>>Read More: Xerox Is the Biggest Secret in Value Stocks as It Moves Beyond Copiers

>>Read More: Investment Rx: Buy Value ETFs in the U.S. and Growth ETFs Overseas

>>Read More: Could Nissan's Electric Minivan Crush Tesla's Model X?

>>Read More: If You Have Euro-Backed Assets You'd Better Sell Them Right Now

At the time of publication, the author held no positions in any of the stocks mentioned.

Follow @StanLuxenberg

This article represents the opinion of a contributor and not necessarily that of TheStreet or its editorial staff.