-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheconomic_model.py
61 lines (53 loc) · 2.04 KB
/
economic_model.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
import numpy as np
import matplotlib.pyplot as plt
def economic_collapse(gdp, unemployment, recovery_rate, intervention_days, days):
"""
Simulates economic decline and recovery.
Parameters:
gdp: Initial GDP (arbitrary units)
unemployment: Initial unemployment rate (percentage, 0-100)
recovery_rate: Rate of recovery per day
intervention_days: List of days where interventions occur (stimulus packages)
days: Total days to simulate
Returns:
A dictionary of daily GDP and unemployment rates
"""
gdp_vals, unemployment_vals = [gdp], [unemployment]
intervention_effect = 0.05 # % GDP growth per intervention
for day in range(days):
# Simulate natural decline
gdp -= gdp * 0.01 # 1% daily GDP loss
unemployment += 0.2 # 0.2% daily unemployment rise
# Apply intervention effects
if day in intervention_days:
gdp += gdp * intervention_effect
unemployment -= 1 # Reduce unemployment by 1%
# Recovery phase
gdp += gdp * recovery_rate
unemployment = max(0, unemployment - recovery_rate * 10)
gdp_vals.append(gdp)
unemployment_vals.append(unemployment)
return {
"GDP": gdp_vals,
"Unemployment": unemployment_vals,
}
# def plot_economy(data, days):
# plt.figure(figsize=(10, 6))
# plt.plot(data["GDP"], label="GDP")
# plt.plot(data["Unemployment"], label="Unemployment Rate (%)", linestyle="--")
# plt.xlabel("Days")
# plt.ylabel("Metrics")
# plt.title("Economic Collapse and Recovery Simulation")
# plt.legend()
# plt.grid()
# plt.show()
def plot_economy(data, days):
fig, ax = plt.subplots(figsize=(10, 6)) # Create a figure and axes
ax.plot(data["GDP"], label="GDP")
ax.plot(data["Unemployment"], label="Unemployment Rate (%)", linestyle="--")
ax.set_xlabel("Days")
ax.set_ylabel("Metrics")
ax.set_title("Economic Collapse and Recovery Simulation")
ax.legend()
ax.grid()
return fig # Return the figure object