robertmartin8 / PyPortfolioOpt

Financial portfolio optimisation in python, including classical efficient frontier, Black-Litterman, Hierarchical Risk Parity
https://pyportfolioopt.readthedocs.io/
MIT License
4.25k stars 928 forks source link

Incorporating broker's margin interest rate into the model? #518

Open nathanramoscfa opened 1 year ago

nathanramoscfa commented 1 year ago

What are you trying to do? With a long/short portfolio, the short side will be charged a margin interest rate by the broker...for example e-trade currently charges between 11.2% to 13.2% interest on the margin balance. How do we incorporate this information into the portfolio optimization model?

What have you tried? I have thought about adjusting posterior returns from black-litterman model by subtracting the margin rate from posterior returns, but, the margin interest rate is only charged on the short side of the portfolio, and I don't know beforehand which tickers the model will decide to short.

I derived a formula to adjust the optimized portfolio's expected return to account for margin interest rate on margin balance to broker:

image

r = unadjusted optimal portfolio return d = margin debt weighting% in portfolio i = margin balance interest rate

So if my optimized 130/30 long/short unadjusted portfolio return is 17.40%, margin balance weighting is 30%, and margin interest rate is 13.2%, then the margin interest rate adjusted optimized portfolio return is = 16.87%. This compares to the unadjusted for margin interest rate return of 17.40%.

Thinking about trying to add this formula as an objective to the model, just hung up on how, if anyone has any examples using this library, I'd appreciate it.

What data are you using? Using black-litterman covariance matrix and posterior returns.

mdmcconnell commented 1 year ago

I think you may be mixing two concepts - margin interest is charged on the (net) amount of cash borrowed to take (long) positions. In your example, you're borrowing 30% additional cash to buy shares, and it sounds as though e*trade gives no interest credit for the cash raised by selling shares short. Which shares are short, or long, in the portfolio makes no difference to the overall amount of cash borrowed. As long as expected returns of the optimal portfolio are greater than the margin interest there is no need to account for it in the optimization. The returns to the levered portfolio will be reduced by the cost of leverage, as you show, but it is still the optimal portfolio for your constraints.

Meanwhile broker's borrow fees are charged on the shares borrowed to short. They tend to be small, variable, and possibly hard to predict. But they could make a difference to the optimisation if a short position's returns change to the extent it is no longer optimal to short that share (or in the same quantity).

One possible, brutish, way to account for borrow fees would be to create a duplicate short asset for every asset in the model, whose return is the inverse of the original long asset, minus borrow costs.