(4) Net investment income For purposes of this subsection— (A) In general The term “net investment income” means the excess of— (i) investment income, over (ii) investment expenses. (B) Investment income The term “investment income” means the sum of— (i) gross income from property held for investment (other than any gain taken into account under clause (ii)(I)), (ii) the excess (if any) of— (I) the net gain attributable to the disposition of property held for investment, over (II) the net capital gain determined by only taking into account gains and losses from dispositions of property held for investment, plus (iii) so much of the net capital gain referred to in clause (ii)(II) (or, if lesser, the net gain referred to in clause (ii)(I)) as the taxpayer elects to take into account under this clause. Such term shall include qualified dividend income (as defined in section 1(h)(11)(B)) only to the extent the taxpayer elects to treat such income as investment income for purposes of this subsection. (C) Investment expenses The term “investment expenses” means the deductions allowed under this chapter (other than for interest) which are directly connected with the production of investment income. (D) Income and expenses from passive activities Investment income and investment expenses shall not include any income or expenses taken into account under section 469 in computing income or loss from a passive activity.