Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions common/create_link.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
def create_link(ccy, first_date, href, last_date, tickers_list):
tickers_str = ""
t_number = len(tickers_list)
for i, ticker in enumerate(tickers_list):
tickers_str += f"{ticker}," if i + 1 < t_number else ticker
tickers_str = "".join(
f"{ticker}," if i + 1 < t_number else ticker
for i, ticker in enumerate(tickers_list)
)

Comment on lines -2 to +7
Copy link
Author

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:

reset_href = href.split("?")[0]
new_url = f"{reset_href}?tickers={tickers_str}" if tickers_str else reset_href
new_url += f"&ccy={ccy}"
Expand Down
7 changes: 4 additions & 3 deletions common/html_elements/copy_link_div.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_copy_link_div refactored with the following changes:

[
# the URL bar, doesn't render anything
dcc.Location(id=location_id, refresh=False),
Expand All @@ -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,
Expand All @@ -36,4 +38,3 @@ def create_copy_link_div(location_id: str, hidden_div_with_url_id: str, button_i
),
]
)
return div
3 changes: 1 addition & 2 deletions common/html_elements/info_dash_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_info refactored with the following changes:

34 changes: 22 additions & 12 deletions pages/compare/cards_compare/asset_list_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def card_controls(
ccy: Optional[str],
):
tickers_list = get_tickers_list(tickers)
card = dbc.Card(
return dbc.Card(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function card_controls refactored with the following changes:

dbc.CardBody(
[
html.H5("Compare Assets", className="card-title"),
Expand All @@ -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(
[
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -206,7 +217,6 @@ def card_controls(
),
class_name="mb-3",
)
return card


@callback(
Expand Down
10 changes: 6 additions & 4 deletions pages/compare/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function layout refactored with the following changes:

dbc.Col(card_assets_info, lg=5),
]
),
Expand All @@ -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(
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_al_figure refactored with the following changes:

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]
Expand Down
40 changes: 24 additions & 16 deletions pages/efficient_frontier/cards_efficient_frontier/ef_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def card_controls(
last_date: Optional[str],
ccy: Optional[str],
):
card = dbc.Card(
return dbc.Card(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function card_controls refactored with the following changes:

dbc.CardBody(
[
html.H5("Efficient Frontier", className="card-title"),
Expand All @@ -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(
[
Expand All @@ -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"),
],
]
),
]
),
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand All @@ -250,7 +256,6 @@ def card_controls(
),
class_name="mb-3",
)
return card


@callback(
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function check_validity_monte_carlo refactored with the following changes:

return is_correct_number, not is_correct_number
return False, False
29 changes: 19 additions & 10 deletions pages/efficient_frontier/frontier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function layout refactored with the following changes:

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(
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function make_ef_figure refactored with the following changes:

This removes the following comments ( why? ):

# customdata=weights_array,

# X and Y titles
fig.update_layout(
height=800,
Expand Down
Loading