Praise be to Allah, the Lord of the World; and may His blessings and peace be upon our Prophet Muhammad and upon all his Family and Companions.
First, know that every Muslim should limit himself to dealing in what conforms to the Shari'a. So, he should not contribute in an institution whose transactions are forbidden by Shari'a. As he would be considered a participant as per the value of the shares he holds in that company. The Muslim should not participate in any work that includes a forbidden thing regardless of whether it is in a Muslim or a non-Muslim country. As what is forbidden for Muslims in their homes is also forbidden elsewhere. Zakah of shares in companies, is as follows:
1 - If the person has invested in the company with the intention of getting a benefit from the yearly revenue of the shares and not with the intention of trading, then Zakah is similar to that of immovable properties such as real estate and non-agricultural lands. This ruling means that there is no Zakah on the share itself. But the Zakah is obligatory on the yearly earnings of the stock and it is 2.5 percentage from the revenue after the passing of a year from the time this revenue was owned, provided all the conditions of Zakah are met and there is nothing contradicting it. This is only if the company's shares are permanent assets like real estates, factories, boats, … etc. But, if the shares are goods the Zakah is due on both the capital and the benefit.
2 - If the contributor has bought the shares intending to trade them, then he has to give their Zakah like any goods whether these shares are assets or real goods.
If the time of his Zakah comes while he still owns these shares then he has to give Zakah on the actual market value of them whether that value is more or less than what he paid initially. In case there is no market for these shares then he gives the Zakah according to the value decided by the experts in these matters. So, he gives 2.5 percent of their value and of the benefit if there is a benefit from these shares.
If the company assumes the giving of the Zakah then it can do that on behalf of the shareholders.
3 - If the shareholder sells his shares during the Hawl (Zakah year) then he adds their value to his money and when the time of the Zakah comes, he gives their Zakah along with that of his money. As for the buyer of the shares, he gives their Zakah as mentioned above.
This is what the Fiqh Assembly in the Islamic Conference and the High Council of Muslim Scholars in Saudi Arabia issued in this respect.
Allah knows best.