Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Why is my leverage exceeding 1? Please help

Hi,

I tried to keep my leverage under 1. And I am sure that my weights all sum to 1 in absolute terms. So why does the leverage shoot up on 1st July 2013?

is this a bug in Q?

Best regards,
Beginner

3 responses

Your algo suffered from open order disease.

Here, I fixed it the leverage problem, but I don't know enough about your code to tell you if it affects results.
In many cases some sell orders cannot be filled, but the buy orders are filled. This leads to temporary leverage over a day, as the market provides more shares the following days.

It looks like your code tried to sell QVCB on 2013-06-17 ten times. How come?

You are right. I see transaction

QVCB SELL -149040 $19.72 ($2,938,472.64)

Noticed that this problem occurs only when in daily mode and not in minute mode. So maybe it has to do with incorrect daily closing prices.

I don't know enough about the workings of your code (it looks really neat by the way, I imagine you have good hand writing too). But if I were a betting man, I'd say that it's a bug in the Q. I understand your trade execution code and it looks ok. I thought maybe you accidentally repeated QVCB several times in your total_df but it looks good. Total_df by the way is totally not a dataframe! very misleading when debuging :P
Pricing error also doesn't really explain why cancelling orders at the start of the day fixes the problem.

I'll stop now because this is the limit of my expertise in programming and stock market mechanisms.