-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
81 lines (65 loc) · 2.61 KB
/
app.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Run this app with `python app.py` and
# visit http://127.0.0.1:8050/ in your web browser.
from dash import Dash, html, dcc, Input, Output
import plotly.express as px
import pandas as pd
from scr.logic import asset_over_time_apy
app = Dash(__name__)
colors = {"background": "#111111", "text": "#7FDBFF"}
app.layout = html.Div(
children=[
html.Div(
children=[
html.H1(
"Annual Interest Yiled Calculator",
style={"textAlign": "center", "color": colors["text"]},
),
html.Br(),
html.Label(
"Initial Investment [P]",
style={"textAlign": "center", "color": colors["text"]},
),
dcc.Input(id="initial-investment", value=1000, type="number"),
html.Br(),
html.Label(
"Annual Interest Rate [r]",
style={"textAlign": "center", "color": colors["text"]},
),
dcc.Input(id="annual-interest-rate", value=0.05, type="number"),
html.Br(),
html.Label(
"Number of compounding periods per year [n]",
style={"textAlign": "center", "color": colors["text"]},
),
dcc.Input(id="compounding-periods-per-year", value=12, type="number"),
html.Br(),
html.Label(
"Number of years [t]",
style={"textAlign": "center", "color": colors["text"]},
),
dcc.Input(id="number-of-years", value=10, type="number"),
dcc.Graph(id="asset-apy-over-time"),
],
style={"padding": 10, "flex": 1, "backgroundColor": colors["background"]},
),
],
style={
"display": "flex",
"flex-direction": "row",
"backgroundColor": colors["background"],
},
)
@app.callback(
Output(component_id="asset-apy-over-time", component_property="figure"),
Input(component_id="initial-investment", component_property="value"),
Input(component_id="annual-interest-rate", component_property="value"),
Input(component_id="compounding-periods-per-year", component_property="value"),
Input(component_id="number-of-years", component_property="value"),
)
def update_figure(P, r, n, t):
df = asset_over_time_apy(P=P, r=r, n=n, t=t)
fig = px.scatter(data_frame=df, x="time", y="value", size_max=55)
fig.update_layout(transition_duration=500)
return fig
if __name__ == "__main__":
app.run_server(debug=True)