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

Hi,

My algo fails Contest entry because of too much leverage. When I plot Leverage to special data, I see that I get a value of 2 for a day which has this portfolio. When I look at the portfolio, i have roughly equal dollar amounts in longs, shorts and cash. I would expect a leverage value of <1 since the shorts are less than cash. How does Quantopian arrive at a leverage value of 1.99 on this day?

1 response

The leverage on that portfolio is ~2x. context.account.leverage returns the gross leverage of the account (defined below)

gross leverage = (market value of longs + abs(market value of shorts)) / net liquidation value

For your case, you have roughly $10333 long, $10865 short, and $11058 in cash, so your gross leverage is,
(10333 + 10865) / (10333 - 10865 + 11058) = 2.01

You are correct that you have roughly equal dollar amounts long and short, which means your net leverage (aka market exposure) is low, but the gross leverage is what will cause a leverage failure in the contest. Hope this helps.

David