This 0.596375
and this...
from this
#
# coding: utf-8
import numpy as np
from matplotlib import pyplot as plt
from numpy import trapz
GDP = 6532000000000
factors = np.array([0.49,0.59,0.69,0.79,1.89,2.0,5.0,10.0,18.0,60.0])
prep = factors*GDP/100
A, B, C, D, E, F, G, H, I, J = prep
q_s = prep.reshape((5,2))
Q1, Q2, Q3, Q4, Q5 = np.sum(q_s,axis=1)
Qs = np.sum(q_s,axis=1)
# Calculate the percent of total income in each quintile
Ts = ((100.*Qs)/GDP)/100.
TR = np.sum(Ts)
# Calculate the cumulative percentage of household income
y = np.cumsum(Ts)
# The y values. Cumulative percentage of incomes
# The perfect equality y values. Cumulative percentage of incomes.
y_pe = np.linspace(0.0,1.0,len(y))
# Compute the area using the composite trapezoidal rule.
area_lorenz = np.trapz(y, dx=5)
# Calculate the area below the perfect equality line.
area_perfect = np.trapz(y_pe, dx=5)
# Seems to work fine until here.
# Manually calculated Gini using the values given for the areas above
# turns out at .58 which seems reasonable?
Gini = (area_perfect - area_lorenz)/area_perfect
#
print(Gini)
plt.plot(y,label='lorenz')
plt.plot(y_pe,label='perfect_equality')
plt.legend()
plt.show()
And no guarantee it is even remotely correct.