Re: Really clearing out an account

2013-01-09 Thread Jim Robinson
On Wednesday, January 2, 2013 11:27:28 AM UTC-8, Craig Earls wrote:

 My company has changed 401K service providers and I have a problem I can't 
 figure out. For a number of reasons that seemed reasonable up to now I have 
 enter many transaction by having ledger calculate the number of shares of 
 a commodities  like this:

 2012/03/27 * (DD) Earnings
 Assets:Investments:401K:Deferred(198.82/106.30 VIFSX) @ $106.30
 Assets:Investments:401K:Matching(99.40/106.30 VIFSX) @ $106.30
 Assets:Investments:401K:Profit Sharing  (6.38/106.30 VIFSX) @ $106.30
 Income:Exempt:Dividends

 This was fine up until now.  I want to sell all shares out of an account, 
 but since I have used division there are MANY digits of precision that I 
 don't really want to deal with.  

... 

 Any ideas here?


 If I were faced with the problem I'd probably handle it by trying to 
massage the data into the new shape I wanted.  Given how ledger can hook 
into python, if you know that language it might be easy to fix it up.  For 
example, if I were doing it I'd probably reach for awk, starting with 
something like this:

$ cat sample.awk 
{
if ($1 !~ /401K/ || $(NF-3) !~ /\//) {
print $0;
next;
}

stock=$(NF-2);
sub(/\)/, , stock);

ratio=$(NF-3);
sub(/\(/, , ratio);

split(ratio, arr, /);
units=arr[1];

printf();
for (i = 1; i = NF; i++) {
if (i == (NF-3)) {
printf(%s, units);
} else if (i == (NF-2)) {
printf( %s, stock);
} else if (i == (NF-1)) {
printf( @@);
} else {
if (i  1) {
printf( );
}
printf(%s, $i);
}
if (i == NF) {
printf(\n);
}
}
}
$ cat sample.dat 
2012/03/27 * (DD) Earnings
Assets:Investments:401K:Deferred(198.82/106.30 VIFSX) @ $106.30
Assets:Investments:401K:Matching(99.40/106.30 VIFSX) @ $106.30
Assets:Investments:401K:Profit Sharing  (6.38/106.30 VIFSX) @ $106.30
Income:Exempt:Dividends
$ awk -f sample.awk sample.dat 
2012/03/27 * (DD) Earnings
Assets:Investments:401K:Deferred198.82 VIFSX @@ $106.30
Assets:Investments:401K:Matching99.40 VIFSX @@ $106.30
Assets:Investments:401K:Profit Sharing6.38 VIFSX @@ $106.30
Income:Exempt:Dividends




Re: Really clearing out an account

2013-01-09 Thread Jim Robinson
I tried a first response to this but realized I had screwed up what it was 
you were actually showing in your data.  Am I correct in understanding that 
you're recording the total price / unit price to calculate the stock units? 
 I've always just entered the total number of units as expressed by the 
fund and the total price paid.

So what I would probably do if I were faced with this problem is use a 
program to massage the entries into the format I wanted.  If you can do 
this via the python interface that might be the most robust.  Here's what I 
came up with in awk do massage the sample data:

 $ cat sample.awk 
{
if ($1 !~ /401K/ || $(NF-3) !~ /\//) {
print $0;
next;
}

stock=$(NF-2);
sub(/\)/, , stock);

ratio=$(NF-3);
sub(/\(/, , ratio);

split(ratio, arr, /);
total=arr[1];
unit=arr[2];

printf();
for (i = 1; i = NF; i++) {
if (i == (NF-3)) {
printf(%.2f, (total/unit));
} else if (i == (NF-2)) {
printf( %s, stock);
} else if (i == (NF-1)) {
printf( @@);
} else if (i == NF) {
printf( $%.2f, total)
} else {
if (i  1) {
printf( );
}
printf(%s, $i);
}
if (i == NF) {
printf(\n);
}
}
}
$ cat sample.dat
2012/03/27 * (DD) Earnings
Assets:Investments:401K:Deferred(198.82/106.30 VIFSX) @ $106.30
Assets:Investments:401K:Matching(99.40/106.30 VIFSX) @ $106.30
Assets:Investments:401K:Profit Sharing  (6.38/106.30 VIFSX) @ $106.30
Income:Exempt:Dividends
$ awk -f sample.awk sample.dat
2012/03/27 * (DD) Earnings
Assets:Investments:401K:Deferred1.87 VIFSX @@ $198.82
Assets:Investments:401K:Matching0.94 VIFSX @@ $99.40
Assets:Investments:401K:Profit Sharing0.06 VIFSX @@ $6.38
Income:Exempt:Dividends

ledger reports the same output for both the old and new format:

  2.87 VIFSX  Assets:Investments:401K
  1.87 VIFSXDeferred
  0.94 VIFSXMatching
  0.06 VIFSXProfit Sharing
   $-305  Income:Exempt:Dividends

   $-305
  2.87 VIFSX




Re: Really clearing out an account

2013-01-03 Thread Lifepillar
In article 
CAKs9TOKeoHmc5sjZspPfyTZqC89FJh8vzC29yr=hgmm5z4a...@mail.gmail.com,
 Craig Earls ender...@gmail.com wrote:

 OK, here is something that sort of shows my problem:
 
  CUT HERE test.dat
 
 2011/02/17 * (AUTO) VIFSX
 Assets:Standard:Deferred(701.11/102.27 VIFSX)
 Assets:Standard:Deferred$-701.11
 
 2011/02/17 * (AUTO) VIFSX
 Assets:Standard:Matching(350.56/102.27 VIFSX)
 Income:Exempt:Matching  $-350.56
 
 2011/03/03 * (AUTO) VIFSX
 Assets:Standard:Deferred(701.11/101.60 VIFSX)
 Assets:Standard:Deferred$-701.11
 
 2011/03/06  (MAN) Sell everything
Assets:Standard:Deferred  -13.76 VIFSX @ $107.56
Assets:Standard:Matching  -3.43 VIFSX @ $107.56
Assets:Fidelity
 
  CUT HERE test.dat---
 
 21:21:01 ~/FinanceData (master)  ledger -f test.dat bal --cleared
$-1402.22
  17.18 VIFSX  Assets:Standard
$-1402.22
  13.76 VIFSXDeferred
   3.43 VIFSXMatching
 $-350.56  Income:Exempt:Matching
 
$-1752.78
  17.18 VIFSX
 
 
 21:21:38 ~/FinanceData (master)  ledger -f test.dat bal
  $446.74
  -0.01 VIFSX  Assets
 $1848.96Fidelity
$-1402.22Standard:Deferred
 $-350.56  Income:Exempt:Matching
 
   $96.18
  -0.01 VIFSX
 
 
 Notice the -0.01 VIFSX still left in the ASSETS even though I sold
 everything in the uncleared transaction.

Appending this works for me:

2011/03/06  (MAN) Reconcile
 Assets:Standard:Matching  = 0.00 VIFSX
 Assets:Standard:Deferred  = 0.00 VIFSX
 Equity:Adjustments


Another possibility:

2011/03/06  (MAN) Sell everything
   Assets:Standard:Deferred  (-701.11/102.27 VIFSX - 701.11/101.60 
VIFSX) @ $107.56
   Assets:Standard:Matching  (-350.56 VIFSX / 102.27 VIFSX) @ $107.56
   Assets:Fidelity

2011/03/06 Reconcile
Assets:Fidelity  = $1848.96
Equity:Adjustments

Hope this helps,
Life



Re: Really clearing out an account

2013-01-03 Thread Craig Earls
Now that is interesting, because appending this:

2011/03/06  (MAN) Reconcile
 Assets:Standard:Matching  = 0 VIFSX
 Assets:Standard:Deferred  = 0 VIFSX
 Equity:Adjustments

Doesn't.


Does 0 not equal 0.00?


On Thu, Jan 3, 2013 at 4:52 AM, Lifepillar git...@lifepillar.com wrote:

 In article
 CAKs9TOKeoHmc5sjZspPfyTZqC89FJh8vzC29yr=hgmm5z4a...@mail.gmail.com,
  Craig Earls ender...@gmail.com wrote:

  OK, here is something that sort of shows my problem:
 
   CUT HERE test.dat
 
  2011/02/17 * (AUTO) VIFSX
  Assets:Standard:Deferred(701.11/102.27 VIFSX)
  Assets:Standard:Deferred$-701.11
 
  2011/02/17 * (AUTO) VIFSX
  Assets:Standard:Matching(350.56/102.27 VIFSX)
  Income:Exempt:Matching  $-350.56
 
  2011/03/03 * (AUTO) VIFSX
  Assets:Standard:Deferred(701.11/101.60 VIFSX)
  Assets:Standard:Deferred$-701.11
 
  2011/03/06  (MAN) Sell everything
 Assets:Standard:Deferred  -13.76 VIFSX @ $107.56
 Assets:Standard:Matching  -3.43 VIFSX @ $107.56
 Assets:Fidelity
 
   CUT HERE test.dat---
 
  21:21:01 ~/FinanceData (master)  ledger -f test.dat bal --cleared
 $-1402.22
   17.18 VIFSX  Assets:Standard
 $-1402.22
   13.76 VIFSXDeferred
3.43 VIFSXMatching
  $-350.56  Income:Exempt:Matching
  
 $-1752.78
   17.18 VIFSX
 
 
  21:21:38 ~/FinanceData (master)  ledger -f test.dat bal
   $446.74
   -0.01 VIFSX  Assets
  $1848.96Fidelity
 $-1402.22Standard:Deferred
  $-350.56  Income:Exempt:Matching
  
$96.18
   -0.01 VIFSX
 
 
  Notice the -0.01 VIFSX still left in the ASSETS even though I sold
  everything in the uncleared transaction.

 Appending this works for me:

 2011/03/06  (MAN) Reconcile
  Assets:Standard:Matching  = 0.00 VIFSX
  Assets:Standard:Deferred  = 0.00 VIFSX
  Equity:Adjustments


 Another possibility:

 2011/03/06  (MAN) Sell everything
Assets:Standard:Deferred  (-701.11/102.27 VIFSX - 701.11/101.60
 VIFSX) @ $107.56
Assets:Standard:Matching  (-350.56 VIFSX / 102.27 VIFSX) @ $107.56
Assets:Fidelity

 2011/03/06 Reconcile
 Assets:Fidelity  = $1848.96
 Equity:Adjustments

 Hope this helps,
 Life




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


Re: Really clearing out an account

2013-01-03 Thread John Wiegley
 Craig Earls ender...@gmail.com writes:

 Does 0 not equal 0.00?

Ledger internally uses rational numbers, so who knows what 0.00 *really*
means, in its unrounded form.  0 is always true zero, however.

John


Re: Really clearing out an account

2013-01-03 Thread Lifepillar
In article 
CAKs9TOJ20NUfXU=z+smxf1sfwmlobq8krrndrf257bg4us8...@mail.gmail.com,
 Craig Earls ender...@gmail.com wrote:

 Now that is interesting, because appending this:
 
 2011/03/06  (MAN) Reconcile
  Assets:Standard:Matching  = 0 VIFSX
  Assets:Standard:Deferred  = 0 VIFSX
  Equity:Adjustments
 
 Doesn't.

0 or 0.00 doesn't make a difference for me. Maybe you haven't excluded 
Equity:Adjustments from the balance report?

But John's reply in fact makes me wonder: I have always assumed that 
Ledger's computations are exact (as in ³multiple-precision arithmetic²). 
Is that not the case?

Life



Re: Really clearing out an account

2013-01-03 Thread Craig Earls
There was something else going on possibly to do with where I was placing
the assertions in the data stream.  When I used the 0 (vice 0.00) I got an
error complaining that it couldn't subtract VIFSX from $


On Thu, Jan 3, 2013 at 2:18 PM, Lifepillar git...@lifepillar.com wrote:

 In article
 CAKs9TOJ20NUfXU=z+smxf1sfwmlobq8krrndrf257bg4us8...@mail.gmail.com,
  Craig Earls ender...@gmail.com wrote:

  Now that is interesting, because appending this:
 
  2011/03/06  (MAN) Reconcile
   Assets:Standard:Matching  = 0 VIFSX
   Assets:Standard:Deferred  = 0 VIFSX
   Equity:Adjustments
 
  Doesn't.

 0 or 0.00 doesn't make a difference for me. Maybe you haven't excluded
 Equity:Adjustments from the balance report?

 But John's reply in fact makes me wonder: I have always assumed that
 Ledger's computations are exact (as in ³multiple-precision arithmetic²).
 Is that not the case?

 Life




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


Re: Really clearing out an account

2013-01-03 Thread John Wiegley
 Lifepillar  git...@lifepillar.com writes:

 But John's reply in fact makes me wonder: I have always assumed that
 Ledger's computations are exact (as in ³multiple-precision arithmetic²).  Is
 that not the case?

They are exact because they are rational numbers, i.e., always some p/q.  They
are rendered as floating-point only at display time.  So it is not possible to
lose anything during rounding, as no rounding happens except to display
amounts to the user.

John


Re: Really clearing out an account

2013-01-02 Thread John Wiegley
 Craig Earls ender...@gmail.com writes:

 Those remnants of VIPSX and VIFSX are annoying.  Is there a way to really
 zero out the commodities in that account?

You need to negate the remnants, not the dollar amount.

John


Re: Really clearing out an account

2013-01-02 Thread John Wiegley
 Craig Earls ender...@gmail.com writes:

 Yes, but the remnants are calculated out to many decimals places because of
 the fractions in the postings.  So I can't really enter an exact share
 amount.   When I tried to remove 360.1678175665624872914 VIFSX from the
 account, then a balance report still shows 0.000 VIFSX

 Short of going back and reentering three years worth of transaction to get
 rid of the fractional entries I am not sure what to do here.

Hmmm... can you reproduce this in a smaller case?  I may be able to track down
why it's not falling below your display cutoff.

John


Re: Really clearing out an account

2013-01-02 Thread Craig Earls
I will try to reproduce it without duplicating the entire fil, but it may
be that I haven't set the display cutoff correctly


On Wed, Jan 2, 2013 at 9:15 PM, John Wiegley jo...@newartisans.com wrote:

  Craig Earls ender...@gmail.com writes:

  Yes, but the remnants are calculated out to many decimals places because
 of
  the fractions in the postings.  So I can't really enter an exact share
  amount.   When I tried to remove 360.1678175665624872914 VIFSX from the
  account, then a balance report still shows 0.000 VIFSX

  Short of going back and reentering three years worth of transaction to
 get
  rid of the fractional entries I am not sure what to do here.

 Hmmm... can you reproduce this in a smaller case?  I may be able to track
 down
 why it's not falling below your display cutoff.

 John




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