Limit to securities in specific currency

27 views
Skip to first unread message

lipp f

unread,
Mar 16, 2024, 8:37:32 AMMar 16
to Ledger
In my portfolio account I have US / CA / EU securities and I would like get balance by market.
Wondering if there is a way to have a limit filter able to  limit to securities in specific currency in ledger bal / reg. 

TIA.

Martin Michlmayr

unread,
Mar 16, 2024, 9:24:53 AMMar 16
to ledge...@googlegroups.com
* lipp f <flip...@gmail.com> [2024-03-16 05:37]:
-l "commodity == 'EUR'"

Note that quoted commodities need to be quoted properly:

-l "commodity == '\"GB00BPN5P782\"'"

--
Martin Michlmayr
https://www.cyrius.com/

lipp f

unread,
Mar 16, 2024, 10:12:21 AMMar 16
to Ledger
none of your solutions work.
- the first one,  -l "commodity == 'EUR'", will only filter the EUR cash balance.
- the second one, -l "commodity == '\"GB00BPN5P782\"'", only filters one specific commodity.
the request was to filter bal or reg for all securities in specific currency, without listing each individual securities for currency. listing all securities for currency is actually part of the question.

Tavis Ormandy

unread,
Mar 16, 2024, 12:10:45 PMMar 16
to ledge...@googlegroups.com
I can't parse the question, can you show an example of two commodity
purchases from different markets, and the output you're trying to get?

I think what you're asking for is --group-by, but are you using tags, or
accounts, or do you differentiate them based on purchase currency?

If tags, try --group-by 'tag("exchange")', or for purchase currency,
maybe something like --group-by 'commodity(lot_price(amount))'.

Tavis.

--
_o) $ lynx lock.cmpxchg8b.com
/\\ _o) _o) $ finger tav...@sdf.org
_\_V _( ) _( ) @taviso

lipp f

unread,
Mar 16, 2024, 1:01:29 PMMar 16
to Ledger
sure. let's assume the I have the following in the broker account:
- 1000 AAPL @  172.62USD
- 1000 CNR.TO @ 174.28CAD
- 1000 BAYN.DE @ 26.24EUR
- 100 USD cash
- 100 CAD cash
- 100 EUR cash
the value of all assets priced in EUR is 1000 BAYN.DE @ 26.24EUR plus 100 EUR cash, which means 26340EUR. i want to limit bal / reg to those two assets.
-

Tavis Ormandy

unread,
Mar 16, 2024, 1:07:51 PMMar 16
to ledge...@googlegroups.com
On 2024-03-16, lipp f wrote:
> sure. let's assume the I have the following in the broker account:
> - 1000 AAPL @ 172.62USD
> - 1000 CNR.TO @ 174.28CAD
> - 1000 BAYN.DE @ 26.24EUR
> - 100 USD cash
> - 100 CAD cash
> - 100 EUR cash
> the value of all assets priced in EUR is 1000 BAYN.DE @ 26.24EUR plus 100
> EUR cash, which means 26340EUR. i want to limit bal / reg to those two
> assets.
> *-*
>

I see, I think maybe --limit 'commodity(lot_price(amount)) == "EUR"',
but try --group-by too.

(You might need to tweak it, depends on how you record things)

lipp f

unread,
Mar 16, 2024, 1:40:34 PMMar 16
to Ledger
this is my test file:
2024-1-1 Opening Balances
        assets:broker           1000 AAPL
        assets:broker           1000 "CNR.TO"
        assets:broker           1000 "BAYN.DE"
        assets:broker           100 USD
        assets:broker           100 CAD
        assets:broker           100 EUR
            Equity:Opening Balances      -1000 AAPL
            Equity:Opening Balances      -1000 "CNR.TO"
            Equity:Opening Balances      -1000 "BAYN.DE"
            Equity:Opening Balances      -100 USD
            Equity:Opening Balances      -100 CAD
            Equity:Opening Balances      -100 EUR
P 2024-03-15  AAPL 172.62USD
P 2024-03-15  "CNR.TO" 174.28CAD
P 2024-03-15  "BAYN.DE" 26.24EUR

and these are the results:
$ ledger -f test.j  --args-only bal assets:broker --limit 'commodity(lot_price(amount)) == "EUR"'
             100 EUR  assets:broker
$ ledger -f test.j  --args-only bal assets:broker --group-by 'commodity(lot_price(amount))'
"BAYN.DE"
        1000 BAYN.DE  assets:broker

"CNR.TO"
         1000 CNR.TO  assets:broker

AAPL
           1000 AAPL  assets:broker

CAD
             100 CAD  assets:broker

EUR
             100 EUR  assets:broker

USD
             100 USD  assets:broker

not what was expected.

o1bigtenor

unread,
Mar 16, 2024, 4:13:22 PMMar 16
to ledge...@googlegroups.com
IANAA but it seems to me that you are trying to do something in one set of books that just isn't normally done. 

AIUI when I set up my books (and still use this) a set of books was designated in one currency with 
all transactions in any other currency being done in the 'home' currency.  (And yes I do at least
some work in other currencies. Even large companies - - - ie multi-national ones do similar.
Work is done in one currency and then when a report is pulled (closing at say 20240115 for arguments
sake) all the ledgers are closed in the main ledger which is in one currency and all the other currencies
are adjusted into that one currency.

Is not that you can't have more than one currency in a set of books but then what you have is
currency related 'messy'. So - - - in a microcosm you get to do what that multinational company
does - - - use different account numbers for similar functions in each of the different currencies.
Ja - - - its a pain - - - but your trying to stuff a dodecahedron into a sphere and wondering why the
balloon is popping - - - but the ballon was never designed to hold the dodecahedron.

In my books in account '1000' which is

Cash

bank drafts, bank notes, checks, coins, currency, money orders, postal notes and post-dated checks


I have different account numbers (yes I use more than 4 digits and the newer system which uses 5 digits

and is quite new I haven't adjusted to yet (GIFI courtesy of your tax bureaucracy) for each of the cash

items. I do this so I can pull up the asset values in each currency BUT my books are still done in ONE

currency.


This kind of thing is NOT going to make your books easier but if you get audited it will make them

easier to follow by whomever is doing that (which will likely make things easier for you at that point!!).


HTH


Tavis Ormandy

unread,
Mar 16, 2024, 5:45:47 PMMar 16
to ledge...@googlegroups.com
On 2024-03-16, lipp f wrote:
> not what was expected.

Right, but you said you paid for them in USD or CAD or whatever, and
that was how you were defining which exchange they were on. If you paid
for them in USD, then they were on the US exchange, and so on.. that
makes perfect sense!

However you're not *recording* that - you didn't record the lot price (i.e. the
cost basis), so ledger doesn't know what currency you paid with.

For example, which exchange did this transaction occur on?

assets:broker 1000 "AAPL"

I think you just "know" that AAPL trades on the NASDAQ, but ledger
doesn't know that. You could tell ledger that with tags, like this:

assets:broker 1000 "AAPL" ; exchange: US

Or record them with cost basis, like this:

assets:broker 1000 "AAPL" @ $10

Then it will work... shrug.

Tavis Ormandy

unread,
Mar 16, 2024, 5:53:41 PMMar 16
to ledge...@googlegroups.com
On 2024-03-16, Tavis Ormandy wrote:
> On 2024-03-16, lipp f wrote:
>> not what was expected.
>
> However you're not *recording* that - you didn't record the lot price (i.e. the
> cost basis), so ledger doesn't know what currency you paid with.
>
> For example, which exchange did this transaction occur on?
>
> assets:broker 1000 "AAPL"
>
> I think you just "know" that AAPL trades on the NASDAQ, but ledger
> doesn't know that. You could tell ledger that with tags, like this:
>
> assets:broker 1000 "AAPL" ; exchange: US
>
> Or record them with cost basis, like this:
>
> assets:broker 1000 "AAPL" @ $10
>
> Then it will work... shrug.
>

Oh, I guess if you only ever record the price history in one currency
and don't want to log cost basis, maybe you can do
commodity(market(amount)) instead of commodity(lot_price(amount))...
kinda hacky, but might work.

lipp f

unread,
Mar 16, 2024, 6:29:01 PMMar 16
to Ledger
hey, that works.  thanks.

$ ledger -f test.j  --args-only bal assets:broker --limit 'commodity(market(amount)) == "EUR"'
        1000 BAYN.DE
             100 EUR  assets:broker

$ ledger -f test.j  --args-only bal assets:broker --limit 'commodity(market(amount)) == "EUR"' -X EUR
           26340 EUR  assets:broker

$ ledger -f test.j  --args-only bal assets:broker --group-by 'commodity(market(amount))'
CAD
             100 CAD
         1000 CNR.TO  assets:broker

EUR
        1000 BAYN.DE

             100 EUR  assets:broker

USD
           1000 AAPL
             100 USD  assets:broker


Reply all
Reply to author
Forward
0 new messages