Update app.py
Browse files
app.py
CHANGED
|
@@ -123,7 +123,7 @@ def plot_ladder(df: pd.DataFrame):
|
|
| 123 |
ax.bar(pivot.index, assets, label="Assets")
|
| 124 |
ax.bar(pivot.index, -sof, label="SoF")
|
| 125 |
ax.axhline(0, color="gray", lw=1)
|
| 126 |
-
ax.set_ylabel("LKR (
|
| 127 |
ax.set_title("Maturity Ladder (Assets vs SoF)")
|
| 128 |
ax.legend()
|
| 129 |
fig.tight_layout()
|
|
@@ -156,7 +156,7 @@ SELECT
|
|
| 156 |
ELSE 'T+31+'
|
| 157 |
END AS time_bucket,
|
| 158 |
bucket,
|
| 159 |
-
SUM(Portfolio_value) AS
|
| 160 |
FROM {VIEW_FQN}
|
| 161 |
GROUP BY 1,2
|
| 162 |
ORDER BY 1,2;
|
|
@@ -173,7 +173,7 @@ def irr_sql(cols: List[str]) -> str:
|
|
| 173 |
return f"""
|
| 174 |
SELECT
|
| 175 |
bucket,
|
| 176 |
-
SUM(Portfolio_value) / 1000000.0 AS "Portfolio Value (
|
| 177 |
FROM {VIEW_FQN}
|
| 178 |
GROUP BY bucket
|
| 179 |
"""
|
|
@@ -210,20 +210,27 @@ def run_dashboard() -> Tuple[str, str, str, str, str, Any, pd.DataFrame, pd.Data
|
|
| 210 |
# 4) Ladder & IRR
|
| 211 |
ladder = conn.execute(LADDER_SQL).fetchdf()
|
| 212 |
irr = conn.execute(irr_sql(cols)).fetchdf()
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
irr["Portfolio Value (mn)"] = irr["Portfolio Value (mn)"].map('{:,.2f}'.format)
|
| 216 |
|
| 217 |
# 5) Chart
|
| 218 |
fig = plot_ladder(ladder)
|
| 219 |
|
| 220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
return (
|
| 222 |
status,
|
| 223 |
as_of,
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
fig,
|
| 228 |
ladder,
|
| 229 |
irr,
|
|
@@ -258,10 +265,9 @@ with gr.Blocks(title=APP_TITLE) as demo:
|
|
| 258 |
with gr.Row():
|
| 259 |
as_of = gr.Textbox(label="As of date", interactive=False)
|
| 260 |
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
a3 = gr.Textbox(label="Net Gap T+1 (LKR mn)", interactive=False)
|
| 265 |
|
| 266 |
chart = gr.Plot(label="Maturity Ladder")
|
| 267 |
ladder_df = gr.Dataframe(label="Ladder Detail")
|
|
|
|
| 123 |
ax.bar(pivot.index, assets, label="Assets")
|
| 124 |
ax.bar(pivot.index, -sof, label="SoF")
|
| 125 |
ax.axhline(0, color="gray", lw=1)
|
| 126 |
+
ax.set_ylabel("LKR (Mn)")
|
| 127 |
ax.set_title("Maturity Ladder (Assets vs SoF)")
|
| 128 |
ax.legend()
|
| 129 |
fig.tight_layout()
|
|
|
|
| 156 |
ELSE 'T+31+'
|
| 157 |
END AS time_bucket,
|
| 158 |
bucket,
|
| 159 |
+
SUM(Portfolio_value) / 1000000.0 AS "Amount (LKR Mn)"
|
| 160 |
FROM {VIEW_FQN}
|
| 161 |
GROUP BY 1,2
|
| 162 |
ORDER BY 1,2;
|
|
|
|
| 173 |
return f"""
|
| 174 |
SELECT
|
| 175 |
bucket,
|
| 176 |
+
SUM(Portfolio_value) / 1000000.0 AS "Portfolio Value (LKR Mn)"
|
| 177 |
FROM {VIEW_FQN}
|
| 178 |
GROUP BY bucket
|
| 179 |
"""
|
|
|
|
| 210 |
# 4) Ladder & IRR
|
| 211 |
ladder = conn.execute(LADDER_SQL).fetchdf()
|
| 212 |
irr = conn.execute(irr_sql(cols)).fetchdf()
|
| 213 |
+
if "Portfolio Value (LKR Mn)" in irr.columns:
|
| 214 |
+
irr["Portfolio Value (LKR Mn)"] = irr["Portfolio Value (LKR Mn)"].map('{:,.2f}'.format)
|
|
|
|
| 215 |
|
| 216 |
# 5) Chart
|
| 217 |
fig = plot_ladder(ladder)
|
| 218 |
|
| 219 |
+
assets_t1_mn_str = f"{(assets_t1 / 1_000_000):,.2f}"
|
| 220 |
+
sof_t1_mn_str = f"{(sof_t1 / 1_000_000):,.2f}"
|
| 221 |
+
net_gap_mn_str = f"{(net_gap / 1_000_000):,.2f}"
|
| 222 |
+
|
| 223 |
+
a1_text = f"The amount of Assets maturing tomorrow (T+1) is **LKR {assets_t1_mn_str} Mn**."
|
| 224 |
+
a2_text = f"The amount of Sources of Funds (SoF) maturing tomorrow (T+1) is **LKR {sof_t1_mn_str} Mn**."
|
| 225 |
+
a3_text = f"The resulting Net Liquidity Gap for tomorrow (T+1) is **LKR {net_gap_mn_str} Mn**."
|
| 226 |
+
|
| 227 |
+
status = f"Connected to Database (as of {pd.Timestamp.now().strftime('%Y-%m-%d %H:%M:%S')})"
|
| 228 |
return (
|
| 229 |
status,
|
| 230 |
as_of,
|
| 231 |
+
a1_text,
|
| 232 |
+
a2_text,
|
| 233 |
+
a3_text,
|
| 234 |
fig,
|
| 235 |
ladder,
|
| 236 |
irr,
|
|
|
|
| 265 |
with gr.Row():
|
| 266 |
as_of = gr.Textbox(label="As of date", interactive=False)
|
| 267 |
|
| 268 |
+
a1 = gr.Markdown("The amount of Assets maturing tomorrow (T+1) is...")
|
| 269 |
+
a2 = gr.Markdown("The amount of Sources of Funds (SoF) maturing tomorrow (T+1) is...")
|
| 270 |
+
a3 = gr.Markdown("The resulting Net Liquidity Gap for tomorrow (T+1) is...")
|
|
|
|
| 271 |
|
| 272 |
chart = gr.Plot(label="Maturity Ladder")
|
| 273 |
ladder_df = gr.Dataframe(label="Ladder Detail")
|