On Fri, May 07, 2021 at 07:24:58PM +0100, Caesar Schinas wrote:
I'm actually currently working on a plugin to convert all my cost bases
and capital gains computations to USD for the purposes of US taxes,
even if I enter them in CAD (because I actually did the trading in
CAD).
Hopefully the below test case illustrates how it's supposed to work.
It's a bit weird, because it expects the transaction-as-entered to
already have capital gains computed in USD. That kind of suits my own
use case, since I've been obsessing over making sure all my numbers add
up, and don't mind spending a bit of extra time filling in the capital
gains amounts.
Happy to share the current state if anyone is interested now. Otherwise
I was planning to wait until I've successfully converted my ledger to
use it, since I keep thinking of things to change.
(One planned change based on my experience so far: I need to add a work
around for the fact that prices and costs must be in the same currency.
I make liberal use of Norbert's gambit, so some of my postings make the
most sense (to me) as something like:
Assets:Brokerage -5 ACME {20.00 CAD} @ 15.00 USD
I'm thinking I'll just replace the "@ 15.00 USD" with metadata to be
interpreted by the plugin.)
class TestConvertAllCosts(cmptest.TestCase):
@loader.load_doc(expect_errors=False)
def test_simple_buy_sell(self, entries, _errors, _options_map):
"""
plugin "falsifian.convert_cost" "conversion_account=Equity:Cost-conversion"
2000-01-01 open Assets:Brokerage
2000-01-01 open Assets:Chequing
2000-01-01 open Income:Capital-gains
2000-01-01 open Equity:Cost-conversion
; Buy transactions should balance as entered. The conversion_account
; will be used to make sure they still balance after being converted.
2000-01-01 * "Buy"
Assets:Chequing -100.00 CAD
Assets:Brokerage 5 ACME {20.00 CAD}
convert_buy_cost_to: "USD"
; Sell transactions should be written to balance after being converted.
; The capital gain portion of the sale will be converted to
; target_currency, but the rest will be left alone. In this example,
; that means the Assets:Chequing posting can reflect the actual CAD
; balance deposited.
2000-02-01 * "Sell"
Assets:Chequing 200.00 CAD
Assets:Brokerage -5 ACME {20.00 CAD} @ 40.00 CAD
convert_sell_cost_to: "USD"
Income:Capital-gains -90.00 USD
2000-01-01 price CAD 0.70 USD
2000-02-01 price CAD 0.80 USD
; Irrelevant prices that should be ignored
2000-01-01 price CAD 100.00 AUD
2000-01-01 price AUD 100.00 USD
"""
self.assertEqualEntries("""
2000-01-01 open Assets:Brokerage
2000-01-01 open Assets:Chequing
2000-01-01 open Income:Capital-gains
2000-01-01 open Equity:Cost-conversion
2000-01-01 * "Buy"
Assets:Chequing -100.00 CAD
Assets:Brokerage 5 ACME {14.0000 USD}
Equity:Cost-conversion -70.0000 USD
Equity:Cost-conversion 100.00 CAD
2000-02-01 * "Sell"
Assets:Chequing 200.00 CAD
Assets:Brokerage -5 ACME {14.0000 USD} @ 32.0000 USD
Income:Capital-gains -90.00 USD
Equity:Cost-conversion -200.00 CAD
Equity:Cost-conversion 160.0000 USD
2000-01-01 price CAD 0.70 USD
2000-02-01 price CAD 0.80 USD
2000-01-01 price CAD 100.00 AUD
2000-01-01 price AUD 100.00 USD
""", entries)
--
James