Spaces:
Sleeping
Sleeping
File size: 8,292 Bytes
4e96673 9e7ecad 4e96673 7dbf796 9e7ecad 4e96673 7dbf796 4e96673 9e7ecad 4e96673 9e7ecad 4e96673 9e7ecad 4e96673 9e7ecad 4e96673 9e7ecad 4e96673 9e7ecad 4e96673 9e7ecad 4e96673 9e7ecad 4e96673 7ff0ba0 4e96673 7ff0ba0 4e96673 7dbf796 9e7ecad 4e96673 7dbf796 4e96673 7dbf796 4e96673 | 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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | import streamlit as st
import plotly.express as px
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
from metrics_calculations import (
users, monthly_budget, monthly_expenses, savings_rate, debt_overview,
cash_flow, portfolio_value, asset_allocation, dividend_income,
performance_chart, proj_retirement_savings
)
monthly_budget = monthly_budget()
monthly_expenses = monthly_expenses()
savings_rate = savings_rate()
debt_overview = debt_overview()
cash_flow = cash_flow()
portfolio_value = portfolio_value()
asset_allocation = asset_allocation()
dividend_income = dividend_income()
performance_chart = performance_chart()
proj_retirement_savings = proj_retirement_savings()
st.set_page_config(
page_title="Finetech Dashboard",
layout="wide"
)
st.title("Finetech Dashboard")
selected_user = st.selectbox("Select User", users)
with st.container():
fig1, fig2 = st.columns(2)
with fig1:
st.header("Budget Breakdown")
selected_user_budget = monthly_budget[selected_user]
fig1 = px.bar(
selected_user_budget, x=selected_user_budget.index, y=selected_user_budget.values,
labels={'x': 'Categories', 'y': 'Spendings'},
title=f'User {selected_user}'
)
fig1.update_xaxes(title='Categories', tickangle=45)
fig1.update_layout(
height=500,
width=500
)
st.plotly_chart(fig1)
with fig2:
st.header("Monthly Expenses Over Time")
user_data = monthly_expenses
user_data = user_data[user_data['UserId'] == selected_user]
user_data['Month'] = user_data['Month'].astype(str)
fig2 = px.line(
user_data, x='Month', y='MonthlyExpenses', markers=True, line_shape='linear',
title=f'User {selected_user}',
labels={'MonthlyExpenses': 'Total Monthly Expenses (USD)'}
)
fig2.update_xaxes(title='Date', tickangle=45)
fig2.update_yaxes(title='Total Monthly Expenses (USD)')
fig2.update_layout(
height=500,
width=500
)
st.plotly_chart(fig2)
with st.container():
fig1, fig2 = st.columns(2)
with fig1:
st.header("Savings Rate Over Time")
user_data = savings_rate
user_data = user_data[user_data['UserId'] == selected_user]
user_data['date'] = user_data['date'].dt.strftime('%Y-%m')
fig1 = px.line(
user_data, x='date', y='SavingsRate', markers=True, line_shape='linear',
title=f'User {selected_user}',
labels={'SavingsRate': 'Savings Rate (%)'}
)
fig1.update_xaxes(title='Date', tickangle=45)
fig1.update_yaxes(title='Savings Rate (%)')
fig1.update_layout(
height=500,
width=500
)
st.plotly_chart(fig1)
with fig2:
st.header("Debt Overview")
user_data = debt_overview
user_data = user_data[selected_user]
fig2 = px.bar(
user_data, x='debtType', y='amount',
title=f'User {selected_user}',
labels={'amount': 'Debt Amount (USD)'}
)
fig2.update_xaxes(title='Debt Type', tickangle=45)
fig2.update_yaxes(title='Debt Amount (USD)')
fig2.update_layout(
height=500,
width=500
)
st.plotly_chart(fig2)
with st.container():
fig1, fig2 = st.columns(2)
with fig1:
st.header("Cash Flow Over Time")
user_data = cash_flow
user_data = user_data[user_data['UserId'] == selected_user]
fig1 = px.line(
user_data, x='date', y='CashFlow', markers=True, line_shape='linear',
title=f'User {selected_user}',
labels={'CashFlow': 'Cash Flow (USD)'}
)
fig1.update_xaxes(title='Date', tickangle=45)
fig1.update_yaxes(title='Cash Flow (USD)')
fig1.update_layout(
height=500,
width=500
)
st.plotly_chart(fig1)
with fig2:
st.header("Portfolio Value Over Time")
user_data = portfolio_value
user_data = user_data[user_data['UserId'] == selected_user]
fig2 = px.line(
user_data, x='date', y='balance', markers=True, line_shape='linear',
title=f'User {selected_user}',
labels={'balance': 'Total Portfolio Value (USD)'}
)
fig2.update_xaxes(title='Date', tickangle=45)
fig2.update_yaxes(title='Total Portfolio Value (USD)')
fig2.update_layout(
height=500,
width=500
)
st.plotly_chart(fig2)
with st.container():
fig1, fig2 = st.columns(2)
with fig1:
st.header("Asset Allocation")
user_data = asset_allocation
user_data = user_data[user_data['UserId'] == selected_user]
fig1 = px.pie(
user_data, values='Allocation', names='Asset',
title=f'User {selected_user}',
labels={'Allocation': 'Allocation (USD)'}
)
fig1.update_layout(
height=500,
width=500
)
st.plotly_chart(fig1)
with fig2:
st.header("Dividend Income Over Time")
user_data = dividend_income
user_data = user_data[user_data.index.get_level_values('UserId') == selected_user]
user_data.index = pd.to_datetime([str(idx[1]) for idx in user_data.index])
fig2 = px.line(
user_data, x=user_data.index, y='dividends', markers=True, line_shape='linear',
title=f'User {selected_user}'
)
fig2.update_xaxes(title='Date', tickangle=45)
fig2.update_yaxes(title='Dividend Income (USD)')
fig2.update_layout(showlegend=False)
fig2.update_layout(
height=500,
width=500
)
st.plotly_chart(fig2)
with st.container():
st.header("Performance Chart")
user_data = performance_chart
user_data = user_data[user_data['UserId'] == selected_user]
fig1, fig2 = st.columns(2)
with fig1:
fig1 = go.Figure()
fig1.add_trace(go.Scatter(x=user_data['date'], y=user_data['daily_balance'], mode='lines', name='Daily Balance'))
fig1.update_xaxes(title_text='Date')
fig1.update_yaxes(title_text='Daily Balance')
fig1.update_layout(
height=500,
width=500
)
st.plotly_chart(fig1)
with fig2:
one_month_return = user_data['daily_balance'].pct_change(periods=4) # Assuming 20 trading days in a month
one_year_return = user_data['daily_balance'].pct_change(periods=252) # Assuming 252 trading days in a year
five_year_return = user_data['daily_balance'].pct_change(periods=252 * 5) # Assuming 252 trading days in a year for 5 years
# Create a DataFrame for the returns
returns_df = pd.DataFrame({
'Return Period': ['1-Month', '1-Year', '5-Year'],
'Return Value': [one_month_return.iloc[-1], one_year_return.iloc[-1], five_year_return.iloc[-1]]
})
# Create a bar plot for returns
fig2 = px.bar(returns_df, x='Return Period', y='Return Value', text='Return Value', labels={'Return Value': 'Return'})
fig2.update_traces(texttemplate='%{text:.2%}', textposition='outside')
fig2.update_xaxes(title_text='Return Period')
fig2.update_yaxes(title_text='Return')
fig2.update_layout(
height=500,
width=500
)
# Display both charts
st.plotly_chart(fig2)
with st.container():
st.header("Projected Retirement Savings")
user_data = proj_retirement_savings
user_data = user_data[user_data["UserId"] == selected_user]
fig = px.bar(user_data, x='UserId', y='ProjectedSavings',
labels={'UserId': 'User ID', 'ProjectedSavings': 'Total Projected Retirement Savings'},
title='Total Projected Retirement Savings by User')
fig.update_xaxes(tickmode='linear', dtick=1)
fig.update_yaxes(tickformat=',f')
fig.update_yaxes(tickformat=',.2f')
fig.update_layout(
height=600,
width=400
)
st.plotly_chart(fig)
|