The cannabis industry is growing and, naturally, investors are taking notice.

With 30 states and the District of Columbia having legalized the use of the drug for medicinal or recreational use, the stock prices of the companies that grow, process and sell marijuana have been rising.

Late last year, the first marijuana-focused exchange-traded fund, or E.T.F., listed in the United States began trading, making it easier for investors to buy into a swath of companies connected to the industry.

The fund, the ETFMG Alternative Harvest E.T.F., has attracted about $400 million since December, making it one of the fastest growing E.T.F.s this year. The fund tracks 39 companies, many of which trade on stock exchanges in Canada, where listing requirements are less rigorous, and where that country’s Senate passed legislation to legalize marijuana throughout the country.

While investors are optimistic that companies linked to the marijuana industry will continue to grow, the performance of the Alternative Harvest E.T.F. has been uneven. The E.T.F. hit a high of $39.72 in January, but it has slipped about 25 percent since then. The value of the Standard & Poor’s 500-stock index has barely changed over that same period.