Issue #20001:use correct cost method when calculating margin