I'm trying to calculate the weighted average of stock prices but the problem is that some values are negative (where some but not all stocks were sold) and I can't figure out how to make it work.
Here is how I manged to do it with only positive values and it works fine:
But if I try with some negative values added in I get an error:
Any advice would be appreciated. Thank you!
