The key factor here is how much of the investment/margin interest you used and what you used the money for. Investment interest is interest you pay on loans to keep a investment property. That could be things like stocks and securities. Margin interest is interest charged by your broker when you borrow money against your brokerage account. It is more or less considered the same as an investment interest as long as you use the money for investment purposes.
Investment income is your investment property that consists of investment interest, dividends, and short-term capital gains minus any investment expenses you might have.
Investment/margin interest can be written off if it exceeds your investment income. This means that the money you make, the gain on your investments if more than the amount of interest that you paid on your loans to make the investment, is deductible.
Another option available is to include your long term capital gain in your investment income. This gain is not included in your investment income but you may choose to include it. The only downside to doing this is that you lose the ability of your capital gains to reduce your tax rate in the future. Long term capital gain is usually gain from stocks or investments you have held for over one year. By including it in your investment income, you increase your investment interest exemption for this year. This means you'll wind up with more money in your pocket for this tax year. Do remember that in the long term, you are reducing the exemption you can claim on your long term capital gains.
Also remember that investment interest on tax free investments cannot be deducted. In addition, keep in mind that you cannot opt to take the standard deduction and must itemize your deductions. Using standard deductions will yield you no benefits