I understand that interest on a margin balance used to buy securities is tax deductible as an investment interest expense. For example, if I buy $10k of VTI on margin, the investment interest I pay on the margin balance should be deductible.
I'm curious what happens when the margin balance comes from a combination of securities purchases and withdrawals from the account. For example, if I buy $10k of VTI and also withdraw $10k in cash, would half the interest be tax deductible? How would I be able to keep track of this over time as the margin balance fluctuates with transfers, purchases, sales, and dividends?
Similarly, if I bought $10k of VTI on margin, transferred $5k into the account to repay half the margin loan, and then changed my mind the next day and withdrew the same $5k, would I now be in a situation where the resulting $10k margin balance is no longer fully tax deductible?