Skip to content

Commit

Permalink
SecurityListView: Properly show short holdings for "Shares held != 0"…
Browse files Browse the repository at this point in the history
… filter

Don't forcibly clamp negative (short) holdings to zero. However, add comment
that the calculation is still not entirely correct, as it may return 0 in
case one account have positive number of shares, and another - same number,
but negative amount of shares.
  • Loading branch information
pfalcon authored and buchen committed Feb 2, 2025
1 parent 1b7d4f4 commit 73add51
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,11 @@ else if (watchlist != null)
*/
private long getSharesHeld(Client client, Security security)
{
// collect all shares and return a value greater 0
return Math.max(security.getTransactions(client).stream()
// TODO: This calculation is simplistic and may be incorrect.
// e.g., if one account has 1 (long) share and another - -1 (short) share,
// this calculation returns 0. But it's clear that it's not the case that
// we have 0 (i.e. none) shares.
return security.getTransactions(client).stream()
.filter(t -> t.getTransaction() instanceof PortfolioTransaction) //
.map(t -> (PortfolioTransaction) t.getTransaction()) //
.mapToLong(t -> {
Expand All @@ -261,7 +264,7 @@ private long getSharesHeld(Client client, Security security)
default:
return 0L;
}
}).sum(), 0);
}).sum();
}

private boolean isLimitPriceExceeded(Security security)
Expand Down

0 comments on commit 73add51

Please sign in to comment.