Issue #186: Cost & price currency should be coerced to be equal (blais/beancount)

2017-08-18 Thread Martin Blais
New issue 186: Cost & price currency should be coerced to be equal
https://bitbucket.org/blais/beancount/issues/186/cost-price-currency-should-be-coerced-to

Martin Blais:

Somehow this doesn't raise an error anymore... fix this ASAP.

Responsible: blais

-- 
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 beancount+unsubscr...@googlegroups.com.
To post to this group, send email to beancount@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/20170819054627.5678.90968%40celery-worker-105.ash1.bb-inf.net.
For more options, visit https://groups.google.com/d/optout.


Re: can one reduce FIFO lots purchased in one currency and sold in another?

2017-08-18 Thread Martin Blais
On Fri, Aug 18, 2017 at 6:32 PM,  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  BTC449.24 USD
> 2016-05-25  price  EUR1.12 USD
> 2016-05-27  price  BTC474.38 USD
> 2016-05-27  price  EUR1.11 USD
>
> 2016-05-25 * "Coinbase" "Bitcoin purchase"
> Expenses:Crypto:Fees:Coinbase4.60 USD
> Assets:Crypto:Bitcoin1.0214 BTC {450.07 USD}
> Assets:Checking:CapitalOne-464.30 USD
>
> 2016-05-27 * "(s9d8fukf0)" "Sell BTC via bitsquare"
> Assets:Crypto:Bitcoin   -0.5000 BTC {USD} @ 416.75 EUR
> Assets:Checking:BNP208.38 EUR
> Income:CapitalGains
>
> 2016-05-27 * "(l2l3jfp5d)" "Sell BTC via bitsquare"
> Assets:Crypto:Bitcoin   -0.5000 BTC {USD} @ 412.00 EUR
> Assets:Checking:BNP206.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.5000 BTC {USD}
Assets:Checking:BNP208.38 EUR @ 1/416.75 USD
Income:CapitalGains

2016-05-27 * "(l2l3jfp5d)" "Sell BTC via bitsquare"
Assets:Crypto:Bitcoin   -0.5000 BTC {USD}
Assets:Checking:BNP206.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:Bitcoin1.0214 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.5000 BTC {450.07 USD, 2016-05-25}
 ;-225.035000 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.035000 USD)

 Balances after transaction

* Assets:Crypto:Bitcoin0.5214 BTC {450.07 USD, 2016-05-25}

* Assets:Checking:BNP   208.38 EUR

* Income:CapitalGains224.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 

can one reduce FIFO lots purchased in one currency and sold in another?

2017-08-18 Thread jkepler
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  BTC449.24 USD
2016-05-25  price  EUR1.12 USD
2016-05-27  price  BTC474.38 USD
2016-05-27  price  EUR1.11 USD

2016-05-25 * "Coinbase" "Bitcoin purchase"
Expenses:Crypto:Fees:Coinbase4.60 USD
Assets:Crypto:Bitcoin1.0214 BTC {450.07 USD}
Assets:Checking:CapitalOne-464.30 USD

2016-05-27 * "(s9d8fukf0)" "Sell BTC via bitsquare"
Assets:Crypto:Bitcoin   -0.5000 BTC {USD} @ 416.75 EUR
Assets:Checking:BNP208.38 EUR
Income:CapitalGains

2016-05-27 * "(l2l3jfp5d)" "Sell BTC via bitsquare"
Assets:Crypto:Bitcoin   -0.5000 BTC {USD} @ 412.00 EUR
Assets:Checking:BNP206.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

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?

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? 
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 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).


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