From df16b750339b3bb512e6021a15192826bb22c311 Mon Sep 17 00:00:00 2001 From: Rene Fernandez Date: Tue, 3 Sep 2024 22:36:33 +0200 Subject: [PATCH] Fix return yields on closed companies --- backend/companies/data_calculators_closed.py | 27 +++++++------------ .../shares_transaction_calculator.py | 4 +-- client/package.json | 2 +- client/src/version.ts | 2 +- pyproject.toml | 2 +- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/backend/companies/data_calculators_closed.py b/backend/companies/data_calculators_closed.py index 298b8290..d1599861 100644 --- a/backend/companies/data_calculators_closed.py +++ b/backend/companies/data_calculators_closed.py @@ -167,17 +167,14 @@ def calculate_return_with_dividends_on_year(self, year: int) -> Decimal: return return_year + accumulated_dividends def calculate_return_yield_on_year(self, year: int) -> Decimal: + return_value = self.calculate_return_on_year(year) - if ( - int(year) == self.last_transaction.transaction_date.year - or year == settings.YEAR_FOR_ALL - ) or (int(year) == self.last_transaction.transaction_date.year): - total_invested = self.shares_calculator.calculate_accumulated_investment_until_year_excluding_last_sale( # noqa - year - ) - else: - total_invested = self.calculate_accumulated_investment_until_year(year) + # Years before the last sell transaction + total_invested = Decimal(0) + total_invested = self.shares_calculator.calculate_total_investments_until_year( + year + ) if total_invested != 0: return (return_value / total_invested) * 100 @@ -185,15 +182,9 @@ def calculate_return_yield_on_year(self, year: int) -> Decimal: def calculate_return_yield_with_dividends_on_year(self, year: int) -> Decimal: return_with_dividends = self.calculate_return_with_dividends_on_year(year) - if ( - int(year) == self.last_transaction.transaction_date.year - or year == settings.YEAR_FOR_ALL - ) or (int(year) == self.last_transaction.transaction_date.year): - total_invested = self.shares_calculator.calculate_accumulated_investment_until_year_excluding_last_sale( # noqa - year - ) - else: - total_invested = self.calculate_accumulated_investment_until_year(year) + total_invested = self.shares_calculator.calculate_total_investments_until_year( + year + ) if total_invested != 0: return (return_with_dividends / total_invested) * 100 diff --git a/backend/shares_transactions/calculators/shares_transaction_calculator.py b/backend/shares_transactions/calculators/shares_transaction_calculator.py index c1bf1f1e..f0320b34 100644 --- a/backend/shares_transactions/calculators/shares_transaction_calculator.py +++ b/backend/shares_transactions/calculators/shares_transaction_calculator.py @@ -152,13 +152,13 @@ def calculate_accumulated_investment_until_year(self, year: int) -> Decimal: # BUY query = self._get_multiple_buy_transactions_query(year, use_accumulated=True) transactions_calculator = TransactionCalculator() - buy_total = transactions_calculator.calculate_transactions_amount( + buy_total = transactions_calculator.calculate_investments( query, use_portfolio_currency=self.use_portfolio_currency ) # SELL query = self._get_multiple_sell_transactions_query(year, use_accumulated=True) transactions_calculator = TransactionCalculator() - sell_total = transactions_calculator.calculate_transactions_amount( + sell_total = transactions_calculator.calculate_investments( query, use_portfolio_currency=self.use_portfolio_currency ) diff --git a/client/package.json b/client/package.json index 8204a015..ea90f770 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "client", - "version": "1.0.4-beta.11", + "version": "1.0.4-beta.12", "homepage": "/", "private": true, "dependencies": { diff --git a/client/src/version.ts b/client/src/version.ts index 840a938a..6ce68445 100644 --- a/client/src/version.ts +++ b/client/src/version.ts @@ -1,2 +1,2 @@ -export const PACKAGE_VERSION = "1.0.4-beta.9"; +export const PACKAGE_VERSION = "1.0.4-beta.12"; export default { PACKAGE_VERSION }; diff --git a/pyproject.toml b/pyproject.toml index 2044be12..f189bf9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "buho-stocks" -version = "1.0.4-beta.11" +version = "1.0.4-beta.12" description = "Application to manage and track a stocks portfolio with dividends and return for a Buy & Hold investmentinvestment strategy." authors = ["Rene Fernandez "] license = "GPL-3.0-or-later"