Selling and buying shares with borrowed funds

Just following up from recent podcast content, for clarification.

Say I borrowed (equity redraw / debt recycling) equal amounts to buy shares A and B, but decide three years down the track that I want to sell all of B and buy C. Both A & B have grown by 20%. Loan is P&I. Let’s ignore CGT for now.

If I sell all of B, exactly how much do I pay back into my facility before redrawing to buy C, to retain maximum deductibility?

  • The full amount from sale of B? In this case I'm paying off all of B borrowed funds, plus more - which I assume is shrinking my deductibility of A. (If it doesn't do that, when I redraw again to buy C, my “total” borrowed funds would now exceed the facility limit, which makes no sense.)

  • The initial amount used to buy B? But given the loan is P&I, deductible amount of B has been shrinking with my loan repayments. The data “matches” but my loan facility is smaller than when I began, so proportionally this doesn't add up.

  • The initial amount used to buy B, but “shrunk” according to principal paid off? This amount won’t match any transactions the ATO has access to, so it might seem unclear to them.

It feels so much more straightforward to sell B, buy C immediately, and continue to claim the same amount borrowed. (Obviously I will need to pay CGT out-of-pocket). Has the borrowing nexus really been lost in this case?