NEW YORK -- Metal was the magic material for profitable investing in the stock market during 1987. And the surest road to losses was to put your money on Wall Street itself.

Stocks of companies that produce almost any type of metal -- steel, copper, aluminum, gold -- weathered the crash in October to post some of the best gains of the year.

Among all the industry groups tracked by Standard & Poor's Corp., "miscellaneous metals" ranked first for the year through Dec. 23, with a 73.1 percent rise. Gold mining stocks were the runnerup, climbing 61.2 percent, followed by steel, up 60.9 percent, and aluminum companies, up 56.8 percent.

Shares of publicly held brokerage firms showed the biggest loss in S&P's tabulation, falling 37.5 percent. Other losers included toys, down 33.5 percent; money-center banks, down 30.5 percent; and air freight, down 30.1 percent.

As of early this week, the stock with the best individual percentage gain for the year among New York Stock Exchange issues was Lukens Inc., which more than tripled from $14.75 a share to just under $50.

Lukens, a producer of heavy steel plates, had its share of woes earlier in the decade, like many another American steel company, and as recently as 1985 was losing money.

Right behind Lukens among the percentage gainers was another of smokestack America's wounded giants, Bethlehem Steel, which jumped from $6.25 to about $18.

The steel companies, along with producers of nonferrous metals, demonstrated one of the market's upbeat themes during the year -- that American manufacturing was starting a comeback.

The securities industry stocks had been laggards all year, in part because of worries about rising operating costs and bond-trading losses at some firms. Then, when the crash hit, they were natural candidates for a drubbing.

Shares of Salomon Inc., parent of one of the Street's most prestigious investment banking houses, peaked at $59.50 in early 1986. They were trading in the $30s before the crash took them down as low as $16.62 1/2. Early this week they stood at $19.

Merrill Lynch, one of the best-known securities firms that does an extensive public business, traded at $56.62 1/2 in 1983 and has never been that high since. It has lately been changing hands for about $22.