Hi,
I'm trying to complete my Beancount to Ledger syntax converter. There's
only one issue left.

I have some transactions like this in my Beancount file:

2014-11-02 open Expenses:Commissions
2014-11-02 open Assets:CA:Investment:GOOG
2014-11-02 open Assets:CA:Investment:Cash

2014-11-02 * "Buy some stock with foreign currency funds (CAD -> USD)"
  Assets:CA:Investment:GOOG          5 GOOG {520.0 USD}
  Expenses:Commissions            9.95 USD
  Assets:CA:Investment:Cash   -2939.46 CAD @ 0.8879 USD


Specifically, what I mean is that I have postings taking cash in a foreign
currency (the third) and other postings held at cost (the first). This is
not a theoretical use case BTW, in my past account history I have an
account in a foreign currency that is used to buy stocks on the US market
and the conversion occurs this way, automatically and atomically (I'm
trying to convert my real ledger file to Ledger, for comparison purposes).

My converter script translates this to a Ledger equivalent:

account Expenses:Commissions
account Assets:CA:Investment:GOOG
account Assets:CA:Investment:Cash

2014/11/02 * Buy some stock with foreign currency funds (CAD -> USD)
  Assets:CA:Investment:GOOG
5.00 GOOG     {520.00 USD}
  Expenses:Commissions
9.95 USD
  Assets:CA:Investment:Cash
-2,939.46 CAD                  @ 0.887900000000 USD

P 2014/11/02 00:00:00 GOOG                   520.00 USD
P 2014/11/02 00:00:00 CAD                   0.88790 USD

This does not work, however, Ledger appears not to grok it:

ledger -f
/Users/blais/p/beancount-data/foreign-paid-stock-purchase.beancount bal
While parsing file
"/Users/blais/p/beancount-data/foreign-paid-stock-purchase.beancount", line
8:
While balancing transaction from
"/Users/blais/p/beancount-data/foreign-paid-stock-purchase.beancount",
lines 5-8:
> 2014-11-02 * "Buy some stock with foreign currency funds (CAD -> USD)"
>   Assets:CA:Investment:GOOG          5 GOOG {520.0 USD}
>   Expenses:Commissions            9.95 USD
>   Assets:CA:Investment:Cash   -2939.46 CAD @ 0.8879 USD
Unbalanced remainder is:
 5 GOOG {520.00 USD}
        -2600.00 USD
Amount to balance against:
 5 GOOG {520.00 USD}
            9.95 USD
Error: Transaction does not balance

Changing the price conversion to a {} stock conversion also fails:

2014/11/07 * Buy some stock with foreign currency funds (CAD -> USD)
  Assets:CA:Investment:GOOG
5.00 GOOG     {520.00 USD}
  Expenses:Commissions
9.95 USD
  Assets:CA:Investment:Cash
-2,939.46 CAD     {0.887900000000 USD}

I get similar error messages.
So I tried simplifying some more by removing the commissions leg, adjusting
the price:

2014/11/06 * Buy some stock with foreign currency funds (CAD -> USD)
  Assets:CA:Investment:GOOG
5.00 GOOG     {520.00 USD}
  Assets:CA:Investment:Cash
-2,928.2577 CAD  @ 0.887900000000 USD

Ledger isn't happy about this either. But changing the currency conversion
to a cost-style conversion (which intuitively appears to me wrong, this is
not a lot to be tracked, but whatever, at this point I'm just trying to get
syntax that works), it seems to accept it:
2014/11/06 * Buy some stock with foreign currency funds (CAD -> USD)
  Assets:CA:Investment:GOOG
5.00 GOOG     {520.00 USD}
  Assets:CA:Investment:Cash
-2,928.2577 CAD  {0.887900000000 USD}

So based on the above, Ledger _does_ treat @ price vs. {price} rates at
least somewhat differently.
If I add the commissions leg back to the previous transaction (adjusting
the numbers correctly), it stops accepting it.
I'm confused.

I have two questions:

1. Can somebody explain how the treatment of "@ price" vs. "{price}"
differs? Other members of this list have previously pointed out to the docs
that say that they are entirely equivalent. Based on the previous change,
they appear not to be. This needs clarification IMO.

2. What is the correct way to convert my original transaction to Ledger
syntax?

3. More generally, what is the rule for what combinations of price/cost
conversions it should be able to accept or not?

Thank you,

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to