function to calculate transaction cost