Christophe Rhodes writes:

[ More discussion below, but first a statement of exactly what I think I
  want ]

Consider the following ledger file:
--- begin ---
2012/06/01 Foo
  Assets:Foo  FOO1
  Assets:Checking  £-1.00

2012/06/01 Quux
  Assets:Quux  QUUX2
  Assets:Checking  £-2.00

P 2012/09/01 FOO £0.9
P 2012/09/01 BAZ £0.9

2013/02/01 Bar
  Assets:Bar  BAR1
  Assets:Checking  £-1.00

2013/02/01 Baz
  Assets:Baz  BAZ1
  Assets:Checking  £-1.00

2013/02/01 Quux
  Assets:Checking  £1.20
  Income:Capital Gain  £-0.20
  Assets:Quux  QUUX-1

P 2013/03/01 FOO £1.1
P 2013/03/01 BAR £1.2
P 2013/03/01 BAZ £1.2
P 2013/03/01 QUUX £1.3
---  end  ---
and the following reports, first a balance sheet as of 2013/01/01:

  ledger -f foo.dat --end 2013/01/01 -X £ bal Assets Liabilities

              £-0.10  Assets
              £-3.00    Checking
               £0.90    Foo
               £2.00    Quux
--------------------
              £-0.10

then an income/expense for the period 2013/01/01--2013/04/01:

  ledger -f foo.dat --begin 2013/01/01 --end 2013/04/01 --invert -X £ bal 
Income Expense

              £0.20  Income:Capital Gain

then a balance sheet for 2013/04/01:

  ledger -f foo.dat --end 2013/04/01 -X £ bal Assets Liabilities

               £1.00  Assets
               £1.20    Bar
               £1.20    Baz
              £-3.80    Checking
               £1.10    Foo
               £1.30    Quux
--------------------
               £1.00

Now, the "problem" is that the difference in the balance sheets is not
equal to the income/expense over the period.  What I am trying to do is
generate the report which "explains" the difference -- calculates the
difference in account at the end of the period due to commodity value
fluctuations.  Specifically, the report that I would like to generate
is:

              £0.90  Assets
              £0.20    Bar
              £0.20    Baz
              £0.20    Foo
              £0.30    Quux
-------------------
              £0.90

(To explain these figures: the one remaining QUUX has gone up in value
by £0.3 since 2013/01/01; the FOO which has been held throughout the
period has gone up by £0.2.  The value of the BAR which was bought
during the period has gone up by £0.2, and the value of the BAZ likewise
-- the tricky bit there is that the price of BAZ at the start of the
period is irrelevant; it's the value at purchase which is relevant.
And of course £-0.10 + £0.20 + £0.90 = £1.00 and the world is once more
in balance.)

I can /nearly/ generate this report.  With

  ledger -f foo.dat --format '%A 
%(P(T,[2013/03/31],"£")-P(T,[2013/01/01],"£"))\n' bal Assets

I get (slightly reformatted)
Assets BAR-1 {£1.00} [2013/02/01]
       £2.00
Assets:Bar BAR-1 {£1.00} [2013/02/01]
           £1.20
Assets:Baz £0.30
Assets:Checking 0
Assets:Foo £0.20
Assets:Quux £0.30

BAR-1 {£1.00} [2013/02/01]
£2.00

So here the answer for FOO and QUUX is exactly right.  Unfortunately,
the answer for BAR and BAZ is not; for BAR, ledger doesn't give me a
value for the commodity at all, and for BAZ it takes the too-early value
(before the commodity was purchased).

If instead of P (market) in the value expression above, there was a
valuation function which valued at the later of the date given and the
lot purchase price, I think the report would be exactly what I want
(well, minus all the fancy formatting :-).  I have made several false
starts on this already, so I could be wrong, but I did draw a diagram on
my office wall to convince myself this time...

Thoughts?  I hope that this example is clear enough to explain in one
place what I'm trying to do.

Thank you,

Christophe

-- 

--- 
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/groups/opt_out.


Reply via email to