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

As an example, suppose I only have cash, with no pending orders. What are some typical margin rules that would apply? What split between long and short could I have, as a percentage of the cash? How much margin could be applied on top of that? And how?

I realize that this is trading 101, but perhaps someone can provide a few simple illustrations (and code, if you want).

Thanks,

Grant

3 responses

Hello Grant,

These example are from IB:

P.

Thanks Peter,

This appears to be a good summary:

http://206.106.137.34/MktServices/servlet/CreatePdf?f=/en/trading/marginRequirements/fundamentals.php&lm=1185391240

Still opaque yet straightforward grade-school math. The document explains how the rules are applied on real-time and EOD bases.

One question, which perhaps you've sorted out, is what information is available from IB and when, via the Quantopian algorithm (basically the distinction between synchronous (minutely) and asynchronous (ASAP) modes)? Also, looking over the Quantopian help docs., it is not clear if there is a way to tell if a given order has been rejected and why. Have you seen anything?

Grant

Hello Grant,

We may only know when we can run an algo against a real IB paper trade account.

I have seen "IBM is restricted from short sale" and "There is insufficient XOM available for short sale" messages in TWS, and Dan has seen "order held" somewhere, as he advises at https://www.quantopian.com/posts/handling-of-orders-that-cannot-be-filled-by-broker. Dan says "That is not ideal! I want to pass the full error back to you, but the connector isn't in place yet. You'll notice in the "logs" tab that you get SYSTEM messages about IB activity. When we finish the connector, you'll see the fuller IB message about short sales in the connector."

The only other useful info. is https://www.quantopian.com/posts/possible-real-money-bug where we read:

"When you have a position in IB that doesn't match what Quantopian has, Quantopian accepts IB's position as "truth" and updates the Quantopian status. That breaks into a couple main sub-cases.
If Quantopian has a zero position, and IB has non-zero, then Quantopian updates everything - the position, the cost basis, etc.
If Quantopian has non-zero position, and IB has non-zero, then it's a bit trickier. The position is updated in Quantopian, of course. However, we don't adjust the cost basis. IB and Quantopian use different cost basis calculation methods, and it's very difficult to infer the cost basis when you have mis-matched amounts.
The third case is if Quantopian has non-zero and IB has zero, in which case the point is moot - zero shares means no cost basis!"

P.