Revised function get_balances_over_time

Should be more flexible. Callee can use all parameters.
This commit is contained in:
scuti 2025-10-04 22:31:29 -07:00
parent 637aaf5aec
commit e3c68947c5

View File

@ -59,27 +59,17 @@ def mining(balances, halving_frequency=1, reward=10, terms=3):
current_balances = new_bal current_balances = new_bal
return balances_over_time return balances_over_time
def get_balances_over_time(names, balances, func, terms=4, param=0): def get_balances_over_time(names, balances, data):
if func is None:
print("Need a function!")
return
if len(names) != len(balances): if len(names) != len(balances):
print("Every person needs a balance.") print("Every person needs a balance.")
return return
data = { df = pd.DataFrame({
'name' : names, 'name' : names,
'initial' : balances 'initial' : balances
} })
df = pd.DataFrame(data) for i in range(0, len(data)):
frame_data = [] key = str(i+1)
if param == 0: df[key] = data[i]
frame_data = func(balances, terms=terms)
else:
frame_data = func(balances, terms=terms, rate=param)
assert(len(frame_data) == terms)
for i in range(0, terms):
key = str(i)
df[key] = frame_data[i]
return df return df
# ------------- # -------------
@ -97,7 +87,7 @@ def illustrate_share_of_wealth():
print("\n") print("\n")
df = get_balances_over_time ( df = get_balances_over_time (
participants, balances, compounding_interest participants, balances, compounding_interest(balances)
) )
# print(it) # print(it)
df["share"] = [val * 100 for val in calc_share_of_wealth(df["3"]) ] df["share"] = [val * 100 for val in calc_share_of_wealth(df["3"]) ]
@ -112,7 +102,7 @@ def illustrate_share_of_wealth():
print("\n") print("\n")
df = get_balances_over_time ( df = get_balances_over_time (
participants, balances, ubi participants, balances, ubi(balances)
) )
print(df.to_html()) print(df.to_html())
@ -131,8 +121,7 @@ def visualize_ubi(terms=25):
balances = [100,40,20] balances = [100,40,20]
df = get_balances_over_time ( df = get_balances_over_time (
participants, balances, ubi, participants, balances, ubi(balances, terms=terms)
terms = terms
) )
# print(df.keys) # print(df.keys)
shares = [] shares = []
@ -143,9 +132,12 @@ def visualize_ubi(terms=25):
continue continue
shares.append(calc_share_of_wealth(data)) shares.append(calc_share_of_wealth(data))
sow = pd.DataFrame(shares) sow = pd.DataFrame(shares)
# print(sow.keys()) x = [i for i in range(0,terms)]
x = [i for i in range(1,terms)] try:
assert(len(x) == len(shares)) assert(len(x) == len(shares))
except AssertionError:
print(len(x), len(shares))
exit()
plt.style.use('dark_background') plt.style.use('dark_background')
plt.plot( plt.plot(
@ -183,19 +175,23 @@ def draw_specific_chart1(terms=50, linear_label="? (linear)"):
balances = [100,40,20] balances = [100,40,20]
df = get_balances_over_time ( df = get_balances_over_time (
participants, balances, ubi, participants, balances, ubi(balances, terms=terms)
terms = terms
) )
total_supply_ubi = calc_total_supply(df) total_supply_ubi = calc_total_supply(df)
df_si = get_balances_over_time ( df_si = get_balances_over_time (
participants, balances, compounding_interest, participants, balances,
terms = terms compounding_interest(balances, terms=terms)
) )
total_supply_si = calc_total_supply(df_si) total_supply_si = calc_total_supply(df_si)
# + 1 because the initial frame is included this time # + 1 because the initial frame is included this time
x = [i for i in range(1,terms+1)] x = [i for i in range(0,terms+1)]
assert(len(x) == len(total_supply_si)) try:
assert(len(x) == len(total_supply_si))
except AssertionError:
print(len(x), len(total_supply_si))
print(df_si)
exit()
plt.style.use('dark_background') plt.style.use('dark_background')
plt.plot( plt.plot(
@ -206,9 +202,7 @@ def draw_specific_chart1(terms=50, linear_label="? (linear)"):
calc_total_supply(get_balances_over_time( calc_total_supply(get_balances_over_time(
participants, participants,
balances, balances,
compounding_interest, compounding_interest(balances, terms=terms, rate=0.04)
terms=terms,
param=0.04
)), )),
color="orange", label="apy = 0.04" color="orange", label="apy = 0.04"
) )
@ -217,9 +211,7 @@ def draw_specific_chart1(terms=50, linear_label="? (linear)"):
calc_total_supply(get_balances_over_time( calc_total_supply(get_balances_over_time(
participants, participants,
balances, balances,
compounding_interest, compounding_interest(balances, terms=terms, rate=0.03)
terms=terms,
param=0.03
)), )),
color="yellow", label="apy = 0.03" color="yellow", label="apy = 0.03"
) )
@ -236,18 +228,17 @@ def draw_specific_chart2(terms=50):
balances = [100,40,20] balances = [100,40,20]
df = get_balances_over_time ( df = get_balances_over_time (
participants, balances, ubi, participants, balances, ubi(balances, terms=terms)
terms = terms
) )
total_supply_ubi = calc_total_supply(df) total_supply_ubi = calc_total_supply(df)
df_si = get_balances_over_time ( df_si = get_balances_over_time (
participants, balances, compounding_interest, participants, balances,
terms = terms compounding_interest(balances, terms=terms)
) )
total_supply_si = calc_total_supply(df_si) total_supply_si = calc_total_supply(df_si)
# + 1 because the initial frame is included this time # + 1 because the initial frame is included this time
x = [i for i in range(1,terms+1)] x = [i for i in range(0,terms+1)]
assert(len(x) == len(total_supply_si)) assert(len(x) == len(total_supply_si))
plt.style.use('dark_background') plt.style.use('dark_background')
@ -259,9 +250,7 @@ def draw_specific_chart2(terms=50):
calc_total_supply(get_balances_over_time( calc_total_supply(get_balances_over_time(
participants, participants,
balances, balances,
ubi, ubi(balances, rate=5, terms=terms)
terms=terms,
param=5
)), )),
color="violet", label="dividend = 5" color="violet", label="dividend = 5"
) )
@ -270,9 +259,7 @@ def draw_specific_chart2(terms=50):
calc_total_supply(get_balances_over_time( calc_total_supply(get_balances_over_time(
participants, participants,
balances, balances,
ubi, ubi(balances, rate=15, terms=terms)
terms=terms,
param=15
)), )),
color="lightgreen", label="dividend = 15" color="lightgreen", label="dividend = 15"
) )
@ -284,9 +271,7 @@ def draw_specific_chart2(terms=50):
calc_total_supply(get_balances_over_time( calc_total_supply(get_balances_over_time(
participants, participants,
balances, balances,
compounding_interest, compounding_interest(balances, rate=0.04, terms=terms)
terms=terms,
param=0.04
)), )),
color="orange", label="apy = 0.04" color="orange", label="apy = 0.04"
) )
@ -295,9 +280,7 @@ def draw_specific_chart2(terms=50):
calc_total_supply(get_balances_over_time( calc_total_supply(get_balances_over_time(
participants, participants,
balances, balances,
compounding_interest, compounding_interest(balances, rate=0.03, terms=terms),
terms=terms,
param=0.03
)), )),
color="yellow", label="apy = 0.03" color="yellow", label="apy = 0.03"
) )
@ -319,7 +302,6 @@ def visualize_inflation(df, title="Inflation", filename="inflation.png"):
plt.plot( plt.plot(
x, supply_over_time, color="red") x, supply_over_time, color="red")
plt.title(title) plt.title(title)
plt.legend()
plt.xlabel("Terms") plt.xlabel("Terms")
plt.ylabel("Total Currency") plt.ylabel("Total Currency")
plt.savefig(filename) plt.savefig(filename)
@ -373,7 +355,10 @@ if __name__ == "__main__":
participants = ["Alice", "Bob", "Charlie"] participants = ["Alice", "Bob", "Charlie"]
balances = [100,40,20] balances = [100,40,20]
m = get_balances_over_time(participants, balances, mining, terms=10) m = get_balances_over_time(
participants, balances,
mining(balances, halving_frequency=1, terms=10)
)
print(m) print(m)
print(m.shape[1]) print(m.shape[1])
visualize_inflation(m, title="Inflation Given block_reward = 10 and Halving Every Term", filename="inflation-pow.png") visualize_inflation(m, title="Inflation Given block_reward = 10 and Halving Every Term", filename="inflation-pow.png")