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