how does margin calculator work