Skip to content

Commit

Permalink
Fix sale dates in schwab_equity_award_json. (#569)
Browse files Browse the repository at this point in the history
* Bump crazy-max/ghaction-github-labeler from 5.0.0 to 5.1.0 (#567)

Bumps [crazy-max/ghaction-github-labeler](https://github.com/crazy-max/ghaction-github-labeler) from 5.0.0 to 5.1.0.
- [Release notes](https://github.com/crazy-max/ghaction-github-labeler/releases)
- [Commits](crazy-max/ghaction-github-labeler@v5.0.0...v5.1.0)

---
updated-dependencies:
- dependency-name: crazy-max/ghaction-github-labeler
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Fix transaction date in schwab_equity_award_json.

The previous logic was actually incorrect, as noticed by comparing the output of the parser with the corresponding Schwab statement.

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
thibwk and dependabot[bot] authored Nov 7, 2024
1 parent c0f2740 commit d64bd04
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
12 changes: 1 addition & 11 deletions cgt_calc/parsers/schwab_equity_award_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,11 @@
from pathlib import Path
from typing import Any, Final

from pandas.tseries.holiday import USFederalHolidayCalendar
from pandas.tseries.offsets import CustomBusinessDay

from cgt_calc.const import TICKER_RENAMES
from cgt_calc.exceptions import ParsingError
from cgt_calc.model import ActionType, BrokerTransaction
from cgt_calc.util import round_decimal

# Delay between a (sale) trade, and when it is settled.
SETTLEMENT_DELAY: Final = 2 * CustomBusinessDay(calendar=USFederalHolidayCalendar())
OPTIONAL_DETAILS_NAME: Final = "Details"
FIELD_TO_SCHEMA: Final = {"transactions": 1, "Transactions": 2}

Expand Down Expand Up @@ -227,12 +222,7 @@ def __init__(self, row: JsonRowType, file: str, field_names: FieldNames) -> None
f"(ID {details[names.award_id]})"
)
elif row[names.action] == "Sale":
# Schwab's data export shows the settlement date,
# whereas HMRC wants the trade date:
date = (
datetime.datetime.strptime(row[names.date], "%m/%d/%Y").date()
- SETTLEMENT_DELAY
).date() # type: ignore[attr-defined]
date = datetime.datetime.strptime(row[names.date], "%m/%d/%Y").date()

# Schwab's data export sometimes lacks decimals on Sales
# quantities, in which case we infer it from number of shares in
Expand Down
6 changes: 3 additions & 3 deletions tests/test_schwab_equity_award_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_schwab_transaction_v1() -> None:
assert transactions[0].currency == "USD"
assert transactions[0].broker == "Charles Schwab"

assert transactions[1].date == datetime.date(2022, 6, 10)
assert transactions[1].date == datetime.date(2022, 6, 14)
assert transactions[1].action == ActionType.SELL
assert transactions[1].quantity == Decimal("62.601495")
assert transactions[1].price == Decimal("113.75")
Expand All @@ -76,7 +76,7 @@ def test_schwab_transaction_v1() -> None:
assert transactions[2].price == Decimal("112.42")
assert transactions[2].fees == Decimal("0")

assert transactions[3].date == datetime.date(2022, 11, 14)
assert transactions[3].date == datetime.date(2022, 11, 16)
assert transactions[3].action == ActionType.SELL
assert transactions[3].quantity == Decimal("12.549")
assert transactions[3].price is not None
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_schwab_transaction_v2() -> None:
assert transactions[1].price == Decimal("106.78")
assert transactions[1].fees == Decimal("0")

assert transactions[2].date == datetime.date(2023, 8, 29)
assert transactions[2].date == datetime.date(2023, 8, 31)
assert transactions[2].action == ActionType.SELL
assert transactions[2].quantity == Decimal("14.40")
assert transactions[2].price == Decimal("137.90")
Expand Down

0 comments on commit d64bd04

Please sign in to comment.