Skip to content

Commit

Permalink
attempt to resolve the split issue
Browse files Browse the repository at this point in the history
  • Loading branch information
sygi committed Jul 2, 2024
1 parent 52189a6 commit 0d36915
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cgt_calc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
)
from .parsers import read_broker_transactions, read_initial_prices
from .spin_off_handler import SpinOffHandler
from .transaction_log import add_to_list, has_key
from .transaction_log import add_to_list, has_key, multiply_entries
from .util import round_decimal

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -123,7 +123,16 @@ def add_acquisition(
price, amount = self.handle_spin_off(transaction)
elif transaction.action is ActionType.STOCK_SPLIT:
price = Decimal(0)
amount = Decimal(0)
original = self.portfolio[symbol].quantity
multiple = Decimal((original + quantity) / original)
# Retroactively alter the acquisition / disposal list, instead of
# adding the split as a separate acquisition event.
multiply_entries(
self.acquisition_list, symbol, multiple, transaction.date)
multiply_entries(
self.disposal_list, symbol, multiple, transaction.date)
self.portfolio[symbol] += Position(quantity, Decimal(0))
return
else:
if price is None:
raise PriceMissingError(transaction)
Expand Down
12 changes: 12 additions & 0 deletions cgt_calc/transaction_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,15 @@ def add_to_list(
amount=amount,
fees=fees,
)

def multiply_entries(
current_list: HmrcTransactionLog,
symbol: str,
multiple: Decimal,
multiply_date: datetime.date | None = None
) -> None:
for date, entries in current_list.items():
if multiply_date is not None:
assert multiply_date >= date
entries[symbol].quantity *= multiple

0 comments on commit 0d36915

Please sign in to comment.