Generally, capital gains received by a nonresident alien not present in the United States for 183 days or more are not taxable in the United States, but in the home country IRC Section 865(a).
A nonresident alien is present in the US for 183 days even as a exempt individual (e.g. F-1 student) is subject to capital gain tax at a flat 30% tax rate [IRC Section 871(a)(2)], regardless it is long term or short term, with no deduction allowed for allocable expenses per IRS website.
If the nonresident alien meets above 183 day test, then capital gains or losses are included in the calculation even she is not present in the United States when the gains were recognized per Reg. Section 1.871-7(d)(2)(i).
- Nonresident aliens pay a flat 30% tax on dividends from US source, but the article 9 of China-US tax treaty reduced the tax rate to 10%:
… the tax so charged shall not exceed 10 percent of the gross amount of the dividends
Nonresident aliens are able to exclude interest, foreign dividends from their gross income Pub 519.
For residents, short term capital gain, non-qualified dividend, and interest are taxed as regular income, long term and qualified dividend are taxed at 0% to 20% depending in tax bracket as documented in wikipedia.