Getting commodity tracking working for individual securities

122 views
Skip to first unread message

Sagar Shankar

unread,
Oct 28, 2023, 11:34:03 PM10/28/23
to bean...@googlegroups.com
Hi,

I'm trying to import my mutual fund transactions into Beancount. The mutual fund security names are in the format, "ADIT_BSL_FRON_YK3Z7Z", which are the ticker names from Google Finance. 

Initially I had tried to create transactions like:
Assets:Broker:ADIT_BSL_FRON_YK3Z7Z  100 ADIT_BSL_FRON_YK3Z7Z {10 USD}
Assets:Broker:ADIT_BSL_NIFT_136TO8I  100 ADIT_BSL_NIFT_136TO8I {9 USD}
and so and so forth.

This threw up a "Invalid Token" error. So I thought, maybe Beancount has some restrictions on account names. So then I moved to the following format:
Assets:Broker  100 ADIT_BSL_FRON_YK3Z7Z {10 USD}
Assets:Broker  100 ADIT_BSL_NIFT_136TO8I {9 USD}
and I'm now getting an "Invalid Currency" error. 

I'm following the examples from this page - https://beancount.github.io/docs/how_inventories_work.html, as what I want to achieve is:
1. Track per security inventory
2. Track cost basis and networth, the latter by pulling the latest market price from Google Finance.

Appreciate any advice on how to get this working

Thanks
Sagar

Sagar Shankar

unread,
Oct 28, 2023, 11:44:43 PM10/28/23
to bean...@googlegroups.com
Sorry, I forgot to mention that I'm only facing this issue for securities in this name format.

Other securities, like ITC or INFY, dont have this issue.

For them, I'm able to track like:
Assets:Broker:ITC  100 ITC {10 USD}
Assets:Broker:INFY  100 INFY {9 USD}

Thanks
Sagar

Martin Blais

unread,
Oct 28, 2023, 11:44:47 PM10/28/23
to bean...@googlegroups.com
The problem is not your currencies, it's the account names.
Account names do not support underscores. Use dashes instead.
(They probably should (mabe), but I'm not going to change the syntax in stable/v2).

I'm not sure what the invalid currency error is, needs more detail

--
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/CAAP45exGz6rcYUAj5AgCgzQFn16DRKxprbse74R3bUJR2UuTTw%40mail.gmail.com.

Sagar Shankar

unread,
Nov 11, 2023, 4:23:00 AM11/11/23
to Beancount
Hi Martin, sorry for the late reply. For some reason I never got this digest in my email inbox.

OK, understood about the underscores and using dashes instead. Problem is that the tickers for these funds in Google Finance use underscores - which means updating the prices on a regular basis won't work, if I understood the part of price fetching correctly

Thanks
Sagar

Sagar Shankar

unread,
Nov 11, 2023, 5:38:28 AM11/11/23
to Beancount
Well, looks like bean-price doesn't support Google Finance. That was a bit confusing since the documentation still refers to google finance and I had to go down the issues in the mailing list and the GitHub repo for bean-price to figure that part out.

The issue with Yahoo Finance is that for some Indian securities, it uses the format, 0P0000XVUH.BO, which bean count doesn't accept since it starts with a zero. Using the Yahoo Finance website and the ISIN, INF846K01EH3 works. But that doesn't work for bean-price and it returns an error with the ISIN.

So I'm a bit stumped on what to do. Appreciate any suggestions!

Thanks,
Sagar

Patrick Ruckstuhl

unread,
Nov 11, 2023, 6:12:51 AM11/11/23
to bean...@googlegroups.com

Hi Sagar,

you don't need to use the same symbol name in beancount as you use for lookup. You can define it in the commodity metadata


e.g. something like (I'm using alphavantage price source here, but yahoo should work the same way)

2010-01-01 commodity MYSUPERCOMMODITY
    price: "USD:alphavantage/price:TSLA:USD"

Sagar Shankar

unread,
Nov 11, 2023, 7:32:15 AM11/11/23
to Beancount
Hi Patrick, that's super useful!

That's got it working at the command-line! I can run bean-price -e ledger.beancount and it pulls in the data from Yahoo Finance.

However, if I try to get it to update the ledger file with bean-price --update ledger.beancount, fails with TypeError: conversion from NoneType to Decimal is not supported
Using the clear-cache and no-cache also doesn't fix this

It looks very similar to this issue on https://github.com/beancount/beanprice/issues/60

Any advice? I'm on a Mac btw and I've installed the gdbm 3.11 dependency using Homebrew

Thanks,
Sagar
Reply all
Reply to author
Forward
0 new messages