Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
leverage ratio just going up even when no trading happened.

I am wondering if there is a flaw with the function context.account.leverage. I cannot understand why this figure would change. I made the trade to happened every 2 years. but around march 2009 the leverage spikes to 10 when I didn't buy or sell! Please help me understand what is going on.

6 responses

See this post on how Q calculates leverage. You probably had some shorts that blew up.

Michael, if you see the positionCount, which shows the number of positions outstanding, it is consistently at 33.

Your leverage depends not on the number of positions but on their market value relative to the account liquidation value.

Michael,
Could you explain to me why market value and the liquidation value should be any different? I thought we were trading public securities where except for slippage, you account liquidation value should be roughly equal to market value. Only in private equity or real estate investment the gap should be big. But you can notice that the leverage ratio was hovering 10!

If you use margin (as your algo does, though you may not have intended it), market value and liquidation value will differ. Suppose you have $100 in your account. You buy $200 of stock, using your $100 cash and a $100 margin loan. At this point your net liquidation value is $0 cash - $100 loan + $200 stock = $100. The market value of your positions is $200. So your leverage is $200 / $100 = 2.0.

Then suppose the stock drops 40% to $120. Your net liquidation value is $0 cash - $100 loan + $120 stock = $20. The market value of your positions is $120. So your leverage has tripled to $120 / $20 = 6.0.

Your algo starts buying stocks in October 2005, using order_target_percent. Quantopian calculates the number of shares to buy based on the price at that time and places an order. This number of shares is not adjusted later, even if the order doesn't fill right away and the price changes. Some of the stocks are illiquid, so the orders fill over a period of many weeks, ending in December 2005. By that time some of the prices have risen. So you end up using margin (spending more than 100% of your original cash). Your leverage when you finish all the buys is about 1.4.

Similarly, your 2007 buys take about two months to finish, and after that, your leverage is over 1.6. Your portfolio includes illiquid small-cap stocks. When the market crashes in 2008, those stocks go down hard, and your leverage spikes up.

Michael,
I really appreciate you explanation. So I must have ended up taking out loans due to trading in illiquid assets that was executed many weeks down the road.
Regards
Ujae