2001-05-09 Christian Stimming <stimming@tuhh.de>

* src/scm/report/price-scatter.scm: Added new option: get weighted
	average prices from the past, not only the instant prices.

	* src/scm/commodity-utilities.scm
	(gnc:get-commodity-totalaverage-prices): Added
	function. Eventually this could be an extension/alternative to
	prices from the pricedb.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4138 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Christian Stimming 2001-05-09 08:52:12 +00:00
parent 5848a94c30
commit 87edd32c82
3 changed files with 190 additions and 80 deletions

View File

@ -1,3 +1,13 @@
2001-05-09 Christian Stimming <stimming@tuhh.de>
* src/scm/report/price-scatter.scm: Added new option: get weighted
average prices from the past, not only the instant prices.
* src/scm/commodity-utilities.scm
(gnc:get-commodity-totalaverage-prices): Added
function. Eventually this could be an extension/alternative to
prices from the pricedb.
2001-05-09 Robert Graham Merkel <rgmerk@mira.net> 2001-05-09 Robert Graham Merkel <rgmerk@mira.net>
* src/scm/report/net-barchart.scm: check for empty data * src/scm/report/net-barchart.scm: check for empty data

View File

@ -83,6 +83,82 @@
(gnc:get-match-commodity-splits currency-accounts end-date-tp #f)) (gnc:get-match-commodity-splits currency-accounts end-date-tp #f))
;; Create a list of all prices of 'price-commodity' measured in the
;; currency 'report-currency'. The prices are taken from all splits in
;; 'currency-accounts' up until the date 'end-date-tp'. Returns a list
;; of lists. Each element-list looks like (time price), where 'time'
;; is the timepair when the 'price' was valid.
(define (gnc:get-commodity-totalaverage-prices
currency-accounts end-date-tp price-commodity report-currency)
(let ((total-foreign (gnc:numeric-zero))
(total-domestic (gnc:numeric-zero)))
(map-in-order
(lambda (a)
(let* ((transaction-comm (gnc:transaction-get-commodity
(gnc:split-get-parent a)))
(account-comm (gnc:account-get-commodity
(gnc:split-get-account a)))
(share-amount (gnc:numeric-abs
(gnc:split-get-share-amount a)))
(value-amount (gnc:numeric-abs
(gnc:split-get-value a)))
(transaction-date (gnc:transaction-get-date-posted
(gnc:split-get-parent a)))
(foreignlist
(if (gnc:commodity-equiv? transaction-comm
price-commodity)
(list account-comm
share-amount value-amount)
(list transaction-comm
value-amount share-amount))))
; (warn "render-scatterplot: value "
; (commodity-numeric->string
; (first foreignlist) (second foreignlist))
; " bought shares "
; (commodity-numeric->string
; price-commodity (third foreignlist)))
(list
transaction-date
(if (not (gnc:commodity-equiv? (first foreignlist)
report-currency))
(begin
(warn "totalaverage-prices: "
"Sorry, currency exchange not yet implemented:"
(commodity-numeric->string
(first foreignlist) (second foreignlist))
" (buying "
(commodity-numeric->string
price-commodity (third foreignlist))
") =? "
(commodity-numeric->string
report-currency (gnc:numeric-zero)))
(gnc:numeric-zero))
(begin
(set! total-foreign (gnc:numeric-add-fixed
total-foreign (third foreignlist)))
(set! total-domestic (gnc:numeric-add-fixed
total-domestic (second foreignlist)))
(gnc:numeric-div
total-domestic
total-foreign
GNC-DENOM-AUTO
(logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND)))))))
;; Get all the interesting splits, and sort them according to the
;; date.
(sort
(gnc:get-match-commodity-splits
currency-accounts
end-date-tp price-commodity)
(lambda (a b)
(gnc:timepair-lt
(gnc:transaction-get-date-posted
(gnc:split-get-parent a))
(gnc:transaction-get-date-posted
(gnc:split-get-parent b)))))
)))
;; Go through all toplevel non-report-commodity balances in sumlist ;; Go through all toplevel non-report-commodity balances in sumlist
;; and add them to report-commodity, if possible. This function takes ;; and add them to report-commodity, if possible. This function takes
;; a sumlist (described below) and returns an alist similar to one ;; a sumlist (described below) and returns an alist similar to one

View File

@ -31,6 +31,7 @@
(optname-report-currency (N_ "Report's currency")) (optname-report-currency (N_ "Report's currency"))
(optname-price-commodity (N_ "Price of Commodity")) (optname-price-commodity (N_ "Price of Commodity"))
(optname-price-source (N_ "Price Source"))
;; (optname-accounts (N_ "Accounts")) ;; (optname-accounts (N_ "Accounts"))
@ -59,17 +60,17 @@
(gnc:options-add-interval-choice! (gnc:options-add-interval-choice!
options gnc:pagename-general optname-stepsize "b" 'MonthDelta) options gnc:pagename-general optname-stepsize "b" 'MonthDelta)
; (add-option ; (add-option
; (gnc:make-account-list-option ; (gnc:make-account-list-option
; gnc:pagename-accounts optname-accounts ; gnc:pagename-accounts optname-accounts
; "c" ; "c"
; (N_ "Report on these accounts, if chosen account level allows.") ; (N_ "Report on these accounts, if chosen account level allows.")
; (lambda () ; (lambda ()
; (gnc:group-get-subaccounts (gnc:get-current-group))) ; (gnc:group-get-subaccounts (gnc:get-current-group)))
; (lambda (accounts) ; (lambda (accounts)
; (list #t ; (list #t
; accounts)) ; accounts))
; #t)) ; #t))
(gnc:options-add-currency! (gnc:options-add-currency!
options gnc:pagename-general optname-report-currency "d") options gnc:pagename-general optname-report-currency "d")
@ -81,11 +82,27 @@
(N_ "Calculate the price of this commodity.") (N_ "Calculate the price of this commodity.")
(gnc:locale-default-currency))) (gnc:locale-default-currency)))
(add-option
(gnc:make-multichoice-option
gnc:pagename-general optname-price-source
"f" (N_ "The source of price information")
'actual-transactions
(list (vector 'weighted-average
(N_ "Weighted Average")
(N_ "The weighted average all currency transactions of the past"))
(vector 'actual-transactions
(N_ "Actual Transactions")
(N_ "The actual price of currency transactions in the past"))
;;(vector 'pricedb-nearest
;; (N_ "Pricedb: Nearest in time")
;; (N_ "The price recorded nearest in time to the report date"))
)))
(gnc:options-add-plot-size! (gnc:options-add-plot-size!
options gnc:pagename-display options gnc:pagename-display
optname-plot-width optname-plot-height "c" 500 400) optname-plot-width optname-plot-height "c" 500 400)
(gnc:options-add-marker-choice! (gnc:options-add-marker-choice!
options gnc:pagename-display options gnc:pagename-display
optname-marker "a" 'filledsquare) optname-marker "a" 'filledsquare)
@ -126,7 +143,7 @@
(op-value gnc:pagename-general (op-value gnc:pagename-general
optname-from-date)))) optname-from-date))))
(interval (op-value gnc:pagename-general optname-stepsize)) (interval (op-value gnc:pagename-general optname-stepsize))
; (accounts (op-value gnc:pagename-accounts optname-accounts)) ;; (accounts (op-value gnc:pagename-accounts optname-accounts))
(height (op-value gnc:pagename-display optname-plot-height)) (height (op-value gnc:pagename-display optname-plot-height))
(width (op-value gnc:pagename-display optname-plot-width)) (width (op-value gnc:pagename-display optname-plot-width))
@ -140,6 +157,8 @@
optname-report-currency)) optname-report-currency))
(price-commodity (op-value gnc:pagename-general (price-commodity (op-value gnc:pagename-general
optname-price-commodity)) optname-price-commodity))
(price-source (op-value gnc:pagename-general
optname-price-source))
(dates-list (gnc:make-date-list (dates-list (gnc:make-date-list
(gnc:timepair-end-day-time from-date-tp) (gnc:timepair-end-day-time from-date-tp)
@ -151,6 +170,7 @@
(currency-accounts (currency-accounts
(filter gnc:account-has-shares? (gnc:group-get-subaccounts (filter gnc:account-has-shares? (gnc:group-get-subaccounts
(gnc:get-current-group)))) (gnc:get-current-group))))
;; some bogus data
(data '((1.0 1.0) (1.1 1.2) (1.2 1.4) (1.3 1.6) (data '((1.0 1.0) (1.1 1.2) (1.2 1.4) (1.3 1.6)
(2.0 1.0) (2.1 1.2) (2.2 1.4) (2.3 1.6)))) (2.0 1.0) (2.1 1.2) (2.2 1.4) (2.3 1.6))))
@ -193,70 +213,78 @@
;; go into commodity-utilities.scm or even start a new file. ;; go into commodity-utilities.scm or even start a new file.
(set! (set!
data data
;; go through all splits; convert all splits into a (case price-source
;; price. ('actual-transactions
(map ;; go through all splits; convert all splits into a
(lambda (a) ;; price.
(let* ((transaction-comm (gnc:transaction-get-commodity (map
(gnc:split-get-parent a))) (lambda (a)
(account-comm (gnc:account-get-commodity (let* ((transaction-comm (gnc:transaction-get-commodity
(gnc:split-get-account a))) (gnc:split-get-parent a)))
(share-amount (gnc:split-get-share-amount a)) (account-comm (gnc:account-get-commodity
(value-amount (gnc:split-get-value a)) (gnc:split-get-account a)))
(transaction-date (gnc:transaction-get-date-posted (share-amount (gnc:split-get-share-amount a))
(gnc:split-get-parent a))) (value-amount (gnc:split-get-value a))
(foreignlist (transaction-date (gnc:transaction-get-date-posted
(if (gnc:commodity-equiv? transaction-comm (gnc:split-get-parent a)))
price-commodity) (foreignlist
(list account-comm (if (gnc:commodity-equiv? transaction-comm
(gnc:numeric-neg share-amount) price-commodity)
(gnc:numeric-neg value-amount)) (list account-comm
(list transaction-comm (gnc:numeric-neg share-amount)
value-amount (gnc:numeric-neg value-amount))
share-amount)))) (list transaction-comm
value-amount
; (warn "render-scatterplot: value " share-amount))))
; (commodity-numeric->string
; (first foreignlist) (second foreignlist)) ;;(warn "render-scatterplot: value "
; " bought shares " ;; (commodity-numeric->string
; (commodity-numeric->string ;; (first foreignlist) (second foreignlist))
; price-commodity (third foreignlist))) ;; " bought shares "
;;(commodity-numeric->string
(list ;; price-commodity (third foreignlist)))
transaction-date
(if (not (gnc:commodity-equiv? (first foreignlist) (list
report-currency)) transaction-date
(begin (if (not (gnc:commodity-equiv? (first foreignlist)
(warn "render-scatterplot: " report-currency))
"Sorry, currency exchange not yet implemented:" (begin
(commodity-numeric->string (warn "render-scatterplot: "
(first foreignlist) (second foreignlist)) "Sorry, currency exchange not yet implemented:"
" (buying " (commodity-numeric->string
(commodity-numeric->string (first foreignlist) (second foreignlist))
price-commodity (third foreignlist)) " (buying "
") =? " (commodity-numeric->string
(commodity-numeric->string price-commodity (third foreignlist))
report-currency (gnc:numeric-zero))) ") =? "
(gnc:numeric-zero)) (commodity-numeric->string
(gnc:numeric-div report-currency (gnc:numeric-zero)))
(second foreignlist) (gnc:numeric-zero))
(third foreignlist) (gnc:numeric-div
GNC-DENOM-AUTO (second foreignlist)
(logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND)))))) (third foreignlist)
;; Get all the interesting splits GNC-DENOM-AUTO
(gnc:get-match-commodity-splits (logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND))))))
currency-accounts ;; Get all the interesting splits
to-date-tp price-commodity)))) (gnc:get-match-commodity-splits
currency-accounts
to-date-tp price-commodity)))
('weighted-average
(gnc:get-commodity-totalaverage-prices
currency-accounts to-date-tp
price-commodity report-currency))
)))
(set! data (filter (set! data (filter
(lambda (x) (gnc:timepair-lt from-date-tp (first x))) (lambda (x)
(gnc:timepair-lt from-date-tp (first x)))
data)) data))
;; some output ;; some output
; (warn (map (lambda (x) (list ;;(warn (map (lambda (x) (list
; (gnc:timepair-to-datestring (car x)) ;; (gnc:timepair-to-datestring (car x))
; (gnc:numeric-to-double (second x)))) ;; (gnc:numeric-to-double (second x))))
; data)) ;;data))
;; convert the gnc:numeric's to doubles ;; convert the gnc:numeric's to doubles
(set! data (map (lambda (x) (set! data (map (lambda (x)
@ -287,7 +315,7 @@
(gnc:html-scatter-set-data! (gnc:html-scatter-set-data!
chart data) chart data)
(gnc:html-document-add-object! document chart) (gnc:html-document-add-object! document chart)
(gnc:html-document-add-object! (gnc:html-document-add-object!
@ -296,11 +324,8 @@
(gnc:html-markup-p (gnc:html-markup-p
"This report calculates the 'prices of commodity' transactions \ "This report calculates the 'prices of commodity' transactions \
versus the 'report commodity'. (I.e. it won't work if there's another \ versus the 'report commodity'. (I.e. it won't work if there's another \
commodity involved in between.) The prices shown are the actual values, \ commodity involved in between.) cstim.")))
i.e. there is no averaging at all. This scaling of the x-axis looks so \
weird that \
we should rather throw it out before 1.6 is released, I guess (cstim).")))
document)) document))
;; Here we define the actual report ;; Here we define the actual report
@ -310,4 +335,3 @@ we should rather throw it out before 1.6 is released, I guess (cstim).")))
;;'menu-path (list gnc:menuname-asset-liability) ;;'menu-path (list gnc:menuname-asset-liability)
'options-generator options-generator 'options-generator options-generator
'renderer renderer)) 'renderer renderer))