calculateTimeWeightedAverage
should normalize the weighted sum
calculateTimeWeightedAverage
compute the time weighted average over multiple periods, each one having its own weight, indicating its importance over the other ones.
The issue is that while the values are scaled by their weights, the end result is not normalized to 1, which is usually done by dividing the final result by the sum of all weights, as described by the definition of a time weighted average
Example (all period having a duration of 1
for simplicity):
Period1: value = 10
, weight = 2
Period2: value = 50
, weight = 1
Period1: value = 5
, weight = 2
The actual implementation will return 10*2 + 50*1 + 5*2 = 80
, which is definitely not the weighted average of the periods.
While it should have returned (10*2 + 50*1 + 5*2)/(2+1+2) = 16
Overly inflated value of the average
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.