-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
145 lines (120 loc) · 5.67 KB
/
Copy pathapp.py
File metadata and controls
145 lines (120 loc) · 5.67 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import streamlit as st
import pandas as pd
import numpy as np
import plotly.graph_objects as go
from financial_model import calculate_mall_economics
from report_generator import create_pdf_report
st.set_page_config(page_title="WestProp Financial Twin (Pro)", layout="wide", page_icon="🏦")
st.markdown("""
<style>
.metric-box {padding:10px; background-color:#f0f2f6; border-radius:5px;}
</style>
""", unsafe_allow_html=True)
# --- SIDEBAR: INITIALIZATION ---
if 'cost_key' not in st.session_state: st.session_state.cost_key = 180
if 'rent_key' not in st.session_state: st.session_state.rent_key = 28.0
if 'vac_key' not in st.session_state: st.session_state.vac_key = 8
if 'ltv_key' not in st.session_state: st.session_state.ltv_key = 50
if 'int_key' not in st.session_state: st.session_state.int_key = 11.0
def reset_simulation():
st.session_state.cost_key = 180
st.session_state.rent_key = 28.0
st.session_state.vac_key = 8
st.session_state.ltv_key = 50
st.session_state.int_key = 11.0
if st.sidebar.button("🔄 Reset Defaults", on_click=reset_simulation):
pass
st.sidebar.header("🏗️ Project Inputs")
cost_input = st.sidebar.slider("Total Capex ($M)", 100, 300, step=5, key="cost_key") * 1_000_000
rent_input = st.sidebar.slider("Start Rent ($/sqm)", 15.0, 50.0, step=0.5, key="rent_key")
vacancy_input = st.sidebar.slider("Vacancy (%)", 0, 30, step=1, key="vac_key") / 100
st.sidebar.divider()
st.sidebar.header("🏦 Bank Structure (Debt)")
ltv_input = st.sidebar.slider("Loan-to-Value (%)", 0, 80, step=5, key="ltv_key") / 100
interest_input = st.sidebar.slider("Interest Rate (%)", 5.0, 18.0, step=0.5, key="int_key") / 100
escalation_input = 0.03 # Hardcoded 3% annual inflation for simplicity
st.sidebar.divider()
# --- CALCULATE ENGINE ---
data = calculate_mall_economics(
cost_input, rent_input, vacancy_input, 0.20,
ltv_input, interest_input, escalation_input
)
cash_flows = data["Cash_Flows"]
equity_irr = data["Equity_IRR"]
# --- PDF GENERATOR BUTTON ---
if st.sidebar.button("Generate Investment Memo"):
cumulative_cash = np.cumsum(cash_flows)
break_even_index = next((i for i, x in enumerate(cumulative_cash) if x >= 0), None)
real_break_year = f"Year {break_even_index}" if break_even_index else "Never"
pdf_bytes = create_pdf_report(
cost_input,
rent_input,
vacancy_input,
0.20, # OpEx (hardcoded or slider)
equity_irr,
sum(cash_flows), # Total Profit
real_break_year,
cash_flows,
ltv_input, # <--- NEW: Send LTV
interest_input # <--- NEW: Send Interest
)
st.sidebar.download_button("📥 Download Report", pdf_bytes, "Mall_Strategy_Report.pdf", "application/pdf")
# --- MAIN DASHBOARD ---
st.title("🏦 Mall of Zimbabwe: Leveraged Investment Model")
st.markdown(f"**Debt Structure:** {ltv_input*100:.0f}% Loan @ {interest_input*100:.1f}% Interest | **Inflation:** 3% p.a.")
# 1. CALCULATE BREAK-EVEN (Logic moved up so we can use it in metrics)
cumulative_cash = np.cumsum(cash_flows)
break_even_index = next((i for i, x in enumerate(cumulative_cash) if x >= 0), None)
dashboard_break_year = f"Year {break_even_index}" if break_even_index else "> 12 Years"
# 2. METRICS ROW (Now with 5 Columns)
col1, col2, col3, col4, col5 = st.columns(5)
# Color Logic for IRR
irr_color = "normal"
if equity_irr >= 20: irr_color = "normal"
elif equity_irr < 10: irr_color = "off"
col1.metric("Equity IRR", f"{equity_irr:.2f}%", f"{equity_irr - data['Project_IRR']:.1f}% vs Project", delta_color=irr_color)
col2.metric("Equity Required", f"${data['Equity_Required']/1_000_000:.1f} M")
col3.metric("Bank Loan", f"${data['Loan_Amount']/1_000_000:.1f} M")
col4.metric("Equity Multiple", f"{data['Equity_Multiple']:.2f}x")
col5.metric("Payback Period", dashboard_break_year) # <--- IT IS BACK!
st.divider()
# --- TABS ---
tab1, tab2 = st.tabs(["🔥 Risk Heatmap", "📊 Cash Flow Waterfall"])
with tab1:
st.subheader("Sensitivity: How does Rent impact Investor Returns?")
costs = np.linspace(100_000_000, 300_000_000, 10)
rents = np.linspace(15, 50, 10)
z_values = []
for r in rents:
row = []
for c in costs:
# Recalculate full model for every pixel
res = calculate_mall_economics(c, r, vacancy_input, 0.20, ltv_input, interest_input, 0.03)
row.append(res["Equity_IRR"])
z_values.append(row)
fig = go.Figure(data=go.Heatmap(
z=z_values,
x=[f"${c/1e6:.0f}M" for c in costs],
y=[f"${r:.0f}" for r in rents],
colorscale='RdYlGn', zmin=0, zmax=30,
colorbar=dict(title='Equity IRR %')
))
fig.update_layout(xaxis_title="Total Project Cost", yaxis_title="Start Rent ($/sqm)")
st.plotly_chart(fig, use_container_width=True)
with tab2:
st.subheader("Net Cash Flow to Investors (After Debt Service)")
years = [f"Y{i+1}" for i in range(len(cash_flows))]
colors = ['crimson' if x < 0 else 'forestgreen' for x in cash_flows]
fig_cf = go.Figure(data=[go.Bar(
x=years, y=cash_flows, marker_color=colors,
hovertemplate='$%{y:,.0f}<extra></extra>'
)])
fig_cf.update_layout(yaxis_title="Net Equity Cash Flow ($)")
st.plotly_chart(fig_cf, use_container_width=True)
# Cumulative Line
# (We already calculated 'cumulative_cash' at the top, so we just plot it)
fig_cum = go.Figure()
fig_cum.add_trace(go.Scatter(x=years, y=cumulative_cash, mode='lines+markers', line=dict(color='blue', width=3)))
fig_cum.add_hline(y=0, line_dash="dash", line_color="red")
fig_cum.update_layout(title="Time to Break-Even on Equity", yaxis_title="Cumulative Wealth ($)")
st.plotly_chart(fig_cum, use_container_width=True)