On Fri, Aug 18, 2017 at 6:32 PM, <[email protected]> wrote:

> Hello fellow beancount users,
>
> I've got a bunch of bitcoin purchases in USD that I then sold for EUR, and
> beancount isn't matching the EUR sales with the USD purchases of bitcoin.
> Running *bean-check* against the transactions results in a "No position
> matches" and a list of the current non-reduced lots--all denominated in
> USD. I have daily EUR - USD and BTC - USD price histories per beancount's
> syntax in my ledger file. All my sales of bitcoin to USD reduced just
> fine... its just the sales to EUR that aren't working out.
>
> Originally I had my reducing legs of the transactions with empty curly
> braces {} but then I tried the following:
>
> option "title" "My Personal Ledger"
> option "operating_currency" "USD"
> option "booking_method" "FIFO"
>
> 2013-01-01 open Equity:Opening-Balances
> 2013-01-01 open Assets:Crypto:Bitcoin           BTC
> 2013-01-01 open Assets:Checking:CapitalOne      USD
> 2013-01-01 open Expenses:Crypto:Fees:Coinbase   USD
> 2013-01-01 open Assets:Checking:BNP             EUR
> 2013-01-01 open Income:CapitalGains
>
> 2016-05-25  price  BTC    449.24 USD
> 2016-05-25  price  EUR    1.12 USD
> 2016-05-27  price  BTC    474.38 USD
> 2016-05-27  price  EUR    1.11 USD
>
> 2016-05-25 * "Coinbase" "Bitcoin purchase"
>     Expenses:Crypto:Fees:Coinbase    4.60 USD
>     Assets:Crypto:Bitcoin            1.02140000 BTC {450.07 USD}
>     Assets:Checking:CapitalOne    -464.30 USD
>
> 2016-05-27 * "(s9d8fukf0)" "Sell BTC via bitsquare"
>     Assets:Crypto:Bitcoin           -0.50000000 BTC {USD} @ 416.75 EUR
>     Assets:Checking:BNP            208.38 EUR
>     Income:CapitalGains
>
> 2016-05-27 * "(l2l3jfp5d)" "Sell BTC via bitsquare"
>     Assets:Crypto:Bitcoin           -0.50000000 BTC {USD} @ 412.00 EUR
>     Assets:Checking:BNP            206.00 EUR
>     Income:CapitalGains
>
> That seems to work, except that that *bean-report* balances now shows me
> EUR and USD on separate capital gains lines:
> Income:CapitalGains             -414.38       EUR
> Income:CapitalGains              450.07       USD
>
>
This is not legal Beancount syntax, you're not supposed to be able to use a
different cost currency as a price currency.
This should raise an error (it doesn't, verified).
(This is excellent, you have an exceptional skill at finding bugs. I was
dead certain I had a unit test for this type of error and the fact it
doesn't raise an error really surprises me. I will fix and make this raise
an error.)

Furthermore, when a cost basis and a price annotation are both present, the
price is unused. It's only there as a convenience to fill in the price
database (the implicit_prices plugin does that, it looks for those and
converts them into Price directives). The total cost basis of that posting
is always the amount used to balance with the rest of the postings.


Here, this will work:

2016-05-27 * "(s9d8fukf0)" "Sell BTC via bitsquare"
    Assets:Crypto:Bitcoin           -0.50000000 BTC {USD}
    Assets:Checking:BNP            208.38 EUR @ 1/416.75 USD
    Income:CapitalGains

2016-05-27 * "(l2l3jfp5d)" "Sell BTC via bitsquare"
    Assets:Crypto:Bitcoin           -0.50000000 BTC {USD}
    Assets:Checking:BNP            206.00 EUR @ 1/412.00 USD
    Income:CapitalGains

Here's how to debug: You can view what Beancount expands to like this:

bean-query /home/blais/r/q/beancount-data/user/jkepler/20170819.beancount
print

This gives you the whole file, interpolated, expanded, matched.
This is what actually gets aggregated.


If you're interested in the context of a particular transaction you can use
this command:

bean-doctor context 20170819.beancount 25
Hash:ff03de6e58cb3b0b4355684d0e00be61
Location: /home/blais/r/q/beancount-data/user/jkepler/20170819.beancount:22

------------ Balances before transaction

  Assets:Crypto:Bitcoin            1.02140000 BTC {450.07 USD, 2016-05-25}

  Assets:Checking:BNP

  Income:CapitalGains


------------ Transaction

2016-05-27 * "(s9d8fukf0)" "Sell BTC via bitsquare"
  Assets:Crypto:Bitcoin  -0.50000000 BTC {450.07 USD, 2016-05-25}
     ;                -225.0350000000 USD
  Assets:Checking:BNP         208.38 EUR @ 0.002399520095980803839232153569
USD  ; 0.5000119976004799040191961607 USD
  Income:CapitalGains         224.53 USD
      ;  224.5349880023995200959808038 USD


Tolerances: BTC=5E-9, EUR=0.005
Basis: (-225.0350000000 USD)

------------ Balances after transaction

* Assets:Crypto:Bitcoin            0.52140000 BTC {450.07 USD, 2016-05-25}

* Assets:Checking:BNP                                           208.38 EUR

* Income:CapitalGains                    224.5349880023995200959808038 USD


"25" is the line number, and the Emacs mode has support for automatically
bringing up this.
This is useful to debug issues with matching lots.




> So, I've got two questions:
>
> 1. Since my file includes prices, is there a way I can have beancount know
> the USD equivalent for reducing lots in EUR that were purchased with USD?
>

You could convert the amounts to a single currency (though the rate used
for the conversion will be the latest/current one, not that at the time of
each transaction).

bean-query ...  "select account, convert(sum(position), 'USD') ..."




>
> 2. If I explicitly put "USD" in all my empty {}, how does will FIFO
> booking option handle the occasional cases where I've purchased bitcoin
> with euros?
>

I don't understand the question. If you try to reduce and provide USD in
the description, it will only match against lots in USD. Can you provide an
example pair of transactions?




> Will it always reduce the oldest bitcoin lots first, regardless of the
> currency I'm reducing with, or will explicitly specifying the reducing
> currency mean I have to manually check the order lots are cleared to make
> sure that the total of the two currencies reduces correctly per FIFO?
>

I'm still not sure I understand, it will never convert currencies when
reducing.



>
> I guess I'm looking to understand more specifically what the FIFO booking
> is doing or not doing when a commodity (BTC) is purchased in one currency
> (USD) and sold in another (EUR).
>

The booking method looks at the contents of {...}, treats it like a
specification to winnow down the set of available lots to a subset of ones
matching what you put in there (currency, cost basis, purchase date, label,
and any combination of those). If after filtering there is more than a
single lot, the "booking method" is invoked. If that is STRICT (the
default), an error is raised. If it is FIFO, the lots are eaten up until
there is a total amount matching the balancing number of units.

I hope this helps,




 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 post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/beancount/77653225-48df-4b1d-8e36-939a4ae6b138%40googlegroups.com
> <https://groups.google.com/d/msgid/beancount/77653225-48df-4b1d-8e36-939a4ae6b138%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/CAK21%2BhNWXTB_%2Bd8bsWCqM10xHW%2BE7MG9pAqPS%2Bh7x%2BYmksStcQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to