On Sun, Aug 01, 2021 at 03:26:38PM -0700, Ben L wrote:
> Thanks for all the suggestions. Using 
> https://hub.darcs.net/falsifian/misc-pub/browse/beancount_plugins/falsifian/parallel_average_cost.py
>  
> as a starting point, I'm trying to write a plugin that will duplicate every 
> transaction in a second currency. So for example:
> 
> 2020-01-01 * "Buy"
>   Assets:Chequing    -400.00 USD
>   Assets:Brokerage       4 ACME {100.00 USD}
> 
> Would turn into
> 
> 2020-01-01 * "Buy"
>   Assets:Chequing    -400.00 USD
>   Assets:Brokerage       4 ACME {100.00 USD}
> 
> 2020-01-01 * "Buy"
>   Assets:Chequing_CAD    -500.00 CAD
>   Assets:Brokerage_CAD       4 ACME_CAD {500.00 CAD}
> 
> (1.25 CAD = USD) This works fine for basic stuff, but the problem I'm 
> having is I want to use the  beancount engine to calculate the values of 
> certain lines. In the above example, if the exchange rate changes to 1.2 
> CAD = USD, and I sell 2 units of ACME, I would add
> 
> 2020-03-01 * "Sell"
>   Assets:Chequing       220.00 USD  
>   Income:Capital-gains  
>   Assets:Brokerage         -2 ACME {} @ 110.00 USD
> 
> (Beancount calculates cap gains as $20 since previous buy was at $100)
> 
> I want my plugin to generate symmetric lines in CAD using the 1.2 exchange 
> rate:
> 
> 2020-03-01 * "Sell"
>   Assets:Chequing_CAD       264.00 CAD
>   Income:Capital-gains_CAD
>   Assets:Brokerage_CAD         -2 ACME_CAD {} @ 132.00 CAD
> 
> And then beancount calculate $14 CAD as cap gains since the 2 ACME_CAD were 
> previously purchased at $125 CAD each.
> 
> The problem I'm having is in my plugin, when I loop through the entries 
> (for entry in entries in python) then the entry figure has the USD value 
> for the Capital-gains, so it just converts the USD to CAD with the relevant 
> exchange rate instead of calculating it using the cost of the ACME_CAD 
> asset. So in this example, instead of $14 CAD cap gains, it is $16.67 CAD 
> ($20 / 1.2). 
> 
> Is there a way to loop over the entries before beancount does these 
> calculations? Or is there a better approach?
> 
> Thanks,
> 
> Ben

Hi Ben,

I had my plugin compute capital gains itself, at least partly for the
reason in your email. See for example the test case "test_uses_price"
in
https://hub.darcs.net/falsifian/misc-pub/browse/beancount_plugins/falsifian/parallel_average_cost_test.py

If you still want to do things your way, maybe you could add a metadata
field like "blank: True" to fields your plugin should treat as "blank". E.g.

  2020-03-01 * "Sell"
    Assets:Chequing       220.00 USD  
    Income:Capital-gains  
      blank: True
    Assets:Brokerage         -2 ACME {} @ 110.00 USD

and then your plugin would know to ignore the USD value it sees in the
Income:Capital-gains posting.

I don't know if there's a way to modify the entries before Beancount
fills in blanks.

-- 
James

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/20210816201054.ns4dhnsdbpd5zo6x%40moth.falsifian.org.

Reply via email to