From 2355d79e6013dae115a072cf5ac0103b7499e2aa Mon Sep 17 00:00:00 2001 From: likho Date: Sat, 23 Aug 2025 19:23:41 -0700 Subject: [PATCH] (initial) prints html tables of balances over time --- econ-demo.py | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 econ-demo.py diff --git a/econ-demo.py b/econ-demo.py new file mode 100644 index 0000000..abeb5c4 --- /dev/null +++ b/econ-demo.py @@ -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()