## Math Tip for Coders:

Remember when averaging percentages, unlike plain values,no matter if its a simple mean, a moving average, or a exponential moving average, you always want to use the repeated operator on percentages compared to the one you would use on plain values. I know thats confusing and really only makes sense with an example.

So each of the following operators is the repeated form of the prior: +, *,^ (exponent)

Similarly the following: -, / , roots (like square root)

So for a simple mean with plain values you would average three values by doing:

(a + b + c)/3

However if your doing that for percentages that formula doesnt work instead you do:

(a * b * c) ^ (1/3)

Remember taking something to the power of 1/3 is the same as taking the third root.

Also keep in mind the variables here must be percentages such that they are anywhere from 0 to infinity. If you invested in something and you made no money and lost no money it would be 1, for 100%, if you lost all your money its 0, if you lost half its 0.5 (50%), if you doubled your money its 2.0 (200%) and so on

So if you inveted in three different things, and each time you doubled your money, and you wanted to know what your average percentage of return on investment was you would do: (2 * 2 * 2) ^ (1/3) and that would give you your mean, 2.. If you treated it like normal values and added then divided while it would work in this case it would give you significantly incorrect values in other cases.

As I stated this holds true for more complex types of averages too, take exponential moving average as an example. For plain values with EMA you apply each new value to just the previous EMA (and dont need to worry about combining all the values at once).. So if you flipped a coin 100 times and and took the EMA of the first 99 and now want to know know the EMA after the 100th flip (1 being heads and 0 being tails) you do:

(last_value * (1 - alpha) + current_value * alpha)

that gives you your current EMA where alpha is any number from 0 to 1… now to apply that to percentages again you take each operator and make it the next one up so for percentages it is actually:

(last_percentage^(1-alpha) * current_percentage^alpha)

@freemo Does this apply to sets of percentages that are constrained to 0 <= 1 ? That is, percentages that are never above 100%?

@Pat Depends on why it is constrained in that way.. does it truely represent situations where the final value has always decreased? then if so, yes..

@freemo Yes, like relative humidity or percentage of reflected light.

@freemo Thank you. (I was not aware this and I’ve probably made that mistake before without even realizing it.)

@Pat Most people have, another common mistake is you cant extend percentages across time by multiplying.. for example “I made 5% in one day, if i can do this every day for 10 days then I can make 50% in a week!

you would have to instead take the power: 1.05^10 = 1.628, so in face if you make 5% a day then if you do that every day over 10 days you would make 62.8%

@Pat Actually sorry a bit sleep deprived and someone pointed out an important fact.. This only applies to a sequence where the relative percentage refers to the total accumulated at each check point, not independent events and not percentages relative to a fixed absolute.. so in fact for relative humidity the plain way would work.

@Pat yes we are talking about compounding, but norally people are used to only working with compounding percentages when the percentages are fixed (and its easy).. im describing how to take the average of a changing percentage that represents a continuously compounding change.

@freemo
Can you explain why the normal way of doing percentages would be wrong, and why this is the right way?
Taking a different example, say I have 100 doubloons and split it equally to invest in three things, which give me 40% profit (1.4),160% profit (2.6) and 20% loss (0.8), my return would be ((100/3)1.4 + (100/3)2.6 + (100/3)*0.8) = 160 doubloons. Meaning overall average return on these investments is 1.6.
And the plain arithmetic mean of (1.4, 2.6, 0.8) is 1.6, while the geometric mean you suggest is 1.42. The arithmetic mean seems to be the one that correctly gives us the average return of these investments in this sense. In what context does the geometric mean make more sense?

@digital_carver Sorry i should have been more clear, and thanks for pointing this out. I should have specifically said when taking the average of a sequence, not parallel events.

If every day for 10 days I had half the days where I lost 50% and half the days where I doubled my money, 200%, taking the plain average to find out the average you made per day gives you the wrong answer, you’d have to do it the way I described. In the example you gave (which is not a sequence) then doing it the plain way works just fine QOTO: Question Others to Teach Ourselves