Skip to content

Commit

Permalink
fix: portfolio listing table columns updated
Browse files Browse the repository at this point in the history
  • Loading branch information
arpandaze committed Jul 23, 2024
1 parent 6dc83eb commit 907ee91
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions nepseutils/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ def do_portfolio(self, args):
combined_entry.value_as_of_last_transaction_price += (
entry.value_as_of_last_transaction_price
)
combined_entry.value_as_of_previous_closing_price += (
entry.value_as_of_previous_closing_price
)
found = True
break

Expand All @@ -204,11 +207,9 @@ def do_portfolio(self, args):
portfolio = account.portfolio.entries

total_value = 0.0
for entry in portfolio:
total_value += entry.value_as_of_last_transaction_price

total_value_as_of_closing = 0.0
for entry in portfolio:
total_value += entry.value_as_of_last_transaction_price
total_value_as_of_closing += entry.value_as_of_previous_closing_price

headers = [
Expand All @@ -218,6 +219,8 @@ def do_portfolio(self, args):
"Last Transaction Price",
"Value as of Prev Closing",
"Value",
"+/- Amount",
"+/- %",
]
table = [
[
Expand All @@ -227,10 +230,14 @@ def do_portfolio(self, args):
f"{itm.last_transaction_price:,.1f}",
f"{itm.value_as_of_previous_closing_price:,.1f}",
f"{itm.value_as_of_last_transaction_price:,.1f}",
f"{itm.value_as_of_last_transaction_price - itm.value_as_of_previous_closing_price:,.1f}",
f"{(itm.value_as_of_last_transaction_price - itm.value_as_of_previous_closing_price)/itm.value_as_of_previous_closing_price*100:,.2f}%",
]
for itm in portfolio
]
table.append(["Total", "", "","",f"{total_value_as_of_closing:,.1f}", f"{total_value:,.1f}"])
total_diff = total_value - total_value_as_of_closing
total_diff_percent = total_diff / total_value_as_of_closing * 100
table.append(["Total", "", "","",f"{total_value_as_of_closing:,.1f}", f"{total_value:,.1f}", f"{total_diff:,.1f}", f"{total_diff_percent:,.2f}%"])
print(tabulate(table, headers=headers, tablefmt="pretty"))

def help_list(self):
Expand Down

0 comments on commit 907ee91

Please sign in to comment.