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.