calculate margin of safety