Hotfix for weighted median premium (#180)

* hotfix for empty array handling
This commit is contained in:
satsbaba 2022-07-01 16:48:17 +02:00 committed by GitHub
parent b5dd4fbea5
commit 41f3df570e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -185,10 +185,11 @@ def compute_avg_premium(queryset):
total_volume = sum(volumes)
# weighted_median_premium is the weighted median of the premiums by volume
weighted_median_premium = weighted_median(values=premiums,
sample_weight=volumes,
quantiles=0.5,
values_sorted=False)
if len(premiums) > 0 and len(volumes)>0:
weighted_median_premium = weighted_median(values=premiums,
sample_weight=volumes,
quantiles=0.5,
values_sorted=False)
else:
weighted_median_premium = 0.0
return weighted_median_premium, total_volume