On Sun, Aug 4, 2019 at 6:25 AM John Wiegley <[email protected]> wrote:
>
> >>>>> "YK" == Yuri Khan <[email protected]> writes:
>
> YK> What else can I try in order to get a stream of postings normalized to a
> YK> single currency? (`ledger reg -X RUB` works but I would very much dislike
> YK> to scrape its output.)
>
> Does --no-revalued help with the query?

I was thinking I tried that, but it turns out I didn’t. Yes,
--no-revalued affects all of: ledger print, ledger xml, and
legder.Journal.query. Thank you.

Now it appears what I asked for is not what I need :) So I will
describe the bigger picture.

I have a Python script that takes a Ledger journal and a query, and
produces a stacked graph of each account’s balance over time.
Currently, it supports only a single currency, ignoring all the
others.

https://github.com/yurikhan/ledger-d3/

I am currently extending it so that it can track investments. I was
thinking I could add -X RUB --no-revalued to the query, but that
freezes each investment’s price to the value it had at the time of
purchase. I want to track currency prices throughout the time range.

To that end, I calculate partial sums in each currency separately,
which gives me a mapping (date, account, currency) → balance. Then, in
order to plot the graph, I need to know the price of each currency at
each given date.

I have found ledger.Commodity.find_price which accepts a base
Commodity and two time points, but I seem to be unable to use it from
Python:

    #!/usr/bin/python

    from datetime import datetime
    import ledger

    journal = ledger.read_journal('test1.ledger')
    usd = ledger.commodities.find('USD')
    rub = ledger.commodities.find('RUB')
    print(usd.find_price(rub, datetime(2019,2,1), datetime(1970,1,1))

    Traceback (most recent call last):
      File "./test_price.py", line 9, in <module>
        print(usd.find_price(rub, datetime(2019,2,1), datetime(1970,1,1)))
    TypeError: No to_python (by-value) converter found for C++ type:
boost::optional<ledger::price_point_t>

There are more things in the Python API that use unexposed types:

* AutomatedTransaction.extend_xact accepts a parse_context_t as its
second argument
* PeriodicTransaction.period has type date_interval_t


PS: I was able to solve my problem using Amount.value(Commodity,
date). Still, having to backtrack from that find_price dead end took
me some time.

-- 

--- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ledger-cli/CAP_d_8UOMQOpmq3g5xJfcZyS-8o2c9dNf4C2AQP39-hqcF0auw%40mail.gmail.com.

Reply via email to