Re: New option: --time-report

2012-03-14 Thread Jim Robinson
On Tuesday, March 13, 2012 9:38:30 PM UTC-7, John Wiegley wrote:

 I tried to go to bed, failed, got out of the bed at 7am, crawled 
 downstairs,
 implemented select queries, came back up and crashed.  I think it took 
 about 3
 hours to implement, which shows you how well structured Ledger has become
 internally that I was able to create this feature almost entirely within a
 single file (select.cc), not having to munge any of the rest of the code.

 If anything, what slows me down is C++ compile times, since it takes 2-3
 minutes to build after every header file change, generally.  I'm looking
 forward to upgrading my 8-core Mac Pro to the Ivy Bridge platform sometime 
 in
 the next year.

 BTW - My company (boostpro.com) does C++ consulting services, if anyone is
 ever looking to hire a mad coder. ;)

 John

Well that's pretty amazing (on multiple counts).   I'm going to go and build
the latest branch of next and play around with select, it looks as though 
it's
an effective replacement to a number of aggregating shell+awk scripts I
currently use.

As a random aside, maybe you'd be interesting in looking 
 at http://golang.org/, I
recall that of the reasons authors cited for writing yet 
another programming language
is that they were sick of the multi-hour C++ recompile times!

Jim



Having Ledger calculate a commodity / exchange rates by telling it an entry balances

2012-03-14 Thread Kamal Marhubi
Hi,

Is it possible to tell Ledger an entry with transactions in two commodities / 
currencies balances, so that it can calculate the exchange rate?

Motivating situation: I am in the US, and I withdrew, say, USD 200.00 from my 
Canadian chequing account.  The ATM here charged me USD 2.50 as an additional 
fee.  The withdrawal shows up in my online banking as CAD 203.42 or something 
like that.  In addition to this, my bank in Canada charged me a CAD 2.00 fee.  
I would like to write something like the following:

2012-03-12 * Withdrawal
Assets:Cash   USD 200.00 
Expenses:Banking:Fees   USD 2.50
Assets:Chequing CAD -203.42
Expenses:Banking:Fees   CAD 2.00
Assets:ChqeuingCAD -2.00

and tell Ledger that this balances, so it can work out the rate.  I have used 
the @@ in the past, but that was on withdrawals in the UK where the ATMs do not 
charge fees.  Dealing with the CAD fee is simple, it's the USD fee here that is 
throwing things off; the only way I can see is to do a manual calculation of 
the portion that the USD 2.50 makes up of the CAD 203.42.  This seems wrong.  
Is there a way to get Ledger to do what I want?

Thanks,

-Kamal

Re: Accounting for currency gains/losses

2012-03-14 Thread thierry
Hi John,
With recent improvments on ledger, do you think that this thread can be 
solved?
Thanks
Thierry

On Monday, May 3, 2010 3:00:49 AM UTC+2, John Wiegley wrote:

 On May 2, 2010, at 8:57 PM, Peter Ross wrote: 

  However it doesn't handle the case of unrealized currency gains. 
  
  I added the line 
  
  P 2009/02/15 EUR 1.90 AUD 
  
  to your example above and here is my balance sheet on that date 
  
  $ ledger -f invoice3.dat -X AUD -e 2009/02/15 bal assets liabilities 

 Use of pricing entries only affects -X reports that contain the priced 
 commodity.  You are correct that I do not register unrealized gains as a 
 real gain.  We had a huge discussion about this on #ledger over the course 
 of a few days, but I was unable to come up with a convincing solution, 
 despite spending a few hours coding a couple alternatives. 

 John 



Re: Metadata on commodity level

2012-03-14 Thread Jim Robinson
I'm sure that I'm doing it wrong but I just fake it by adding 
sub-categories for different funds (or stocks), so, for example:

2011-12-30 * Fidelity - 403b Dividend
Assets:403b:Fidelity:VBMPX  2.493 VBMPX @@ 
$27.42
Income:403b:Fidelity:VBMPX -$27.42




Girlfriends budget?

2012-03-14 Thread Raphael Lorenzeto
Guys,

What would be the best way to implement a budget so I could track how much 
I'm overspending with my girlfriend?

So far I register all transactions as happen... Going to the movies - 
Expenses:Entertainment:Movies, fueling the car to go to her house - 
Expenses:Transportation:Fuel and so on. I tag these postings with 
:grilfriend:.

There is no Expenses:Girlfriend root account and as far as I could 
understand the docs there is no way to do a periodic transaction based only 
on tags, not accounts.

Should I create an automatic transaction based on the :girlfriend: tag to a 
virtual account and balance that? Is this the best way?

Thanks!


Re: A word on Ledger structure

2012-03-14 Thread Jim Robinson
On Tuesday, March 13, 2012 10:45:10 PM UTC-7, John Wiegley wrote:

 And that's Ledger in a nutshell.  All the rest are details


I believe the term is a small matter of programming. :-D
 
Thanks very much for posting this overview, it's very interesting
to read how it is all laid out.

Jim



Re: Girlfriends budget?

2012-03-14 Thread Raphael Lorenzeto
Actually, let me rephrase that:

Is there any way to do tag-based budget?

Provided that I cannot use a single account root for any given group of 
expense and if tag-based budgeting is not a possibility, are automatic 
transactions the right way to go?

On Wednesday, March 14, 2012 8:38:38 PM UTC-3, Raphael Lorenzeto wrote:

 In fact we do have plans, but we are also well aware of how we spend our 
 money. She is a Gnucash user and she has a budget for me as well but this 
 is not the point. :-)

 My question still stands.


 On Wednesday, March 14, 2012 8:30:05 PM UTC-3, enderw88 wrote:

 If you have any idea of her becoming more than a girlfriend in the 
 future, then stop this effort right now. 




 -- 
 Craig, Corona De Tucson, AZ
 enderw88.wordpress.com



Re: Calculating Asset Allocation

2012-03-14 Thread Craig Earls
I have been building the latest ledger but I am still using a custom build
witha few tweeks of my own.  I need to switch so I can see if anything I
need has broken. (I have modified mine to tag automatic transactions as
cleared if the base transaction is cleared and I have a special tag that
returns only the filename, and not the entire path.

I will check this out.

On Wed, Mar 14, 2012 at 17:16, Jim Robinson jim.robin...@gmail.com wrote:

 This is awesome, thanks for writing it up.  I tried it out and found
 that ledger  3.0.0-20120217 complaints about not understanding
 the format string:

 While calculating format expression:
   percent(market(display_total), market((parent.total)))
 While evaluating value expression:
   percent(market(display_total), market((parent.total)))
 ^^
 While calling function 'market #EXPR (parent.total)':
 While calling function 'percent (#EXPR market(display_total), #EXPR
 market((parent.total)))':
 Error: Left operand does not evaluate to an object

 While I did find that this appeared to work:

   ledger balance -X '$' Allocation --current -%


 Jim




-- 
Craig, Corona De Tucson, AZ
enderw88.wordpress.com


Re: Girlfriends budget?

2012-03-14 Thread Raphael Lorenzeto
I don't mind :p, this works perfectly, however it is not what I was looking 
for.

Can I use the budgeting feature as described in @chapter Budgeting and 
Forecasting, line 5320 of ledger3.texi with tags?

Is it possible do define ---

~ Monthly
   :girlfriend:   $100,00

--- and have it work with ledger --budget?



On Wednesday, March 14, 2012 9:15:37 PM UTC-3, enderw88 wrote:

 :) I shouldn't have been so flip.  I am not certain exactly what you want 
 to do.  If you just want to know how much you have spent on the girlfriend 
 you can do balance and register reports limited to the girlfriend tag:

 ledger bal --limit has_tag('Girlfriend')

 and similar for register.

 On Wed, Mar 14, 2012 at 16:38, Raphael Lorenzeto wrote:

 In fact we do have plans, but we are also well aware of how we spend our 
 money. She is a Gnucash user and she has a budget for me as well but this 
 is not the point. :-)

 My question still stands.


 On Wednesday, March 14, 2012 8:30:05 PM UTC-3, enderw88 wrote:

 If you have any idea of her becoming more than a girlfriend in the 
 future, then stop this effort right now. 




 -- 
 Craig, Corona De Tucson, AZ
 enderw88.wordpress.com




 -- 
 Craig, Corona De Tucson, AZ
 enderw88.wordpress.com



Re: A word on Ledger structure

2012-03-14 Thread Alexandre Rademaker
Hello John,

Many thanks for this email. Does cl-ledger (lisp version) has similar
architecture? What are the differences? I don't know how many of the
ledger's users are programmers but making Ledger's architecture more
transparent will, for sure, help people understand and contribute to
ledger.

Best,

Alexandre Rademaker
http://arademaker.github.com/



On Wed, Mar 14, 2012 at 2:45 AM, John Wiegley jwieg...@gmail.com wrote:
 Ledger is developed as a tiered set of functionality, where lower tiers no
 nothing about the higher tiers.  In fact, I build multiple libraries during
 the process, and link unit tests to these libraries, so that it is a link
 error for a lower tier to violate this modularity.

 Those tiers are:

  - Utility code

   There's lots of general utility in Ledger for doing time parsing, using
   Boost.Regex, error handling, etc.  It's all done in a way that can be
   reused in other projects as needed.

  - Commoditized Amounts (amount_t, commodity_t and friends)

   An numerical abstraction combining multi-precision rational numbers (via
   GMP) with commodities.  These structures can be manipulated like regular
   numbers in either C++ or Python (as Amount objects).

  - Commodity Pool

   Commodities are all owned by a commodity pool, so that future parsing of
   amounts can link to the same commodity and established a consistent price
   history and record of formatting details.

  - Balances

   Adds the concept of multiple amounts with varying commodities.  Supports
   simple arithmetic, and multiplication and division with non-commoditized
   values.

  - Price history

   Amounts have prices, and these are kept in a data graph which the amount
   code itself is only dimly aware of (there's three points of access so an
   amount can query its revalued price on a given date).

  - Values

   Often the higher layers in Ledger don't care if something is an amount or a
   balance, they just want to add stuff to it or print it.  For this, I
   created a type-erasure class, value_t/Value, into which many things can be
   stuffed and then operated on.  They can contain amounts, balances, dates,
   strings, etc.  If you try to apply an operation between two values that
   makes no sense (like dividing an amount by a balance), an error occurs at
   runtime, rather than at compile-time (as would happen if you actually tried
   to divide an amount_t by a balance_t).

   This is the core data type for the value expression language.

  - Value expressions

   The next layer up adds functions and operators around the Value concept.
   This lets you apply transformations and tests to Values at runtime without
   having to bake it into C++.  The set of functions available is defined by
   each object type in Ledger (posts, accounts, transactions, etc.), though
   the core engine knows nothing about these.  At its base, it only knows how
   to apply operators to values, and how to pass them to and receive them from
   functions.

  - Query expressions

   Expressions can be onerous to type at the command-line, so there's a
   shorthand for reporting called query expressions.  These add no
   functionality of there own, but are purely translated from the input string
   (cash) down to the corresponding value expression (account =~ /cash/).
   This is a convenience layer.

  - Format strings

   Format strings let you interpolate value expressions into string, with the
   requirement that any interpolated value have a string representation.
   Really all this does is calculate the value expression in the current
   report context, call the resulting value's to_string() method, and stuffs
   the result into the output string.  It also provides printf-like behavior,
   such as min/max width, right/left justification, etc.

  - Journal items

   Next is a base type shared by anything that can appear in a journal: an
   item_t.  It contains details common to all such parsed entities, like what
   file and line it was found on, etc.

  - Journal posts

   The most numerous object found in a Journal, postings are a type of item
   that contain an account, an amount, a cost, and metadata.  There are some
   other complications, like the account can be marked virtual, the amount
   could be an expression, etc.

  - Journal transactions

   Postings are owned by transactions, always.  This subclass of item_t knows
   about the date, the payee, etc.  If a date or metadata tag is requested
   from a posting and it doesn't have that information, the transaction is
   queried to see if it can provide it.

  - Journal accounts

   Postings are also shared by accounts, though the actual memory is managed
   by the transaction.  Each account knows all the postings within it, but
   contains relatively little information of its own.

  - The Journal object

   Finally, all transactions with their postings, and all accounts, are owned
   by a journal_t object.  This is the go-to object for querying ad reporting
   

Re: Girlfriends budget?

2012-03-14 Thread Craig Earls
As far as I know that will not work.

On Wed, Mar 14, 2012 at 17:48, Raphael Lorenzeto 
raphael.lorenz...@gmail.com wrote:

 I don't mind :p, this works perfectly, however it is not what I was
 looking for.

 Can I use the budgeting feature as described in @chapter Budgeting and
 Forecasting, line 5320 of ledger3.texi with tags?

 Is it possible do define ---

 ~ Monthly
:girlfriend:   $100,00

 --- and have it work with ledger --budget?



 On Wednesday, March 14, 2012 9:15:37 PM UTC-3, enderw88 wrote:

 :) I shouldn't have been so flip.  I am not certain exactly what you want
 to do.  If you just want to know how much you have spent on the girlfriend
 you can do balance and register reports limited to the girlfriend tag:

 ledger bal --limit has_tag('Girlfriend')

 and similar for register.

 On Wed, Mar 14, 2012 at 16:38, Raphael Lorenzeto wrote:

 In fact we do have plans, but we are also well aware of how we spend our
 money. She is a Gnucash user and she has a budget for me as well but this
 is not the point. :-)

 My question still stands.


 On Wednesday, March 14, 2012 8:30:05 PM UTC-3, enderw88 wrote:

 If you have any idea of her becoming more than a girlfriend in the
 future, then stop this effort right now.




 --
 Craig, Corona De Tucson, AZ
 enderw88.wordpress.com




 --
 Craig, Corona De Tucson, AZ
 enderw88.wordpress.com




-- 
Craig, Corona De Tucson, AZ
enderw88.wordpress.com


Re: Automatic Transactions Question

2012-03-14 Thread John Wiegley
 Will Goodwin shadowcoder83-re5jqeeqqe8avxtiumw...@public.gmane.org 
 writes:

 However, I'm wondering if there's a way to create an automatic transaction
 that will recognize the (DC) (all the examples I've seen trigger the
 transactions based on account, not codes) and automatically do the right
 calculation.

Use:

= expr code == DC
...

John


Re: Calculating Asset Allocation

2012-03-14 Thread Craig Earls
This is very strange.  It works for me under the latest build exactly as
presented in the manual.

On Wed, Mar 14, 2012 at 17:21, Craig Earls ender...@gmail.com wrote:

 I have been building the latest ledger but I am still using a custom build
 witha few tweeks of my own.  I need to switch so I can see if anything I
 need has broken. (I have modified mine to tag automatic transactions as
 cleared if the base transaction is cleared and I have a special tag that
 returns only the filename, and not the entire path.

 I will check this out.


 On Wed, Mar 14, 2012 at 17:16, Jim Robinson jim.robin...@gmail.comwrote:

 This is awesome, thanks for writing it up.  I tried it out and found
 that ledger  3.0.0-20120217 complaints about not understanding
 the format string:

 While calculating format expression:
   percent(market(display_total), market((parent.total)))
 While evaluating value expression:
   percent(market(display_total), market((parent.total)))
 ^^
 While calling function 'market #EXPR (parent.total)':
 While calling function 'percent (#EXPR market(display_total), #EXPR
 market((parent.total)))':
 Error: Left operand does not evaluate to an object

 While I did find that this appeared to work:

   ledger balance -X '$' Allocation --current -%


 Jim




 --
 Craig, Corona De Tucson, AZ
 enderw88.wordpress.com




-- 
Craig, Corona De Tucson, AZ
enderw88.wordpress.com


Re: A word on Ledger structure

2012-03-14 Thread John Wiegley
 Alexandre Rademaker arademaker-re5jqeeqqe8avxtiumw...@public.gmane.org 
 writes:

 Many thanks for this email. Does cl-ledger (lisp version) has similar
 architecture? What are the differences? I don't know how many of the
 ledger's users are programmers but making Ledger's architecture more
 transparent will, for sure, help people understand and contribute to ledger.

CL-Ledger is based on the same essential design.  On that platform, report
filters are SERIES functions, so that all evaluation is performed lazily.
Otherwise, everything else is quite similar.

John


Re: Girlfriends budget?

2012-03-14 Thread John Wiegley
 Raphael Lorenzeto 
 raphael.lorenzeto-re5jqeeqqe8avxtiumw...@public.gmane.org writes:

 Actually, let me rephrase that: Is there any way to do tag-based budget?

Yes, but not with a simple tag like :girlfriend:.  You'd have to do this:

  ; Girlfriend: Expenses:Movies

Then use --account='tag(Girlfriend)', and your budget will be against
Expenses:Movies, via the metadata tag.

You could also limit the report to only postings with that tag using -l
'has_tag(Girlfriend)'.

John


Re: Calculating Asset Allocation

2012-03-14 Thread John Wiegley
 Jim Robinson jim.robinson-re5jqeeqqe8avxtiumw...@public.gmane.org 
 writes:

 This is awesome, thanks for writing it up.  I tried it out and found that
 ledger 3.0.0-20120217 complaints about not understanding the format string:

 While calculating format expression:
   percent(market(display_total), market((parent.total)))
 While evaluating value expression:
   percent(market(display_total), market((parent.total)))
 ^^
 While calling function 'market #EXPR (parent.total)': While calling
 function 'percent (#EXPR market(display_total), #EXPR market
 ((parent.total)))': Error: Left operand does not evaluate to an object

 While I did find that this appeared to work:

   ledger balance -X '$' Allocation --current -%

--percent only works with balance reports.  The error reporting should be
clearer about this.  Do you have a balance report where it's failing?

John


Re: Metadata on commodity level

2012-03-14 Thread John Wiegley
 Raphael Lorenzeto 
 raphael.lorenzeto-re5jqeeqqe8avxtiumw...@public.gmane.org writes:

 Wow! That really helped!  I would use the = expr ( commodity == 'SYMBOL' )
 to propagate the commodity tags to all related postings.

 It would be nice tough if this could be achieved using the simple tag
 directive.

Since tags don't have metadata -- only postings and transactions do -- the tag
directive is unable to achieve such support.

You can, however, use --group-by=commodity.

John


Re: Understanding transactions

2012-03-14 Thread John Wiegley
 thierry  thierry.daucourt-ganu6spq...@public.gmane.org writes:

 Is that really important? I have 10% of my transactions with top posting
 as source, and final posting as target. And IMHO, I do prefer that source
 is first, and target is last. Can I safely ignore this ledger convention?  I
 realize also that I am never using -V, but only -X, and this may be the
 explanation.

It's not important, it only affects the behavior of -V.  -V tries to be a
shorthand for show me values in terms of the commodities I used to purchase
things with.  This was the best heuristic I could come up with.

John


Re: Having Ledger calculate a commodity / exchange rates by telling it an entry balances

2012-03-14 Thread John Wiegley
 Kamal Marhubi kamal-7mlawaoftq1bdgjk7y7...@public.gmane.org writes:

 Hi, Is it possible to tell Ledger an entry with transactions in two
 commodities / currencies balances, so that it can calculate the exchange
 rate?

 2012-03-12 * Withdrawal
 Assets:Cash   USD 200.00 
 Expenses:Banking:Fees   USD 2.50
 Assets:Chequing  CAD -203.42
 Epenses:Banking:FeesCAD 2.00
 Assets:ChqeuingCAD -2.00

As far as I can tell, this already does exactly what you want.  It does reveal
a bug, though as a bogus price entry gets created:

~/src/ledger $ ./ledger -f /tmp/foo.dat pricedb
P 2012/03/12 00:00:00 CAD CAD 1.00454320987654321
P 2012/03/12 00:00:00 USD CAD 1.00454320987654321

John