Skip to content

Commit

Permalink
Fix calculation with sales in last day of tax year (#128)
Browse files Browse the repository at this point in the history
The last day of tax year is included in the tax year.
Previously, a sale in the last day of the tax year was not
counted and produced a result with 0 disposal.

The previous code was off-by-one; it used the amount of days
in the period being checked as an argument to range(), but the end
in range() is exclusive.

To illustrate: if being_index and end_index are the same,
end_index - begin_index will be 0. Then we will do range(0, 0), which
is empty. But it should be one day instead! (the first and last day of
the imaginary tax year).

Note: I found this out exactly because I had one disposal in the last
day of the tax year!
  • Loading branch information
danielkza committed Nov 27, 2021
1 parent 70a2a5b commit 6c5574d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion cgt_calc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ def calculate_capital_gain(
calculation_log: CalculationLog = {}
for date_index in (
begin_index + datetime.timedelta(days=x)
for x in range(0, (end_index - begin_index).days)
for x in range(0, (end_index - begin_index).days + 1)
):
if date_index in acquisition_list:
for symbol in acquisition_list[date_index]:
Expand Down

0 comments on commit 6c5574d

Please sign in to comment.