Calculating exchange with Scala