summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-06-22 02:05:42 -0400
committerjohnw <johnw@newartisans.com>2004-06-22 02:05:42 -0400
commitd022744c18729b6e70dc5fe11d18317b964d0a4f (patch)
tree89eb67968f2e4954b1dcd05ed2f5b125c1f5a185
parent1a1c8cdd2b4a3641102bb7147da7a4c507331dd0 (diff)
downloadfork-ledger-d022744c18729b6e70dc5fe11d18317b964d0a4f.tar.gz
fork-ledger-d022744c18729b6e70dc5fe11d18317b964d0a4f.tar.bz2
fork-ledger-d022744c18729b6e70dc5fe11d18317b964d0a4f.zip
asset gain report added (-A)
-rw-r--r--README26
-rw-r--r--reports.cc41
2 files changed, 55 insertions, 12 deletions
diff --git a/README b/README
index 51a38f1c..c230141d 100644
--- a/README
+++ b/README
@@ -403,7 +403,12 @@ To enable pricing reports, three options are possible:
at time of purchase. Thus, totals in the register and balance
report reflect the total amount spent.
-**-Q FILE** ::
+**-A** ::
+ Report commodities in terms of their net gain, which is: the market
+ value minus the cost basis. A balance report using this option
+ shows very quickly the performance of investments.
+
+**-Q** ::
When needed (see the =-L= option) pricing quotes are obtained by
calling the script =getquote= (a sample Perl script is provided, but
the interface is kept simple so replacements may be made).
@@ -413,8 +418,16 @@ To enable pricing reports, three options are possible:
pricing data is older than MINS minutes. The default is one day,
or 1440 minutes.
-Note that the =-B=, =-T=, =-V=, and =-P= and =-Q= flags are all
-mutually exclusive. Whichever option appears last is used.
+**-p ARG** ::
+ If a string, such as "COMM=$1.20", the commodity COMM will be
+ reported only in terms of the conversion factor, which supersedes
+ all other pricing histories for that commodity. This can be used to
+ perform arbitrary value substitutions. For example, to report the
+ value of your dollars in terms of the ounces of gold they would buy,
+ use: -p "$=0.00280112 AU" (or whatever the current exchange rate
+ is).
+
+Note that the =-B=, =-T=, =-V=, and =-A= are mutually exclusive.
** Accounts and Inventories
@@ -1169,7 +1182,12 @@ launches =vi= to let you confirm that the entry looks appropriate.
at time of purchase. Thus, totals in the register and balance
report reflect the total amount spent.
-**-Q FILE** ::
+**-A** ::
+ Report commodities in terms of their net gain, which is: the market
+ value minus the cost basis. A balance report using this option
+ shows very quickly the performance of investments.
+
+**-Q** ::
When needed (see the =-L= option) pricing quotes are obtained by
calling the script =getquote= (a sample Perl script is provided, but
the interface is kept simple so replacements may be made).
diff --git a/reports.cc b/reports.cc
index 7900afc5..c8738b84 100644
--- a/reports.cc
+++ b/reports.cc
@@ -18,9 +18,10 @@ static bool full_names = false;
static bool print_monthly = false;
static bool gnuplot_safe = false;
-static bool cost_basis = false;
-static bool use_history = false;
-static bool get_quotes = false;
+static bool cost_basis = false;
+static bool use_history = false;
+static bool net_gain = false;
+static bool get_quotes = false;
long pricing_leeway = 24 * 3600;
std::string price_db;
@@ -88,6 +89,23 @@ static amount * resolve_amount(amount * amt,
else if (cost_basis) {
value = amt->value();
}
+ else if (net_gain) {
+ value = amt->street(when ? when : (have_ending ? &end_date : NULL),
+ use_history, get_quotes);
+ amount * basis = amt->value();
+ if (value->commdty() == basis->commdty()) {
+ basis->negate();
+ value->credit(basis);
+ } else {
+ // If the commodities do not match, ignore this amount by
+ // returning a zeroed value.
+ delete basis;
+ basis = value->copy();
+ basis->negate();
+ value->credit(basis);
+ delete basis;
+ }
+ }
else {
value = amt->street(when ? when : (have_ending ? &end_date : NULL),
use_history, get_quotes);
@@ -992,7 +1010,7 @@ int main(int argc, char * argv[])
int c;
while (-1 != (c = getopt(argc, argv,
- "+Bb:Ccd:Ee:Ff:Ghi:L:l:MN:nP:p:QRSsTUVv"))) {
+ "+ABb:Ccd:Ee:Ff:Ghi:L:l:MN:nP:p:QRSsTUVv"))) {
switch (char(c)) {
case 'b':
have_beginning = true;
@@ -1059,13 +1077,20 @@ int main(int argc, char * argv[])
get_quotes = true;
break;
- case 'B':
- cost_basis = true;
- // fall through...
case 'V':
use_history = true;
break;
+ case 'B':
+ cost_basis = true;
+ use_history = true;
+ break;
+
+ case 'A':
+ net_gain = true;
+ use_history = true;
+ break;
+
case 'T':
cost_basis = false;
use_history = false;
@@ -1147,7 +1172,7 @@ int main(int argc, char * argv[])
}
}
- if (use_history && ! price_db.empty())
+ if (use_history && ! cost_basis && ! price_db.empty())
entry_count += parse_ledger_file(main_ledger, price_db, regexps,
command == "equity");