Skip to content

fix: collect all token amounts in portfolio_volatility instead of using last token only#137

Open
bigeez wants to merge 2 commits intoOpenGradient:mainfrom
bigeez:fix/portfolio-volatility-wrong-holding-qty
Open

fix: collect all token amounts in portfolio_volatility instead of using last token only#137
bigeez wants to merge 2 commits intoOpenGradient:mainfrom
bigeez:fix/portfolio-volatility-wrong-holding-qty

Conversation

@bigeez
Copy link
Copy Markdown

@bigeez bigeez commented Apr 4, 2026

Bug

In onchain/analytics/analytics_tools.py, the portfolio_volatility
function iterates over all tokens to fetch price data but only uses
the last token's amount for holding_qty:

for token in tokens:
    ...
    all_price_data.append(close_prices)

holding_qty = np.array(token.amount)  # only last token!

After the loop, token refers to the last item only. This means
portfolio volatility is calculated with incorrect weights for any
wallet holding more than one token — silently producing wrong results.

Fix

Collect each token's amount inside the loop into all_holding_qty,
then build the numpy array from that list after the loop completes.

Impact

  • Any user with 2+ tokens in their wallet was getting wrong volatility numbers
  • Silent bug — no error thrown, just incorrect calculations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant