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



On Tuesday, July 20, 2021 at 6:38:08 AM UTC-6 Alan H wrote:

> I have written a plugin that allows me to split expenses across tax years 
> and assign fractions of each expense to a tax reporting account as needed. 
> (For example to recover home office expenses)
> As for dealing with reporting in the other (non-native) currency I do what 
> Martin said - assuming I can write a query that shows all relevent amounts, 
> I just convert the position to CAD while ensuring that I have appropriate 
> pricing data to support the conversions. TBH this made tax-time this year 
> much easier than prior years and very fragile large sheets
> Alan
>
>
> On Tuesday, July 20, 2021 at 12:48:44 AM UTC+1 [email protected] wrote:
>
>> * Ben Luey <[email protected]> [2021-07-19 08:14]:
>> > 1) Do this all on the query side. Is there a sql query I can run
>> > that would do a convert for each transaction that matches some
>> > criteria and then sum that? Let's assume I've already input the
>> > USD/CAD exchange rate for all transaction dates into beancount.
>>
>> This query will convert from USD to CAD on the date of the
>> transaction:
>>
>> SELECT date, narration, CONVERT(position, 'CAD', date) WHERE account ~ 
>> 'Expenses:Test'
>>
>> -- 
>> Martin Michlmayr
>> https://www.cyrius.com/
>>
>

-- 
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/bd860706-e77b-4ac6-8574-ca589d5604ffn%40googlegroups.com.

Reply via email to