Skip to content

Commit

Permalink
Add support for Margin Interest.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zburatorul committed Dec 18, 2020
1 parent 980d5b7 commit 2b825d2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
10 changes: 10 additions & 0 deletions beancount_import/source/schwab_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class SchwabAction(enum.Enum):
STOCK_PLAN_ACTIVITY = "Stock Plan Activity"
ADR_MGMT_FEE = "ADR Mgmt Fee"
FOREIGN_TAX_PAID = "Foreign Tax Paid"
MARGIN_INTEREST = "Margin Interest"


@dataclass(frozen=True)
Expand Down Expand Up @@ -224,6 +225,8 @@ def get_processed_entry(
return Fee(fees_account=fees_account, **shared_attrs)
if self.action == SchwabAction.FOREIGN_TAX_PAID:
return TaxPaid(taxes_account=taxes_account, **shared_attrs)
if self.action == SchwabAction.MARGIN_INTEREST:
return MarginInterest(**shared_attrs)
assert False, self.action


Expand Down Expand Up @@ -371,7 +374,14 @@ def get_other_account(self) -> str:
def get_narration_prefix(self) -> str:
return "INVBANKTRAN"

@dataclass(frozen=True)
class MarginInterest(TransactionEntry):
def get_sub_account(self) -> Optional[str]:
return "Cash"

def get_narration_prefix(self) -> str:
return "MARGININTEREST"

@dataclass(frozen=True)
class StockPlanActivity(TransactionEntry):
symbol: str
Expand Down
4 changes: 2 additions & 2 deletions beancount_import/source/schwab_csv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def test_source(name: str):
example_dir=example_dir,
source_spec={
'module': 'beancount_import.source.schwab_csv',
"transaction_csv_filenames": glob.glob(f"{example_dir}/transactions/*.CSV"),
"position_csv_filenames": glob.glob(f"{example_dir}/positions/*.CSV"),
"transaction_csv_filenames": sorted(glob.glob(f"{example_dir}/transactions/*.CSV")),
"position_csv_filenames": sorted(glob.glob(f"{example_dir}/positions/*.CSV")),
},
replacements=[(testdata_dir, '<testdata>')],
)
Expand Down
21 changes: 21 additions & 0 deletions testdata/source/schwab_csv/test_basic/import_results.beancount
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
;; date: 2018-06-28
;; info: {"filename": "<testdata>/test_basic/transactions/Intelligent_Transactions_20201115-180120.CSV", "line": 16, "type": "text/csv"}

; features: [
; {
; "amount": "-0.05 USD",
; "date": "2018-06-28",
; "key_value_pairs": {
; "desc": "INTEREST 05/30THRU 06/27",
; "schwab_action": "Margin Interest"
; },
; "source_account": "Assets:Schwab:Intelligent-4321:Cash"
; }
; ]
2018-06-28 * "MARGININTEREST - INTEREST 05/30THRU 06/27"
Assets:Schwab:Intelligent-4321:Cash -0.05 USD
date: 2018-06-28
schwab_action: "Margin Interest"
source_desc: "INTEREST 05/30THRU 06/27"
Expenses:FIXME 0.05 USD

;; date: 2019-06-11
;; info: {"filename": "<testdata>/test_basic/transactions/Intelligent_Transactions_20201115-180120.CSV", "line": 15, "type": "text/csv"}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@
"06/11/2019","Qualified Dividend","NOK","NOKIA CORP FSPONSORED ADR 1 ADR REPS 1 ORD SHS","","","","$6.32",
"06/11/2019","ADR Mgmt Fee","NOK","NOKIA CORP FSPONSORED ADR 1 ADR REPS 1 ORD SHS","","","","-$0.47",
"06/11/2019","Foreign Tax Paid","NOK","NOKIA CORP FSPONSORED ADR 1 ADR REPS 1 ORD SHS","","","","-$1.05"
Transactions Total,"","","","","","",-$8367.99
"06/28/2018","Margin Interest","","INTEREST 05/30THRU 06/27","","","","-$0.05"
Transactions Total,"","","","","","",-$8366.99

0 comments on commit 2b825d2

Please sign in to comment.