Skip to content

Commit

Permalink
Merge pull request #29 from viventriglia/develop
Browse files Browse the repository at this point in the history
v0.2.4
  • Loading branch information
viventriglia authored Nov 16, 2024
2 parents 8cafb60 + 25c9b36 commit cb9c1ea
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ FROM python:3.10-slim

WORKDIR /app

RUN pip install poetry==1.5.1

COPY pyproject.toml poetry.lock ./

RUN poetry install --no-root
RUN pip install poetry==1.8.4 && poetry install --no-root --no-dev

COPY . .

Expand Down
2 changes: 1 addition & 1 deletion src/0_🏠_Home.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
""",
unsafe_allow_html=True,
)
col_l, col_r = st.columns([0.2, 0.95], gap="small")
col_l, col_r = st.columns([0.25, 0.95], gap="small")

uploaded_file = col_r.file_uploader(
label="Upload your Data",
Expand Down
17 changes: 10 additions & 7 deletions src/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def aggregate_by_ticker(df: pd.DataFrame, in_pf_only: bool = False) -> pd.DataFr
@st.cache_data(ttl=10 * CACHE_EXPIRE_SECONDS, show_spinner=False)
def get_wealth_history(
df_transactions: pd.DataFrame, ticker_list: list[str]
) -> pd.Series:
) -> pd.DataFrame:
begin_date = df_transactions["transaction_date"].min()
today = datetime.now().date()
date_range = pd.date_range(start=begin_date, end=today, freq="D")
Expand All @@ -62,26 +62,29 @@ def get_wealth_history(

df_transactions = df_transactions[df_transactions["ticker_yf"].isin(ticker_list)]

df_asset_allocation = pd.DataFrame(
index=date_range,
columns=ticker_list,
data=0,
)
df_asset_allocation = pd.DataFrame(index=date_range, columns=ticker_list, data=0)
df_cumulative_spent = pd.Series(index=date_range, data=0)

for (data, ticker), group in df_transactions.groupby(
["transaction_date", "ticker_yf"]
):
total_shares = group["shares"].sum()
total_spent = group["ap_amount"].sum()
df_asset_allocation.loc[data, ticker] += total_shares
df_cumulative_spent.loc[data] += total_spent

df_asset_allocation = df_asset_allocation.cumsum()
df_cumulative_spent = df_cumulative_spent.cumsum()

df_wealth = pd.DataFrame(
df_asset_allocation.multiply(df_prices.loc[begin_date:])
.ffill()
.sum(axis=1)
.rename("ap_daily_value")
)
df_wealth["diff_previous_day"] = df_wealth.diff()
df_wealth["diff_previous_day"] = df_wealth["ap_daily_value"].diff()
df_wealth["ap_cum_spent"] = df_cumulative_spent
df_wealth["ap_cum_pnl"] = df_wealth["ap_daily_value"] - df_wealth["ap_cum_spent"]

return df_wealth

Expand Down
26 changes: 21 additions & 5 deletions src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def plot_sunburst(df: pd.DataFrame) -> go.Figure:
fig.update_traces(hovertemplate="<b>%{value:.1f}%")
fig.update_layout(
autosize=False,
height=600,
height=620,
margin=dict(l=0, r=0, t=20, b=20),
hoverlabel_font_size=PLT_FONT_SIZE,
)
Expand Down Expand Up @@ -56,17 +56,33 @@ def plot_wealth(df: pd.DataFrame) -> go.Figure:
data_frame=df, x=df.index, y="ap_daily_value", custom_data=["diff_previous_day"]
)
fig.update_traces(
hovertemplate="%{x}: <b>%{y:,.0f}€</b> <extra>Gain/Loss on previous day: %{customdata:,.0f}€</extra>"
hovertemplate=(
"Portfolio value: <b>%{y:,.0f}€</b>"
"<extra>P&L vs previous day: %{customdata:,.0f}€</extra>"
)
)
fig.add_trace(
go.Scatter(
x=df.index,
y=df["ap_cum_spent"],
mode="lines",
name="Cumulative Spent",
line=dict(dash="6px", width=1.5, color="bisque"),
customdata=df["ap_cum_pnl"],
hovertemplate=(
"Invested capital: <b>%{y:,.0f}€</b>"
"<extra>Ap-/De-preciation: %{customdata:,.0f}€</extra>"
),
)
)
fig.update_layout(
autosize=False,
height=550,
hoverlabel_font_size=PLT_FONT_SIZE,
hovermode="x",
margin=dict(l=0, r=0, t=20, b=20),
xaxis=dict(title=""),
yaxis=dict(
title="Daily value", showgrid=False, tickformat=",.0f", ticksuffix=" €"
),
yaxis=dict(title="", showgrid=False, tickformat=",.0f", ticksuffix=" €"),
showlegend=False,
)
return fig
Expand Down
2 changes: 1 addition & 1 deletion src/var.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
os.path.join(*split_script_running_path[0 : len(split_script_running_path) - 1])
)

APP_VERSION = "0.2.3"
APP_VERSION = "0.2.4"

# Data/images

Expand Down

0 comments on commit cb9c1ea

Please sign in to comment.