minimum length of symbols?

117 views
Skip to first unread message

Jim Robinson

unread,
Sep 25, 2021, 12:13:23 AM9/25/21
to Beancount
At first glance I can't see that there is a way to override what beancount is doing here.

It appears as though it has some sort of an opinionated parsers as to what is considered valid for a Ticker Symbol, and it won't accept "V" (the symbol for Visa).  It appears to be wanting an all-uppercase > 1 length symbol, which isn't really valid for the real world.

Is there a way to override this behavior?  I'm not spotting anything on my first pass of the options documentation.

The following ledger fails to parse, complaining about an invalid token 'V' (specifically it is complaining about the use of the ticker symbol as a unit in "10.00 V", it's fine with the account name).

2014-02-16 open Assets:US:ETrade:Cash
2014-02-16 open Assets:US:ETrade:V
2014-02-16 open Expenses:Financial:Commissions
2014-02-16 open Equity:OpeningBalances

2014-02-16 * "Opening Balance"
  Assets:US:ETrade:Cash         10,000.00 USD
  Equity:OpeningBalances

2014-02-16 * Example purchase of stock symbol V (Visa)
  Assets:US:ETrade:V                      10.00 V {231.59 USD}
  Assets:US:ETrade:Cash        -23,159.00 USD
  Expenses:Financial:Commissions    9.95 USD

Jim Robinson

unread,
Sep 25, 2021, 12:18:26 AM9/25/21
to Beancount
Oh, and please forgive the unbalanced transaction issue, I was just messing around with the example documentation and hadn't corrected that problem when I ran into the 'Invalid token' issue I was complaining about.

Jim Robinson

unread,
Sep 25, 2021, 12:35:32 AM9/25/21
to Beancount
Huh, digging around in the source code I see it very specifically talks about "V" as being a valid currency symbol in v3:


It looks like my install is 2.3.4 (it was recommended on the homepage that we not use the master branch)

Martin Blais

unread,
Sep 25, 2021, 1:06:52 AM9/25/21
to Beancount
I was going to send a link to that section; you found it.
The C++ parser is in branch "master" but it's not hooked up yet, it won't be running.
I'm still working on finishing it (actually, these days).

My plan is to finish it, then to translate the booking code to C++  (with improvements in the design doc), and make a one-time conversion to Python objects, so we can use all the existing code and hook up the new parser.

Just use V_ in the meantime.
(Or trade options instead of single stocks... "V_211015_P222.5" is a valid currency symbol... you can sell ATM puts and size up a bit for equivalent delta exposure with a theta component.  Okay okay, never mind...)





--
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+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beancount/2436d5fd-314c-45c5-8853-8880588661afn%40googlegroups.com.

Jim Robinson

unread,
Sep 25, 2021, 2:20:56 AM9/25/21
to Beancount
Thank you for the confirmation.  I've never worked with flex, but I was wondering what it is that prevents adding a single-character token as an option?

E.g., in lexer.l adding one additional [A-Z] token?

198 [A-Z] {
199     return TOKEN(CURRENCY, yytext, yyleng);
200 }
201 [A-Z][A-Z0-9\'\.\_\-]*[A-Z0-9] {
202     return TOKEN(CURRENCY, yytext, yyleng);
203 }
204 \/[A-Z0-9\'\.\_\-]*[A-Z]([A-Z0-9\'\.\_\-]*[A-Z0-9])? {
205     return TOKEN(CURRENCY, yytext, yyleng);
206 }

In the spirit of blindly trying things I used the above change and it *seems* to parse OK.

(venv) $ cat ~/tmp/odd.beancount
2014-02-16 open Assets:US:ETrade:Cash
2014-02-16 open Assets:US:ETrade:V
2014-02-16 open Expenses:Financial:Commissions
2014-02-16 open Equity:OpeningBalances

2014-02-16 * "Opening Balance"
     Assets:US:ETrade:Cash    10,000.00 USD
       Equity:OpeningBalances

2014-02-16 * "Buying some V"
     Assets:US:ETrade:V               10.00 V {231.59 USD}
     Assets:US:ETrade:Cash

(venv) $ bean-query ~/tmp/odd.beancount
Input file: "Beancount"
Ready with 6 directives (4 postings in 2 transactions).
beancount> balances
        account                           sum_position
----------------------          --------------------------
Assets:US:ETrade:Cash         7684.10 USD
Assets:US:ETrade:V                  10.00 V {231.59 USD}
Equity:OpeningBalances     -10000.00 USD

Martin Blais

unread,
Sep 25, 2021, 2:22:08 AM9/25/21
to Beancount
Sorry mate v2 is frozen. Not enough cycles to work on two versions.


Jim Robinson

unread,
Sep 25, 2021, 2:26:12 AM9/25/21
to Beancount
Oh, I was not suggesting you change v2.  I can do that easily enough myself and install a patched version.  What I was wondering was whether or not doing so might introduce some critical bug.

Daniele Nicolodi

unread,
Sep 25, 2021, 5:44:09 AM9/25/21
to bean...@googlegroups.com
On 25/09/2021 08:26, Jim Robinson wrote:
> Oh, I was not suggesting you change v2.  I can do that easily enough
> myself and install a patched version.  What I was wondering was whether
> or not doing so might introduce some critical bug.

In Beancount v2 some upper case characters are valid transaction flags.

Depending on where in the lexer definition you inserted the rule that
recognizes single upper case characters as commodity symbols, either
some single uppercase characters will be miss classified as currency
symbols when they are flags, or the other way around, resulting in
syntax errors in the grammar. The Beancount lexer is not context aware,
thus there is no way out of this and this is the main reason for the
current lexer behavior.

While upper case characters as flags are not very common, they are used
internally by Beancount to mark some transactions that are inserted
automatically at booking time.

The v3 parser requires single uppercase character flags to be prefixed
with a quote symbol thus resolving the ambiguity.

Cheers,
Dan

Martin Blais

unread,
Sep 25, 2021, 8:50:55 AM9/25/21
to Beancount
Precisely 
Thanks Daniele

--
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+...@googlegroups.com.

Jim Robinson

unread,
Sep 27, 2021, 2:12:37 PM9/27/21
to Beancount
Thank you for the explanation.  I guess I'll just use <exchange>_<symbol> in the interim (I don't want to have special logic in place for symbols based on how long they are).
Reply all
Reply to author
Forward
0 new messages