-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #6
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
|
||
def create_copy_link_div(location_id: str, hidden_div_with_url_id: str, button_id: str, card_name: str): | ||
div = html.Div( | ||
return html.Div( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
[ | ||
# the URL bar, doesn't render anything | ||
dcc.Location(id=location_id, refresh=False), | ||
|
@@ -26,7 +26,9 @@ def create_copy_link_div(location_id: str, hidden_div_with_url_id: str, button_i | |
outline=False, | ||
), | ||
# hidden div to receive output from callback with url | ||
html.Div(children="", hidden=True, id=hidden_div_with_url_id), | ||
html.Div( | ||
children="", hidden=True, id=hidden_div_with_url_id | ||
), | ||
dbc.Tooltip( | ||
f"Copy {card_name} link to clipboard", | ||
target=button_id, | ||
|
@@ -36,4 +38,3 @@ def create_copy_link_div(location_id: str, hidden_div_with_url_id: str, button_i | |
), | ||
] | ||
) | ||
return div |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,8 +47,7 @@ def get_info(al_object) -> dash_table.DataTable: | |
if len(al_object.symbols) < 2: | ||
# no need in "Shortest history" and "Longest history" if only one ticker | ||
info_list = info_list[:3] | ||
info_table = dash_table.DataTable( | ||
return dash_table.DataTable( | ||
data=info_list, | ||
style_data={"whiteSpace": "normal", "height": "auto"}, | ||
) | ||
return info_table | ||
Comment on lines
-50
to
-54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ def card_controls( | |
ccy: Optional[str], | ||
): | ||
tickers_list = get_tickers_list(tickers) | ||
card = dbc.Card( | ||
return dbc.Card( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
dbc.CardBody( | ||
[ | ||
html.H5("Compare Assets", className="card-title"), | ||
|
@@ -43,24 +43,24 @@ def card_controls( | |
html.Label("Tickers to compare"), | ||
dcc.Dropdown( | ||
options=options, | ||
value=tickers_list if tickers_list else settings.default_symbols, | ||
value=tickers_list or settings.default_symbols, | ||
multi=True, | ||
placeholder="Select assets", | ||
id="al-symbols-list", | ||
), | ||
], | ||
] | ||
), | ||
html.Div( | ||
[ | ||
html.Label("Base currency"), | ||
dcc.Dropdown( | ||
options=inflation.get_currency_list(), | ||
value=ccy if ccy else "USD", | ||
value=ccy or "USD", | ||
multi=False, | ||
placeholder="Select a base currency", | ||
id="al-base-currency", | ||
), | ||
], | ||
] | ||
), | ||
html.Div( | ||
[ | ||
|
@@ -71,7 +71,7 @@ def card_controls( | |
html.Label("First Date"), | ||
dbc.Input( | ||
id="al-first-date", | ||
value=first_date if first_date else "2000-01", | ||
value=first_date or "2000-01", | ||
type="text", | ||
), | ||
dbc.FormText("Format: YYYY-MM"), | ||
|
@@ -82,7 +82,7 @@ def card_controls( | |
html.Label("Last Date"), | ||
dbc.Input( | ||
id="al-last-date", | ||
value=last_date if last_date else today_str, | ||
value=last_date or today_str, | ||
type="text", | ||
), | ||
dbc.FormText("Format: YYYY-MM"), | ||
|
@@ -115,9 +115,18 @@ def card_controls( | |
), | ||
dbc.RadioItems( | ||
options=[ | ||
{"label": "Wealth Index", "value": "wealth"}, | ||
{"label": "Rolling Cagr", "value": "cagr"}, | ||
{"label": "Rolling Real Cagr", "value": "real_cagr"}, | ||
{ | ||
"label": "Wealth Index", | ||
"value": "wealth", | ||
}, | ||
{ | ||
"label": "Rolling Cagr", | ||
"value": "cagr", | ||
}, | ||
{ | ||
"label": "Rolling Real Cagr", | ||
"value": "real_cagr", | ||
}, | ||
], | ||
value="wealth", | ||
id="al-plot-option", | ||
|
@@ -175,7 +184,9 @@ def card_controls( | |
value=2, | ||
id="al-rolling-window", | ||
), | ||
dbc.FormText("Format: number of years (≥ 1)"), | ||
dbc.FormText( | ||
"Format: number of years (≥ 1)" | ||
), | ||
dbc.Tooltip( | ||
al_options_window, | ||
target="al-info-rolling", | ||
|
@@ -206,7 +217,6 @@ def card_controls( | |
), | ||
class_name="mb-3", | ||
) | ||
return card | ||
|
||
|
||
@callback( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,11 +32,14 @@ | |
|
||
|
||
def layout(tickers=None, first_date=None, last_date=None, ccy=None, **kwargs): | ||
page = dbc.Container( | ||
return dbc.Container( | ||
[ | ||
dbc.Row( | ||
[ | ||
dbc.Col(card_controls(tickers, first_date, last_date, ccy), lg=7), | ||
dbc.Col( | ||
card_controls(tickers, first_date, last_date, ccy), | ||
lg=7, | ||
), | ||
Comment on lines
-35
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
dbc.Col(card_assets_info, lg=5), | ||
] | ||
), | ||
|
@@ -46,7 +49,6 @@ def layout(tickers=None, first_date=None, last_date=None, ccy=None, **kwargs): | |
class_name="mt-2", | ||
fluid="md", | ||
) | ||
return page | ||
|
||
|
||
@callback( | ||
|
@@ -131,7 +133,7 @@ def get_al_figure(al_object: ok.AssetList, plot_type: str, inflation_on: bool, r | |
if plot_type == "wealth": | ||
df = al_object.wealth_indexes | ||
else: | ||
real = False if plot_type == "cagr" else True | ||
real = plot_type != "cagr" | ||
Comment on lines
-134
to
+136
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
df = al_object.get_rolling_cagr(window=rolling_window * settings.MONTHS_PER_YEAR, real=real) | ||
ind = df.index.to_timestamp("D") | ||
chart_first_date = ind[0] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ def card_controls( | |
last_date: Optional[str], | ||
ccy: Optional[str], | ||
): | ||
card = dbc.Card( | ||
return dbc.Card( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
dbc.CardBody( | ||
[ | ||
html.H5("Efficient Frontier", className="card-title"), | ||
|
@@ -37,24 +37,24 @@ def card_controls( | |
html.Label("Tickers in the Efficient Frontier"), | ||
dcc.Dropdown( | ||
options=options, | ||
value=tickers if tickers else settings.default_symbols, | ||
value=tickers or settings.default_symbols, | ||
multi=True, | ||
placeholder="Select assets", | ||
id="ef-symbols-list", | ||
), | ||
], | ||
] | ||
), | ||
html.Div( | ||
[ | ||
html.Label("Base currency"), | ||
dcc.Dropdown( | ||
options=inflation.get_currency_list(), | ||
value=ccy if ccy else "USD", | ||
value=ccy or "USD", | ||
multi=False, | ||
placeholder="Select a base currency", | ||
id="ef-base-currency", | ||
), | ||
], | ||
] | ||
), | ||
html.Div( | ||
[ | ||
|
@@ -65,22 +65,22 @@ def card_controls( | |
html.Label("First Date"), | ||
dbc.Input( | ||
id="ef-first-date", | ||
value=first_date if first_date else "2000-01", | ||
value=first_date or "2000-01", | ||
type="text", | ||
), | ||
dbc.FormText("Format: YYYY-MM"), | ||
], | ||
] | ||
), | ||
dbc.Col( | ||
[ | ||
html.Label("Last Date"), | ||
dbc.Input( | ||
id="ef-last-date", | ||
value=last_date if last_date else today_str, | ||
value=last_date or today_str, | ||
type="text", | ||
), | ||
dbc.FormText("Format: YYYY-MM"), | ||
], | ||
] | ||
), | ||
] | ||
), | ||
|
@@ -148,7 +148,10 @@ def card_controls( | |
dbc.RadioItems( | ||
options=[ | ||
{"label": "On", "value": "On"}, | ||
{"label": "Off", "value": "Off"}, | ||
{ | ||
"label": "Off", | ||
"value": "Off", | ||
}, | ||
], | ||
value="Off", | ||
id="cml-option", | ||
|
@@ -181,7 +184,9 @@ def card_controls( | |
value=0, | ||
id="risk-free-rate-option", | ||
), | ||
dbc.FormText("0 - 100 (Format: XX.XX)"), | ||
dbc.FormText( | ||
"0 - 100 (Format: XX.XX)" | ||
), | ||
dbc.Tooltip( | ||
tl.ef_options_tooltip_rf_rate, | ||
target="info-rf-rate", | ||
|
@@ -219,19 +224,20 @@ def card_controls( | |
), | ||
dbc.FormFeedback("", type="valid"), | ||
dbc.FormFeedback( | ||
f"it should be an integer number ≤{settings.MC_MAX}", type="invalid" | ||
f"it should be an integer number ≤{settings.MC_MAX}", | ||
type="invalid", | ||
), | ||
# dbc.FormText("≤100 000") | ||
], | ||
width=6 | ||
width=6, | ||
), | ||
dbc.Tooltip( | ||
tl.ef_options_monte_carlo, | ||
target="info-monte-carlo", | ||
), | ||
], | ||
className="p-1", | ||
) | ||
), | ||
] | ||
), | ||
html.Div( | ||
|
@@ -250,7 +256,6 @@ def card_controls( | |
), | ||
class_name="mb-3", | ||
) | ||
return card | ||
|
||
|
||
@callback( | ||
|
@@ -296,6 +301,9 @@ def check_validity_monte_carlo(number: int): | |
Check if input is an integer in range for 0 to MC_MAX. | ||
""" | ||
if number: | ||
is_correct_number = number in range(0, settings.MC_MAX) and isinstance(number, int) | ||
is_correct_number = number in range(settings.MC_MAX) and isinstance( | ||
number, int | ||
) | ||
|
||
Comment on lines
-299
to
+307
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return is_correct_number, not is_correct_number | ||
return False, False |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,32 +31,39 @@ | |
|
||
def layout(tickers=None, first_date=None, last_date=None, ccy=None, **kwargs): | ||
tickers_list = get_tickers_list(tickers) | ||
page = dbc.Container( | ||
return dbc.Container( | ||
[ | ||
dbc.Row( | ||
[ | ||
dbc.Col(card_controls(tickers_list, first_date, last_date, ccy), lg=7), | ||
dbc.Col( | ||
card_controls( | ||
tickers_list, first_date, last_date, ccy | ||
), | ||
lg=7, | ||
), | ||
Comment on lines
-34
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
dbc.Col(card_ef_info, lg=5), | ||
] | ||
), | ||
dbc.Row(dbc.Col(card_graf, width=12), align="center"), | ||
dbc.Row( | ||
html.Div( | ||
[ | ||
dcc.Markdown(""" | ||
dcc.Markdown( | ||
""" | ||
**Portfolio data** | ||
Click on points to get portfolio data. | ||
"""), | ||
""" | ||
), | ||
html.P(id='ef-click-data-risk'), | ||
html.P(id='ef-click-data-return'), | ||
html.Pre(id='ef-click-data-weights'), | ||
]), | ||
) | ||
] | ||
), | ||
), | ||
], | ||
class_name="mt-2", | ||
fluid="md", | ||
) | ||
return page | ||
|
||
|
||
@callback( | ||
|
@@ -190,13 +197,15 @@ def make_ef_figure(ef_object: okama.EfficientFrontier, ef_options: dict): | |
fig.add_trace( | ||
go.Scatter( | ||
x=df["Risk"], | ||
y=df["Return"] if ef_options["ror"] == "Arithmetic" else df["CAGR"], | ||
# customdata=weights_array, | ||
y=df["Return"] | ||
if ef_options["ror"] == "Arithmetic" | ||
else df["CAGR"], | ||
hovertemplate='Risk: %{x:.2f}%<br>Return: %{y:.2}%', | ||
mode="markers", | ||
name=f"Monte-Carlo Simulation", | ||
name="Monte-Carlo Simulation", | ||
) | ||
) | ||
|
||
Comment on lines
-193
to
+208
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ):
|
||
# X and Y titles | ||
fig.update_layout( | ||
height=800, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
create_link
refactored with the following changes:move-assign-in-block
)use-join
)