(initial) prints html tables of balances over time

This commit is contained in:
likho 2025-08-23 19:23:41 -07:00
commit 2355d79e60

89
econ-demo.py Normal file
View File

@ -0,0 +1,89 @@
import pandas as pd
def simple_interest(balances, rate=0.05, terms=3):
if terms <= 0:
print("Number of terms must be >0!")
return
new_bal = []
for balance in balances:
b = balance
for i in range(0,terms):
b = b + (b * rate)
new_bal.append(b)
return new_bal
def share_of_wealth(balances):
total_money = sum(balances)
shares = []
for balance in balances:
shares.append(balance/total_money)
return shares
def ubi(balances, dividend=10, terms=3):
new_bal = []
for balance in balances:
b = balance
for i in range(0,terms):
b = b + dividend
new_bal.append(b)
return new_bal
def get_balances_over_time(names, balances, func):
if func is None:
print("Need a function!")
return
if len(names) != len(balances):
print("Every person needs a balance.")
return
data = {
'name' : names,
'initial' : balances
}
df = pd.DataFrame(data)
for t in range(1,4):
key = "term%i" % t
frame = func(balances, terms=t)
if frame is not None:
df[key] = frame
return df
# -------------
def illustrate_share_of_wealth():
participants = ["Alice", "Bob", "Charlie"]
balances = [100,40,20]
print("In this demo, we have three participants.\n", participants)
print("They respectively have ", balances)
print("\nThe initial distribution of wealth is ")
print(share_of_wealth(balances))
print("\n")
df = get_balances_over_time (
participants, balances, simple_interest
)
print(df.to_html())
terms = 222
print(f"How much money exists after {terms} terms?")
#### In 222 terms, even C becomes a millionaire.
nb = simple_interest(balances, terms=terms)
print(nb)
print("\n")
df = get_balances_over_time (
participants, balances, ubi
)
print(df.to_html())
print("How much money exists after 999 terms?")
u = ubi(balances, terms=999)
print(u)
print("What is the share of wealth in a UBI economy?")
print(share_of_wealth(u))
illustrate_share_of_wealth()