I thought about this approach.  I used the fractional entry because my 401K
inputs get split across a few different categories, 2/3 to one 1/3 to
another.  Entering the 4 digit figures from the account statements often
results in an unbalanced transaction.  So rather than playing with the last
few digits I just do the exact calculation.  The method provided above
would have to be extensively massaged to ensure transactions balanced.  I
have several years of transactions tracked this way.

It still begs the question of how to tell ledger to use it internally
calculated value for a balance in an xact.  That way you can easily say
"Sell all shares of X at Y"  when you don't have the full precision value
of the number of shares of X.


On Wed, Jan 9, 2013 at 8:07 AM, Jim Robinson <jim.robin...@gmail.com> wrote:

> 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:Deferred    1.87 VIFSX @@ $198.82
>     Assets:Investments:401K:Matching    0.94 VIFSX @@ $99.40
>     Assets:Investments:401K:Profit Sharing    0.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 VIFSX    Deferred
>           0.94 VIFSX    Matching
>           0.06 VIFSX    Profit Sharing
>                $-305  Income:Exempt:Dividends
> --------------------
>                $-305
>           2.87 VIFSX
>
>
>


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

Reply via email to