Margin vs leverage and shorting

About margin and leverage, there's a ton of information on the web, I just hope to hear from some of you with experience in this environment. I heard, for example, that IB margin is free when cleared by the end of day. I've seen calculations of margin fees, apparently when margin spans multiple days and they were hefty sums, I haven't heard details on how that works. People often record leverage once per day and consider that good. I prefer watching every minute of the day with max-intraday-leverage or pvr and no one to my knowledge watches in code to distinguish between mere intraday leverage/margin (apparently free) versus margin that runs longer than a day. Although if someone is closing positions near the end of a day they have that covered. Unless volumes are high with partial fills, then they'll be hit with fees?

We often use the terms margin and leverage interchangeably and tend to think of leverage as borrowed cash. True for long-only, as I understand it. Leverage is the number that comes from an equation, where 1.0 would be all cash invested in longs for example, if I'm not mistaken, below 1 usually means not invested so much, and above 1 means cash has gone negative.

Things become more complicated with short selling added to the mix. Short selling is required in the Quantopian contest. I was messing around with the leverage formula in Excel. Couple of things: Leverage can be above 1 with shorting and no margin. Leverage without margin. Most of us knew that. And more interesting -- it appears that keeping 2x cash versus the value of short shares makes leverage 1.0. That part was news to me. Figuring longs in the equation cancel out, short value -- as a positive above, and it's negative below, can think of 2 above zero, and 2 below zero and the difference between them is 4.

Imagine longs worth 2 and short worth 2 (that's minus 2) and 2 dollars in cash. The numerator is 2 + 2 = 4. The denominator is -2 + 2 + 2 = 2. So 4 / 2, and the leverage is 2. Change cash to 4 (two times the absolute -- or made positive -- value of short shares, which are a negative) and leverage becomes 1. 4 / (-2 + 2 + 4). Can be useful in code. Here I was using hundreds ...

Suppose the price on shorted stocks represented by the minus 2 above goes down. With cash at 4. What happens to leverage? Figure it was one share at $2 and the price goes down to$1. That's now (1 + 2) / (-1 + 2 + 4) or 3/5 = .6 Leverage went down. Fine.

The weird part that dawned on me was that keeping cash at twice shorts, longs can be anything and leverage stays at 1. Anything other than cash at 2x short and a change in longs will change leverage.

By the way I was looking thru some videos, they often focus on Options, Forex and leveraged ETF's. If anyone finds a pretty good video or resource that discusses leverage and shorting or anything you think folks might find helpful along this line please consider sharing it. This first vid can maybe be interesting in particular to those on Robinhood possibly, although it helped me a little bit in picturing IB too.

Penny Stock Trading Margin vs Leverage