The custom chart does smoothing, a good thing, so on this one the actual value for the leverage spike of over 2.2 on 2008-07-01 can be seen by using the sliders to zoom in on it. (In the IDE the value/number would be displayed, just temporarily out of service here for awhile).
Or here's a simple bit of code some might find handy:
if 'max_lvrg' not in context: context.max_lvrg = 0 # Or init this in initialize()
if context.account.leverage > context.max_lvrg:
context.max_lvrg = context.account.leverage
log.info('lvrg ' + str(context.max_lvrg)) # Log any new leverage high
I guess there are various schools of thought about momentary margin, I tend to think that since over $2M was spent at any point, once the calculations are done with maxspent, the profit was really only around 260%, sad to say, since that's not too bad of a curve otherwise to be working with as a starting point, would be great if you can find a way to reduce that blip.