Skip to content

Commit

Permalink
Add more years and uprate inputs
Browse files Browse the repository at this point in the history
Fixes #31
  • Loading branch information
PavelMakarchuk committed Oct 27, 2024
1 parent ea4eb0b commit 5a7266c
Show file tree
Hide file tree
Showing 7 changed files with 484 additions and 86 deletions.
44 changes: 34 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,23 @@
format_credit_components,
)
from config import APP_TITLE, NOTES, REFORMS_DESCRIPTION, BASELINE_DESCRIPTION
from utils import AVAILABLE_YEARS, BASE_YEAR, uprate_inputs

# Page setup
st.set_page_config(page_title=APP_TITLE, page_icon="👪", layout="wide")
st.title(APP_TITLE)
st.markdown(BASELINE_DESCRIPTION)
st.markdown("## Enter your current household information")
st.markdown("*Please enter annual amounts for the tax year 2024*")

# In app.py - Update year selector
selected_year = st.selectbox(
"Select policy year",
AVAILABLE_YEARS,
index=0, # Default to 2025
help="Select the year for which you want to calculate policy impacts. Your input values will be automatically adjusted for inflation from 2024."
)

st.markdown(f"## Enter your household information for {BASE_YEAR}")
st.markdown(f"*Values will be automatically adjusted for inflation to {selected_year}*")

# Render form sections
personal_col, income_col = st.columns(2)
Expand All @@ -27,30 +37,44 @@

with income_col:
st.markdown("### Income Information")
income, social_security, capital_gains = render_income_inputs()
income, social_security, capital_gains, spouse_income = render_income_inputs(is_married)
itemized_deductions = render_itemized_deductions()

# Calculate button
if st.button("Calculate my household income"):
chart_placeholder = st.empty()
progress_text = st.empty()

# Prepare inputs
inputs = {
# First collect all non-monetary inputs
base_inputs = {
"state": state,
"is_married": is_married,
"child_ages": child_ages,
"head_age": head_age,
"spouse_age": spouse_age,
}

# Collect all monetary inputs (these will be uprated)
monetary_inputs = {
"income": income,
"spouse_income": spouse_income,
"social_security": social_security,
"capital_gains": capital_gains, # Add this line
**itemized_deductions,
"capital_gains": capital_gains,
**itemized_deductions, # Contains all the itemized deduction amounts
}

# Combine all inputs
inputs = {
**base_inputs,
**monetary_inputs,
"year": selected_year, # Add selected year
}

# Calculate and display results
summary_results, results_df = calculate_reforms(
inputs, progress_text, chart_placeholder
inputs,
progress_text,
chart_placeholder,
)

# Display reform details
Expand All @@ -67,11 +91,11 @@

with tab2:
# Display credit components
credit_df = format_credit_components(results_df, state) # Pass the state code
credit_df = format_credit_components(results_df, state)
if credit_df is not None:
st.markdown(credit_df.to_markdown())
else:
st.markdown("### No changes in credit components")

st.markdown(NOTES)
progress_text.empty()
progress_text.empty()
28 changes: 25 additions & 3 deletions calculator.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
import pandas as pd
from results import calculate_consolidated_results
from graph import create_reform_comparison_graph
from utils import MAIN_METRICS, format_credit_name, format_currency
from utils import MAIN_METRICS, format_credit_name, format_currency, uprate_inputs, BASE_YEAR
import streamlit as st


def calculate_reforms(inputs, progress_text, chart_placeholder):
summary_results = {}
selected_year = inputs.pop("year") # Extract year from inputs

# Uprate the inputs from 2024 to selected year
monetary_inputs = {
"income": inputs["income"],
"spouse_income": inputs["spouse_income"],
"social_security": inputs["social_security"],
"capital_gains": inputs["capital_gains"],
"medical_expenses": inputs["medical_expenses"],
"real_estate_taxes": inputs["real_estate_taxes"],
"interest_expense": inputs["interest_expense"],
"charitable_cash": inputs["charitable_cash"],
"charitable_non_cash": inputs["charitable_non_cash"],
"qualified_business_income": inputs["qualified_business_income"],
"casualty_loss": inputs["casualty_loss"],
}

uprated = uprate_inputs(monetary_inputs, BASE_YEAR, selected_year)

# Update inputs with uprated values
inputs.update(uprated)

# Calculate baseline first to get all possible metrics
progress_text.text("Calculating Baseline...")
baseline_results = calculate_consolidated_results("Baseline", **inputs)
baseline_results = calculate_consolidated_results("Baseline", year=selected_year, **inputs)

# Initialize DataFrame with all metrics from baseline results
results_df = pd.DataFrame(
Expand All @@ -30,7 +51,7 @@ def calculate_reforms(inputs, progress_text, chart_placeholder):
# Calculate other reforms
for reform in ["Harris", "Trump"]:
progress_text.text(f"Calculating {reform}...")
reform_results = calculate_consolidated_results(reform, **inputs)
reform_results = calculate_consolidated_results(reform, year=selected_year, **inputs)

# Update results for all metrics
for idx in results_df.index:
Expand All @@ -47,6 +68,7 @@ def calculate_reforms(inputs, progress_text, chart_placeholder):
return summary_results, results_df



def format_detailed_metrics(results_df):
formatted_df = results_df.copy()
formatted_df = formatted_df.loc[MAIN_METRICS]
Expand Down
9 changes: 7 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@
The Trump platform includes:
- **Social Security Tax Exemption**: Eliminating taxes on Social Security benefits for senior citizens
[Learn more about the Social Security proposal](https://policyengine.org/us/research/social-security-tax-exemption)
- **TCJA Extension**: Making permanent the Tax Cuts and Jobs Act provisions that are set to expire in 2026
"""

NOTES = """
### Assumptions and Notes:
- All calculations are based on projected 2025 tax parameters.
- All calculations are based on projected tax parameters for the selected year (2024-2028).
- The baseline scenario assumes TCJA provisions expire as scheduled after 2025.
- All input values are entered in 2024 dollars and automatically adjusted for inflation:
- A 3% annual inflation rate is applied to all monetary inputs
- The calculator assumes all income is from employment (wages and salaries).
- Whether to use standard or itemized deductions is calculated based on the user input.
- The calculator uses the PolicyEngine US microsimulation model.
- Tax parameters are adjusted for inflation based on CBO projections.
- Actual impacts may vary based on individual circumstances and final policy implementations.
- Proposals are modeled based on currently available information and may be updated as more details are released.
"""
"""
Loading

0 comments on commit 5a7266c

Please sign in to comment.