--On February 19, 2006 1:56:38 PM -0800 Andrew Sackville-West
<[EMAIL PROTECTED]> wrote:
It should IMO also use transactions for current value and make a
decision as to which is more accurate, or closer in date to the report
date. but only use buy or sell transactions as those are the only ones
that provide a "price".
These two things are, I believe, the correct behaviour. The
question comes back to automatically creating a pricedb entry for a
buy and sell, which looks to be a reasonable thing to do. The
caveat is that not all stock transactions should create a pricedb
entry.
Two options:
1. Perhaps, one could have a dialog asking the user (with a check
box for "don't ask again" and an Edit->Preferences check box for
this). 2. Those transactions that are "buy" or "sell" could
automatically create a pricedb entry. Those that are a conversion
from another stock or a transfer between stock accounts should not.
Additional thought would have to be given to transactions such as
stock splits or consolidations that change the number of shares
(and therefore the price), but not the cost basis.
yes yes and yes but, one thing at a time ;). my poor little brain can
only take so much!!
when I get back to working on this (couple days probably), I'll see if
I can generalize the value of the stock so that it can use both
properly. I'll ignore the currency conversion for now as that seems to
be another monster altogether. Once I get reliable results for value,
then I can look into that.
I finally managed to get around to looking at this again tonight. The
r13293 version of advanced-portfolio.scm contained most of the changes
I had made earlier. I've attached a patch that fixes one problem by
converting the gain to the report currency properly. The patch also
adds more debugging output (commented out) since I was having trouble
figuring out why the report wasn't working right (turned out to be a
bad transaction with no currency in my test file).
Note that this doesn't address the problems that are the subject of
this thread. I have been assuming that the pricedb is the definitive
source of price information. I can see why this may not always be a
good assumption, but I started out with this assumption since I came
from the Quicken world and that's the way it works. I have a cron job
that updates price information every day so my pricedb is generally
fairly accurate.
One thing I would add to the discussion is to point out that the
pricedb is used for two things in this report (and elsewhere). It
contains prices in some currency for the commodities (stocks, bonds,
etc.) that are being reported on and it also contains exchange rates
used for converting amounts from one currency to another. The report
can infer the first of these from the transactions, but not the latter.
It really needs the pricedb for that.
--
Mike Alexander [EMAIL PROTECTED]
Ann Arbor, MI PGP key ID: BEA343A6
Index: gnucash-1.9/src/report/standard-reports/advanced-portfolio.scm
===================================================================
--- gnucash-1.9/src/report/standard-reports/advanced-portfolio.scm
(revision 13293)
+++ gnucash-1.9/src/report/standard-reports/advanced-portfolio.scm
(working copy)
@@ -178,7 +178,10 @@
(gnc:share-print-info-places
(inexact->exact (get-option gnc:pagename-display
optname-shares-digits)))))
-
+
+ ;; (define (commod-value->string commod amount)
+ ;; (gnc:commodity-value->string (list commod amount)))
+
(define (table-add-stock-rows-internal accounts odd-row?)
(if (null? accounts) total-value
(let* ((row-style (if odd-row? "normal-row" "alternate-row"))
@@ -221,10 +224,10 @@
(lambda (s)
(cond
((same-split? s split)
-;; (gnc:debug "amount " (gnc:numeric-to-double
(gnc:split-get-amount s))
-;; " acct " (gnc:account-get-name
(gnc:split-get-account s)) )
-;; (gnc:debug "value " (gnc:numeric-to-double
(gnc:split-get-value s))
-;; " in " (gnc:commodity-get-printname
commod-currency)
+;; (gnc:debug "amount " (gnc:commodity-value->string
+;; (list commodity
(gnc:split-get-amount s)))
+;; " value " (gnc:commodity-value->string
+;; (list commod-currency
(gnc:split-get-value s)))
;; " from " (gnc:transaction-get-description
(gnc:split-get-parent s)))
(cond
((or include-gains (not (gnc:numeric-zero-p
(gnc:split-get-amount s))))
@@ -244,15 +247,23 @@
((gnc:numeric-negative-p (gnc:split-get-value s))
(moneyoutcoll
'add commod-currency
- (gnc:numeric-neg (gnc:split-get-value s))))
+ (gnc:numeric-neg (gnc:split-get-value s)))
+;; (gnc:debug " moneyoutcoll "
+;; (moneyoutcoll 'format
commod-value->string #f))
+ )
(else (moneyincoll
'add commod-currency
- (gnc:numeric-neg (gnc:split-get-value
s))))))))
+ (gnc:numeric-neg (gnc:split-get-value s)))
+;; (gnc:debug " moneyincoll "
+;; (moneyincoll 'format
commod-value->string #f))
+ )))))
((split-account-type? s 'expense)
+;; (gnc:debug "expense " (gnc:numeric-to-double
(gnc:split-get-value s)))
(brokeragecoll 'add commod-currency
(gnc:split-get-value s)))
((split-account-type? s 'income)
+;; (gnc:debug "income " (gnc:numeric-to-double
(gnc:split-get-value s)))
(dividendcoll 'add commod-currency
(gnc:split-get-value s)))
)
)
@@ -263,14 +274,20 @@
)
(gnc:account-get-split-list current)
)
-;; (gnc:debug "totalunits" totalunits)
-;; (gnc:debug "totalunityears" totalunityears)
+;; (gnc:debug "totalunits " totalunits)
+;; (gnc:debug "totalunityears " totalunityears)
+;; (gnc:debug "moneyincoll1 " (moneyincoll 'format
commod-value->string #f))
+;; (gnc:debug "moneyoutcoll1 " (moneyoutcoll 'format
commod-value->string #f))
(moneyincoll 'minusmerge dividendcoll #f)
(moneyoutcoll 'minusmerge brokeragecoll #f)
(gaincoll 'merge moneyoutcoll #f)
(gaincoll 'add (gnc:gnc-monetary-commodity value)
(gnc:gnc-monetary-amount value))
(gaincoll 'merge moneyincoll #f)
+
+;; (gnc:debug "moneyincoll2 " (moneyincoll 'format
commod-value->string #f))
+;; (gnc:debug "moneyoutcoll2 " (moneyoutcoll 'format
commod-value->string #f))
+;; (gnc:debug "gaincoll2 " (gaincoll 'format commod-value->string #f))
(if (or include-empty (not (gnc:numeric-zero-p units)))
(let ((moneyin (gnc:monetary-neg
@@ -280,6 +297,10 @@
(activecols (list (gnc:html-account-anchor current)))
)
+;; (gnc:debug "moneyin " (gnc:numeric-to-double
(gnc:gnc-monetary-amount moneyin)))
+;; (gnc:debug "moneyout " (gnc:numeric-to-double
(gnc:gnc-monetary-amount moneyout)))
+;; (gnc:debug "gain " (gnc:numeric-to-double
(gnc:gnc-monetary-amount gain)))
+
(total-value 'add (gnc:gnc-monetary-commodity value)
(gnc:gnc-monetary-amount value))
(total-moneyin 'merge moneyincoll #f)
(total-moneyout 'merge moneyoutcoll #f)
@@ -300,19 +321,16 @@
(gnc:price-get-value price)))
#f)))))
(append! activecols (list (gnc:make-html-table-header-cell/markup
"number-cell" value)
+ (gnc:make-html-table-header-cell/markup
"number-cell" moneyin)
+ (gnc:make-html-table-header-cell/markup
"number-cell" moneyout)
+ (gnc:make-html-table-header-cell/markup
"number-cell" gain)
(gnc:make-html-table-header-cell/markup
"number-cell"
- (gnc:monetary-neg
(gnc:sum-collector-commodity moneyincoll currency exchange-fn)))
- (gnc:make-html-table-header-cell/markup
"number-cell"
- (gnc:sum-collector-commodity
moneyoutcoll currency exchange-fn))
- (gnc:make-html-table-header-cell/markup
"number-cell"
- (gnc:sum-collector-commodity
gaincoll currency exchange-fn))
- (gnc:make-html-table-header-cell/markup
"number-cell"
(let ((moneyinvalue
(gnc:numeric-to-double
- (cadr
(moneyincoll 'getpair currency #t)))))
+
(gnc:gnc-monetary-amount moneyin))))
(if (= 0.0 moneyinvalue)
(_ "N/A")
(sprintf #f "%.2f%%" (* 100
(/ (gnc:numeric-to-double
-
(cadr (gaincoll 'getpair currency #f)))
+
(gnc:gnc-monetary-amount gain))
moneyinvalue))))))
)
)
@@ -445,13 +463,16 @@
"total-number-cell"
(gnc:sum-collector-commodity total-gain currency exchange-fn))
(gnc:make-html-table-cell/markup
"total-number-cell"
- (let ((totalinvalue (gnc:numeric-to-double
- (cadr (total-moneyin
'getpair currency #t)))))
+ (let ((totalinvalue (gnc:numeric-to-double
+ (gnc:gnc-monetary-amount
+
(gnc:sum-collector-commodity total-moneyin currency exchange-fn)))))
(if (= 0.0 totalinvalue)
(_ "N/A")
- (sprintf #f "%.2f%%" (* 100 (/
(gnc:numeric-to-double
- (cadr
(total-gain 'getpair currency #f)))
-
totalinvalue))))))
+ (sprintf #f "%.2f%%" (* 100 (/
(gnc:numeric-to-double
+
(gnc:gnc-monetary-amount
+
(gnc:monetary-neg
+
(gnc:sum-collector-commodity total-gain currency exchange-fn))))
+
totalinvalue))))))
))
_______________________________________________
gnucash-devel mailing list
gnucash-devel@gnucash.org
https://lists.gnucash.org/mailman/listinfo/gnucash-devel