Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Limiting Leverage

Anyone know why this algo is leveraging up to 1.67x when the limit is specified at 1.45x? I thought the limiting method used in this algo (x/n where n = number of securities and x = your leveraging limit [1.45]) and many others was reliable but maybe something else is wrong. Thanks in advance for any ideas.

5 responses

It looks like the leverage varying is not a bug, but a result of fluctuations in your account value. If you rebalance to 145% of your account value and the price of the asset you are holding goes down, then you will have more than 145% of your account invested so leverage goes up.

In general if you are more than 100% invested, then declines in your account value will cause leverage to go up, and if you are less than 100% invested, declines in your account value will cause your leverage to decrease. If you happen to be exactly 100% invested, then your leverage will always be 1x regardless of fluctuations in your account value. Hope this answers your question.

David

Thanks David, but I still do not understand why a decline in account value would cause leverage to go up when you are more than 100% invested. To me it seems like regardless of your leverage when your account value goes down you would have less leverage and vice-versa.

Also, regarding this specific algo, if in the future I decide to enter it into the Quantopian Open, I will have to keep the leverage below 3x. I am wondering how I can make sure the leverage never goes above 3x (or for this half of the algo, 1.45x) so I don't get disqualified.

For illustration:

Your account has $100 to start.
You buy $200 of stock and have $100 of equity, so your leverage is 2.0.
That stock loses 25%, so your $200 is now $150. Note that that $50 loss comes straight off your equity though.
Now, you own $150 of stock but only have $50 of equity, so your leverage is 3.0.

Cheers,

Simon.

I thought leverage above 1 was an indication of margin/borrowing, now I guess that's wrong. Looks like it is figured like this:

    prtflio = context.portfolio.portfolio_value  
    lvrg = (prtflio - context.portfolio.cash) / prtflio  

Here's some code I've been messing around with. Clone/run and mouse over the custom chart, zooming in on, say, 2013, and with a couple million borrowed the leverage can be either high or even negative depending on the portfolio value. Literally scratching my head.

@Simon Thank you! Your explanation was very helpful.

@garyha Very strange. Not sure what to make of that either.