Guess Hanan has answered this for you here - http://zerodha.com/varsity/chapter/margin-calculator-part-2/