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

Is there a way to create a function in an algorithm to chart the costs?

From https://www.quantopian.com/posts/stocks-on-the-move-by-andreas-clenow
... I understand this defines the costs of margin (negative cash, borrowing), the particular form of leverage that is margin:

LevCost(t) = (1+L)∙k∙A(0)∙(1 + r + α – fc%)^t - (1+L)∙k∙A(0)∙(1 + r + α – lc% – fc%)^t  

IB
Margin Fees: https://www.interactivebrokers.com/en/index.php?f=interest&p=schedule2
Margin Limits: https://www.interactivebrokers.com/en/index.php?f=marginnew&p=stk
Intro to Margin: https://www.interactivebrokers.com/en/index.php?f=4745&p=pmar

1 response

One small step for margin awareness, not a giant leap for much, important nonetheless.

This backtest from here was incurring margin beyond the value of positions at times. No broker will do that unless you're putting up your yachts for collateral. In the code, the margin hack looks for those times near the end of day and adjusts positions to target less than 100% margin for something closer to tradable on planet earth. Results and some lines from the log output ...

                  Q Returns    PvR (Profit per maximum dollar risked)  
   His version:   2707%        237%  
Limited margin:   1760%        256% (increase)

2013-04-01 12:58 margin_hack:138 INFO mratio -3.11%  
2013-04-01 12:58 margin_hack:144 INFO YHOO order -967 of 31094  
2013-04-01 12:58 margin_hack:144 INFO DAL order -967 of 31094  
2013-04-01 12:58 margin_hack:144 INFO TSN order -992 of 31908  
2013-04-01 12:58 margin_hack:144 INFO HRB order -992 of 31908  
2013-04-01 12:58 margin_hack:144 INFO HPQ order -992 of 31908  
2013-04-01 12:58 margin_hack:144 INFO PSX order -967 of 31094  
2013-04-01 12:58 margin_hack:144 INFO MPC order -967 of 31094  
2013-04-01 12:58 margin_hack:144 INFO NYX order -992 of 31908  
2013-04-01 12:58 margin_hack:144 INFO BBY order -992 of 31908  
2013-04-01 12:58 margin_hack:144 INFO BAC order -967 of 31094  
2013-12-02 12:58 margin_hack:138 INFO mratio -28.15%  
2013-12-02 12:58 margin_hack:144 INFO DAL order -11308 of 40165  
2013-12-02 12:58 margin_hack:144 INFO FB order -10442 of 37089  
2013-12-02 12:58 margin_hack:144 INFO MU order -11308 of 40165  
2013-12-02 12:58 margin_hack:144 INFO LNG order -10442 of 37088  
2013-12-02 12:58 margin_hack:144 INFO TSLA order -11308 of 40165  
2013-12-02 12:58 margin_hack:144 INFO IEP order -10442 of 37088  
2013-12-02 12:58 margin_hack:144 INFO LUV order -10442 of 37088  
2013-12-02 12:58 margin_hack:144 INFO BBY order -11308 of 40165  

PvR is turned off here for speed and to give mratio the stage.