/// Takes a list of (quantity/amount and price/rate) as decimals, and gives a weighted average let weightedAvg mylist = let weightedValue = mylist |> List.sumBy(fun (isum,irate) -> isum*irate) let weightedSum = mylist |> List.sumBy(fun (isum,irate) -> isum) match weightedSum with | 0m -> 0m | x -> weightedValue / x