Created
September 15, 2025 08:54
-
-
Save Thorium/99bebae07c0d6663014c8f9627581e8b to your computer and use it in GitHub Desktop.
Takes a list of (quantity/amount and price/rate) as decimals, and gives a weighted average
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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<GBP> -> 0m | |
| | x -> weightedValue / x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment