Start with the guaranteed side
Prepaying a loan at 9% gives you a guaranteed, tax-free 9% return. There is no market risk, no exit timing and no fund manager. That is the benchmark any investment has to beat.
Then look at the realistic side
Equity returns are not guaranteed over a five-year window, which is the horizon that matters when comparing against a loan. If the investment is a debt fund yielding 7% pre-tax, prepayment wins comfortably. If it is equity with a realistic long-run expectation of 11–12% pre-tax, the comparison becomes closer and depends on your risk tolerance.
Liquidity is the tie-breaker
Money paid into a loan is gone until you sell the asset or borrow again. Money in a mutual fund is available in three working days. If your emergency fund is not funded, that liquidity is worth paying some interest for.
A simple rule
If the loan rate is above 10%, prepay. Between 8% and 10%, split the surplus. Below 8%, invest — and keep the loan, because that money is cheap.