Skip to content

Commit

Permalink
Fix return yields on closed companies
Browse files Browse the repository at this point in the history
  • Loading branch information
renefs committed Sep 3, 2024
1 parent e4a1952 commit df16b75
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 23 deletions.
27 changes: 9 additions & 18 deletions backend/companies/data_calculators_closed.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,33 +167,24 @@ 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
return Decimal(0)

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "client",
"version": "1.0.4-beta.11",
"version": "1.0.4-beta.12",
"homepage": "/",
"private": true,
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion client/src/version.ts
Original file line number Diff line number Diff line change
@@ -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 };
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
license = "GPL-3.0-or-later"
Expand Down

0 comments on commit df16b75

Please sign in to comment.