Abid Ali Awan
commited on
Commit
·
c317aeb
1
Parent(s):
d5c2e38
Refactor allocation calculation in FinancialTools: simplified logic for determining final total value based on investment type, ensuring accurate handling of both percentage-based and share-based portfolios.
Browse files- agents/tools.py +6 -7
agents/tools.py
CHANGED
@@ -640,9 +640,7 @@ class FinancialTools:
|
|
640 |
if shares is not None:
|
641 |
# Shares-based calculation
|
642 |
value = current_price * shares
|
643 |
-
allocation_percentage =
|
644 |
-
percentage if percentage > 0 else 0
|
645 |
-
)
|
646 |
else:
|
647 |
# Percentage-based calculation
|
648 |
value = total_investment * (percentage / 100)
|
@@ -674,11 +672,12 @@ class FinancialTools:
|
|
674 |
}
|
675 |
)
|
676 |
|
677 |
-
#
|
|
|
678 |
final_total_value = (
|
679 |
-
|
680 |
-
if any(h.get("percentage", 0) > 0 for h in holdings_info)
|
681 |
-
else
|
682 |
)
|
683 |
|
684 |
# Analysis and recommendations
|
|
|
640 |
if shares is not None:
|
641 |
# Shares-based calculation
|
642 |
value = current_price * shares
|
643 |
+
allocation_percentage = percentage
|
|
|
|
|
644 |
else:
|
645 |
# Percentage-based calculation
|
646 |
value = total_investment * (percentage / 100)
|
|
|
672 |
}
|
673 |
)
|
674 |
|
675 |
+
# For percentage-based portfolios, use the original total investment
|
676 |
+
# For share-based portfolios, use calculated value
|
677 |
final_total_value = (
|
678 |
+
total_investment
|
679 |
+
if total_investment > 0 and any(h.get("percentage", 0) > 0 for h in holdings_info)
|
680 |
+
else total_calculated_value
|
681 |
)
|
682 |
|
683 |
# Analysis and recommendations
|