-
Notifications
You must be signed in to change notification settings - Fork 1
/
donation_simulation.py
70 lines (57 loc) · 2.12 KB
/
donation_simulation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from policyengine_us import Simulation
from constants import CURRENT_YEAR
def create_donation_simulation(situation, donation_amount):
"""
Creates a simulation with the specified donation amount.
Args:
situation (dict): Base situation dictionary
donation_amount (float): Amount of charitable donation
Returns:
Simulation: PolicyEngine simulation object with donation
"""
# Create a copy of the situation to avoid modifying the original
donation_situation = situation.copy()
# Add the donation amount
donation_situation["people"]["you"]["charitable_cash_donations"] = {
CURRENT_YEAR: donation_amount
}
# Remove any axes if they exist
if "axes" in donation_situation:
del donation_situation["axes"]
# Create and return the simulation
return Simulation(situation=donation_situation)
def display_results(
baseline_net_income, actual_net_income, donation_amount, marginal_savings
):
"""
Displays the results of the donation simulation.
Args:
baseline_net_income (float): Net income without donations
actual_net_income (float): Net income with donations
donation_amount (float): Amount donated
marginal_savings (float): Marginal cost of giving at target donation
"""
import pandas as pd
import streamlit as st
# Display net income values
st.write(f"Household net income with no donations: ${int(baseline_net_income):,}")
st.write(
f"Household net income with ${donation_amount:,} donation: "
f"${int(actual_net_income - donation_amount):,}"
)
# Create and display results table
results_df = pd.DataFrame(
{
"Metric": [
"Household net income without donations",
"Actual net income after donation",
"Marginal cost of giving at target donation",
],
"Amount": [
f"${int(baseline_net_income):,}",
f"${int(actual_net_income):,}",
f"${marginal_savings:.2f}",
],
}
).set_index("Metric")
st.dataframe(results_df)