Skip to content

Commit

Permalink
Add vault share price to dashboard (#1733)
Browse files Browse the repository at this point in the history
  • Loading branch information
slundqui authored Nov 14, 2024
1 parent 04abee5 commit 464a21f
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/agent0/chainsync/dashboard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Dashboard utilities"""

from .build_dashboard_dfs import build_pool_dashboard, build_wallet_dashboard
from .plot_fixed_rate import plot_rates
from .plot_ohlcv import plot_ohlcv
from .plot_outstanding_positions import plot_outstanding_positions
from .plot_rates import plot_rates
from .plot_share_price import plot_share_price
from .plot_utils import reduce_plot_data
from .usernames import abbreviate_address, build_user_mapping, map_addresses
2 changes: 2 additions & 0 deletions src/agent0/chainsync/dashboard/build_dashboard_dfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .build_outstanding_positions import build_outstanding_positions
from .build_ticker import build_ticker_for_pool_page, build_ticker_for_wallet_page
from .build_variable_rate import build_variable_rate
from .build_vault_share_price import build_vault_share_price
from .build_wallet_positions import (
build_pnl_over_time,
build_positions_over_time,
Expand Down Expand Up @@ -108,6 +109,7 @@ def build_pool_dashboard(
# build rates
out_dfs["fixed_rate"] = build_fixed_rate(pool_info)
out_dfs["variable_rate"] = build_variable_rate(pool_info)
out_dfs["vault_share_price"] = build_vault_share_price(pool_info)

# build outstanding positions plots
out_dfs["outstanding_positions"] = build_outstanding_positions(pool_info)
Expand Down
22 changes: 22 additions & 0 deletions src/agent0/chainsync/dashboard/build_vault_share_price.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Builds the variable rate dataframe to be plotted."""

import pandas as pd


def build_vault_share_price(pool_info: pd.DataFrame) -> pd.DataFrame:
"""Gets the proper columns from pool info for plotting variable rate.
Arguments
---------
pool_info: pd.DataFrame
The pool analysis object from `get_pool_info`
Returns
-------
pd.DataFrame
The ready to plot variable rate
"""
vault_share_price = pool_info[["timestamp", "vault_share_price"]].copy()
vault_share_price["vault_share_price"] = vault_share_price["vault_share_price"].astype(float)
# Return here as float for plotting
return vault_share_price
2 changes: 1 addition & 1 deletion src/agent0/chainsync/dashboard/plot_ohlcv.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def plot_ohlcv(ohlcv: pd.DataFrame, ohlcv_ax: Axes) -> None:
mpf.plot(ohlcv, type="candle", ax=ohlcv_ax, show_nontrading=True)

ohlcv_ax.yaxis.set_major_formatter(mpl_ticker.FuncFormatter(lambda x, p: format(x, "0.6")))
ohlcv_ax.set_xlabel("block timestamp")
ohlcv_ax.set_xlabel("Timestamp")
ohlcv_ax.set_title("Spot Price Ohlc")
ohlcv_ax.yaxis.set_label_position("right")
ohlcv_ax.yaxis.tick_right()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def plot_outstanding_positions(data: pd.DataFrame, axes: Axes):
# change y-axis unit format to 0.1%
axes.yaxis.set_label_position("right")
axes.yaxis.tick_right()
axes.set_xlabel("Block Timestamp")
axes.set_xlabel("Timestamp")
axes.set_ylabel(bonds_symbol)
axes.set_title("Open Positions")
axes.legend()
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def plot_rates(fixed_rate: pd.DataFrame, variable_rate: pd.DataFrame, axes: Axes
axes.yaxis.set_major_formatter(mpl_ticker.FuncFormatter(lambda x, p: format(x, "0.3%")))
axes.yaxis.set_label_position("right")
axes.yaxis.tick_right()
axes.set_xlabel("block timestamp")
axes.set_xlabel("Timestamp")
axes.set_ylabel("rate (%)")
axes.set_title("Fixed/Variable rate")
axes.legend()
26 changes: 26 additions & 0 deletions src/agent0/chainsync/dashboard/plot_share_price.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Plot the fixed rate."""

from __future__ import annotations

import pandas as pd
from matplotlib.axes import Axes


def plot_share_price(vault_share_price: pd.DataFrame, axes: Axes) -> None:
"""Plots the vault share price.
Arguments
---------
vault_share_price: pd.DataFrame
The vault_share_price dataframe.
axes: Axes
The matplotlib axes to plot on.
"""
# TODO add lp share price to this plot
axes.plot(vault_share_price["timestamp"], vault_share_price["vault_share_price"], label="Vault Share Price")
axes.yaxis.set_label_position("right")
axes.yaxis.tick_right()
axes.set_xlabel("Timestamp")
axes.set_ylabel("Share Price")
axes.set_title("Share Price")
axes.legend()
5 changes: 4 additions & 1 deletion src/agent0/chainsync/streamlit/Dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
plot_ohlcv,
plot_outstanding_positions,
plot_rates,
plot_share_price,
)
from agent0.chainsync.db.base import initialize_session
from agent0.chainsync.db.hyperdrive import get_hyperdrive_addr_to_name
Expand Down Expand Up @@ -54,7 +55,7 @@

main_fig = mpf.figure(style="mike", figsize=(10, 10))
# matplotlib doesn't play nice with types
(ax_ohlcv, ax_fixed_rate, ax_positions) = main_fig.subplots(3, 1, sharex=True) # type: ignore
(ax_ohlcv, ax_fixed_rate, ax_vault_share_price, ax_positions) = main_fig.subplots(4, 1, sharex=True) # type: ignore

while True:
if selected_hyperdrive_address is not None:
Expand All @@ -75,10 +76,12 @@
# Clears all axes
ax_ohlcv.clear()
ax_fixed_rate.clear()
ax_vault_share_price.clear()
ax_positions.clear()

plot_ohlcv(data_dfs["ohlcv"], ax_ohlcv)
plot_rates(data_dfs["fixed_rate"], data_dfs["variable_rate"], ax_fixed_rate)
plot_share_price(data_dfs["vault_share_price"], ax_vault_share_price)
plot_outstanding_positions(data_dfs["outstanding_positions"], ax_positions)

ax_ohlcv.tick_params(axis="both", which="both")
Expand Down

0 comments on commit 464a21f

Please sign in to comment.