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