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

Hello!

Just getting my feet wet here but I was hoping for some guidance on how to track potential margin calls.

Here I am just trying to graph when the portfolio might get a margin call (indicated by the value going below 0)


maintenance_requirement = 0.25  
total_value = context.portfolio.positions_value + context.portfolio.cash  
margin = (total_value) - (context.portfolio.positions_value * maintenance_requirement)  
record(margin_watch=margin)

For some reason I feel like this is too simple and very incorrect. Advice/Suggestions very welcome!

2 responses

Hello Nick,

There has been some discussion of this over the last few months. This is the most in depth that I am aware of: https://www.quantopian.com/posts/template-limiting-leverage-by-brandon-ogle-and-dan-sandberg

As live trading will be via IB it would be interesting if somone could write some reuseable code that matched their handling of a US Reg-T margin account. See:

https://www.interactivebrokers.com/en/?f=margin
https://www.interactivebrokers.com/en/index.php?f=margin&p=stk
https://www.interactivebrokers.com/en/?f=margin&p=overview1

P.

Hey Peter,

I am aware of Brandon and Dan's work but I guess I am surprised that this can't be tracked with the given 'portfolio' vars. imo portfolio level variables like the 'totalShorts' and 'totalLongs' in B/D's work should be able to be calculated from 'portfolio' without having to go through every position. I have been working on a more complicated monitoring system for Reg-T requirements and will be sure to post.

NB