|
|
|
|
|
import gradio as gr |
|
import matplotlib.pyplot as plt |
|
import numpy as np |
|
import pandas as pd |
|
|
|
|
|
|
|
data = pd.read_excel("graph_data.xlsx", |
|
sheet_name = "Sheet1", |
|
header = 0 |
|
) |
|
|
|
|
|
|
|
data = data.rename(columns = {"Unnamed: 0": "Year"}) |
|
|
|
|
|
|
|
data = data[[ |
|
"Year", |
|
"Total Revenues", |
|
"Debt Balance", |
|
"Revenues ex SS OASDI", |
|
"Average Rate on Federal Debt", |
|
"Net Interest / Revenues (Baseline)", |
|
"Net Interest / Revenues ex SS OASDI (Baseline)" |
|
]] |
|
|
|
print(data) |
|
|
|
|
|
|
|
baseline_interest_rate = 3.67 |
|
|
|
def plot_interest_coverage(interest_rate): |
|
|
|
|
|
yearly_increase = (interest_rate - baseline_interest_rate) / (2054 - 2025) / 100 |
|
|
|
|
|
data["Average Rate on Federal Debt (Projected)"] = np.where( |
|
data["Year"].astype(int) < 2026, |
|
data["Average Rate on Federal Debt"], |
|
data["Average Rate on Federal Debt"] + (yearly_increase * (data["Year"].astype(int) - 2025))) |
|
|
|
|
|
data["Net Interest / Revenues (Projected)"] = np.where( |
|
data["Year"].astype(int) < 2026, |
|
data["Net Interest / Revenues (Baseline)"], |
|
data["Average Rate on Federal Debt (Projected)"] * data["Debt Balance"] / data["Total Revenues"]) |
|
|
|
|
|
data["Net Interest / Revenues ex SS OASDI (Projected)"] = np.where( |
|
data["Year"].astype(int) < 2026, |
|
data["Net Interest / Revenues ex SS OASDI (Baseline)"], |
|
data["Average Rate on Federal Debt (Projected)"] * data["Debt Balance"] / data["Revenues ex SS OASDI"]) |
|
|
|
|
|
plt.figure(figsize = (10, 4.8)) |
|
|
|
plt.plot( |
|
data["Year"], |
|
data["Average Rate on Federal Debt"], |
|
color = "Green", |
|
label = "Average Rate on Federal Debt" |
|
) |
|
|
|
plt.plot( |
|
data["Year"], |
|
data["Average Rate on Federal Debt (Projected)"], |
|
color = "Green", |
|
label = "Average Rate on Federal Debt (Projected)", |
|
linestyle = "--" |
|
) |
|
|
|
plt.plot( |
|
data["Year"], |
|
data["Net Interest / Revenues (Baseline)"], |
|
color = "Blue", |
|
label = "Net Interest / Revenues (Baseline)" |
|
) |
|
|
|
plt.plot( |
|
data["Year"], |
|
data["Net Interest / Revenues (Projected)"], |
|
color = "Blue", |
|
label = "Net Interest / Revenues (Projected)", |
|
linestyle = "--" |
|
) |
|
|
|
plt.plot( |
|
data["Year"], |
|
data["Net Interest / Revenues ex SS OASDI (Baseline)"], |
|
color = "Orange", |
|
label = "Net Interest / Revenues ex SS OASDI (Baseline)" |
|
) |
|
|
|
plt.plot( |
|
data["Year"], |
|
data["Net Interest / Revenues ex SS OASDI (Projected)"], |
|
color = "Orange", |
|
label = "Net Interest / Revenues ex SS OASDI (Projected)", |
|
linestyle = "--" |
|
) |
|
plt.title("Interest as Share of Revenues Through 2054") |
|
plt.legend(loc = "upper left") |
|
plt.ylim(0, 1.05) |
|
plt.yticks(np.arange(0, 1.1, 0.1)) |
|
plt.xticks(range(1940,2055,4), rotation = 45) |
|
plt.axvline(x = 2024, color = "black") |
|
plt.grid(True, axis = 'y', linestyle = '--', linewidth = 0.7) |
|
|
|
|
|
plt.savefig("interest_coverage.png") |
|
plt.close() |
|
|
|
|
|
return "interest_coverage.png" |
|
|
|
|
|
interest_rate_lowerbound = 0 |
|
interest_rate_upperbound = 15 |
|
|
|
with gr.Blocks() as interface: |
|
|
|
graph = gr.Image(type="filepath", label = "Graph", value = plot_interest_coverage(baseline_interest_rate)) |
|
|
|
|
|
interest_rate_slider = gr.Slider( |
|
interest_rate_lowerbound, |
|
interest_rate_upperbound, |
|
step = .1, |
|
value = baseline_interest_rate, |
|
label = "2054 Projected Average Interest Rate on Federal Debt" |
|
) |
|
|
|
gr.Markdown('<p style="font-size:11px;">Source: CBO June 2024 An Update to the Budget and Economic Outlook: 2024 to 2034, March 2024 report The Long-Term Budget Outlook: 2024 to 2054, and author\'s calculations. Scenario of higher interest rate is author\'s calculations. Data points for 2035-2054 calculated to build on CBO\'s June 2024 10-year update and be consistent with the March 2024 long-term report. Historical Social Security OASDI payroll tax revenue from Table 4-3 of the SSA\'s Trust Fund Data, and projections from the CBO\'s August 2024 Long Term Projections for Social Security.</p>') |
|
|
|
|
|
interest_rate_slider.change( |
|
plot_interest_coverage, |
|
inputs = interest_rate_slider, |
|
outputs = graph |
|
) |
|
|
|
|
|
interface.launch(share = True) |
|
|
|
|
|
|