Łukasz Stelmach
<[email protected]> writes:

> Xavier Shay <[email protected]> writes:
>
>> I am trying to use an automated transaction to estimate my tax
>> liability. Depending on how much I earn, I pay a different percentage.
>> For reference, here are the current brackets:
>
> The same method is in use in Poland so let me ask some more questions.
>
>> 1) How to do this properly?
>> 2) Is there any documentation on account("") methods, and if not,
>> where in the source code are they defined?
>
> 3) How to make an automated transaction valid/evaluated only for
> transactions from within a specified period (the brackets change on
> yearly basis, more or less)
>
> 4) Is it possible to select and add up several accounts with the
> account("") function so that: account("Income:Salary") returns the sum
> of Income:Salary:BigCorp and Income:Salary:SmalCo totals?

After some investigation I consider the automated transaction as rather
wrong way to calculate progressive tax amounts. because there will be
noticeable errors on the boundaries of ranges. For example (let's assume
the account("Income").total is checked after the transaction, if it's
not then the next transaction will cause the error):

In August you earn $1000

2010/8/1 Test 
   Income  -$1000 
   Assets  $1000 

and in September $6000

2010/9/1 Test 
   Income  -$6000
   Assets  $6000

ledger calculates the tax amount to be $900 instead of $100 becase it
checks (as we assumed) the value of Income.total after it is updated
(it's $7000 then) and calculates 15% of the *transaction* (instead of
account("Income").total - $6000, ... hold on maybe there is a way)

--8<---------------cut here---------------start------------->8---
$ ~/src/ledger/ledger  -f /tmp/ledger-tax.dat bal
               $7000  Assets
                $900  Expenses:Tax
              $-7000  Income
               $-900  Liabilities:Tax
--------------------
                   0
--8<---------------cut here---------------end--------------->8---


--8<---------------cut here---------------start------------->8---
= /Income/ 
 Expenses:Tax      (account("Income").total < -6000 ? -0.15 * 
(account("Income").total - 6000) : 0) 
 Liabilities:Tax   (account("Income").total < -6000 ? 0.15 * 
(account("Income").total - 6000) : 0) 
--8<---------------cut here---------------end--------------->8---

It seems this might yield accurate results but there is an obvious
problem with units and ledger says:

--8<---------------cut here---------------start------------->8---
While parsing file "/tmp/ledger-tax.dat", line 14: 
While evaluating value expression:
  (account("Income").total < -6000) ? (-0.15 * (account("Income").total - 
6000)) : 0
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
While multiplying -0.15 with -6000:
While applying automated transaction from "/tmp/ledger-tax.dat", lines 2-4:
> = /Income/ 
>  Expenses:Tax      (account("Income").total < -6000 ? -0.15 * 
> (account("Income").total - 6000) : 0) 
>  Liabilities:Tax   (account("Income").total < -6000 ? 0.15 * 
> (account("Income").total - 6000) : 0) 
While extending transaction from "/tmp/ledger-tax.dat", lines 12-14:
> 2010/8/1 Test 
>    Income    $-6000
>    Assets     $6000
Error: Cannot multiply an amount with a balance
--8<---------------cut here---------------end--------------->8---


-- 
Miłego dnia,
Łukasz Stelmach

Reply via email to