mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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:
parent
5848a94c30
commit
87edd32c82
10
ChangeLog
10
ChangeLog
@ -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>
|
||||
|
||||
* src/scm/report/net-barchart.scm: check for empty data
|
||||
|
@ -83,6 +83,82 @@
|
||||
(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
|
||||
;; and add them to report-commodity, if possible. This function takes
|
||||
;; a sumlist (described below) and returns an alist similar to one
|
||||
|
@ -31,6 +31,7 @@
|
||||
(optname-report-currency (N_ "Report's currency"))
|
||||
|
||||
(optname-price-commodity (N_ "Price of Commodity"))
|
||||
(optname-price-source (N_ "Price Source"))
|
||||
|
||||
;; (optname-accounts (N_ "Accounts"))
|
||||
|
||||
@ -59,17 +60,17 @@
|
||||
(gnc:options-add-interval-choice!
|
||||
options gnc:pagename-general optname-stepsize "b" 'MonthDelta)
|
||||
|
||||
; (add-option
|
||||
; (gnc:make-account-list-option
|
||||
; gnc:pagename-accounts optname-accounts
|
||||
; "c"
|
||||
; (N_ "Report on these accounts, if chosen account level allows.")
|
||||
; (lambda ()
|
||||
; (gnc:group-get-subaccounts (gnc:get-current-group)))
|
||||
; (lambda (accounts)
|
||||
; (list #t
|
||||
; accounts))
|
||||
; #t))
|
||||
; (add-option
|
||||
; (gnc:make-account-list-option
|
||||
; gnc:pagename-accounts optname-accounts
|
||||
; "c"
|
||||
; (N_ "Report on these accounts, if chosen account level allows.")
|
||||
; (lambda ()
|
||||
; (gnc:group-get-subaccounts (gnc:get-current-group)))
|
||||
; (lambda (accounts)
|
||||
; (list #t
|
||||
; accounts))
|
||||
; #t))
|
||||
|
||||
(gnc:options-add-currency!
|
||||
options gnc:pagename-general optname-report-currency "d")
|
||||
@ -81,11 +82,27 @@
|
||||
(N_ "Calculate the price of this commodity.")
|
||||
(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!
|
||||
options gnc:pagename-display
|
||||
optname-plot-width optname-plot-height "c" 500 400)
|
||||
|
||||
|
||||
(gnc:options-add-marker-choice!
|
||||
options gnc:pagename-display
|
||||
optname-marker "a" 'filledsquare)
|
||||
@ -126,7 +143,7 @@
|
||||
(op-value gnc:pagename-general
|
||||
optname-from-date))))
|
||||
(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))
|
||||
(width (op-value gnc:pagename-display optname-plot-width))
|
||||
@ -140,6 +157,8 @@
|
||||
optname-report-currency))
|
||||
(price-commodity (op-value gnc:pagename-general
|
||||
optname-price-commodity))
|
||||
(price-source (op-value gnc:pagename-general
|
||||
optname-price-source))
|
||||
|
||||
(dates-list (gnc:make-date-list
|
||||
(gnc:timepair-end-day-time from-date-tp)
|
||||
@ -151,6 +170,7 @@
|
||||
(currency-accounts
|
||||
(filter gnc:account-has-shares? (gnc:group-get-subaccounts
|
||||
(gnc:get-current-group))))
|
||||
;; some bogus data
|
||||
(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))))
|
||||
|
||||
@ -193,70 +213,78 @@
|
||||
;; go into commodity-utilities.scm or even start a new file.
|
||||
(set!
|
||||
data
|
||||
;; go through all splits; convert all splits into a
|
||||
;; price.
|
||||
(map
|
||||
(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:split-get-share-amount a))
|
||||
(value-amount (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
|
||||
(gnc:numeric-neg share-amount)
|
||||
(gnc:numeric-neg 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 "render-scatterplot: "
|
||||
"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))
|
||||
(gnc:numeric-div
|
||||
(second foreignlist)
|
||||
(third foreignlist)
|
||||
GNC-DENOM-AUTO
|
||||
(logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND))))))
|
||||
;; Get all the interesting splits
|
||||
(gnc:get-match-commodity-splits
|
||||
currency-accounts
|
||||
to-date-tp price-commodity))))
|
||||
(case price-source
|
||||
('actual-transactions
|
||||
;; go through all splits; convert all splits into a
|
||||
;; price.
|
||||
(map
|
||||
(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:split-get-share-amount a))
|
||||
(value-amount (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
|
||||
(gnc:numeric-neg share-amount)
|
||||
(gnc:numeric-neg 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 "render-scatterplot: "
|
||||
"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))
|
||||
(gnc:numeric-div
|
||||
(second foreignlist)
|
||||
(third foreignlist)
|
||||
GNC-DENOM-AUTO
|
||||
(logior (GNC-DENOM-SIGFIGS 8) GNC-RND-ROUND))))))
|
||||
;; Get all the interesting splits
|
||||
(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
|
||||
(lambda (x) (gnc:timepair-lt from-date-tp (first x)))
|
||||
(lambda (x)
|
||||
(gnc:timepair-lt from-date-tp (first x)))
|
||||
data))
|
||||
|
||||
|
||||
;; some output
|
||||
; (warn (map (lambda (x) (list
|
||||
; (gnc:timepair-to-datestring (car x))
|
||||
; (gnc:numeric-to-double (second x))))
|
||||
; data))
|
||||
;;(warn (map (lambda (x) (list
|
||||
;; (gnc:timepair-to-datestring (car x))
|
||||
;; (gnc:numeric-to-double (second x))))
|
||||
;;data))
|
||||
|
||||
;; convert the gnc:numeric's to doubles
|
||||
(set! data (map (lambda (x)
|
||||
@ -287,7 +315,7 @@
|
||||
|
||||
(gnc:html-scatter-set-data!
|
||||
chart data)
|
||||
|
||||
|
||||
(gnc:html-document-add-object! document chart)
|
||||
|
||||
(gnc:html-document-add-object!
|
||||
@ -296,11 +324,8 @@
|
||||
(gnc:html-markup-p
|
||||
"This report calculates the 'prices of commodity' transactions \
|
||||
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, \
|
||||
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).")))
|
||||
|
||||
commodity involved in between.) cstim.")))
|
||||
|
||||
document))
|
||||
|
||||
;; 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)
|
||||
'options-generator options-generator
|
||||
'renderer renderer))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user