Index: src/report/standard-reports/advanced-portfolio.scm
===================================================================
--- src/report/standard-reports/advanced-portfolio.scm	(revision 14275)
+++ src/report/standard-reports/advanced-portfolio.scm	(working copy)
@@ -207,24 +207,34 @@
 	  ((average-basis) 
            (if (not (eqv? b-list '()))
                (list (cons (gnc:numeric-add b-units 
-                                            (caar b-list) 10000 GNC-RND-ROUND) 
+                                            (caar b-list) 
+                                            GNC-DENOM-AUTO 
+                                            (logior GNC-DENOM-REDUCE GNC-RND-NEVER)) 
                            (gnc:numeric-div 
                             (gnc:numeric-add b-value
                                              (gnc:numeric-mul (caar b-list)
                                                               (cdar b-list) 
-                                                              10000 GNC-RND-ROUND)
-                                             10000 GNC-RND-ROUND)
+                                                              GNC-DENOM-AUTO 
+                                                              (logior 
+                                                               GNC-DENOM-REDUCE 
+                                                               GNC-RND-NEVER))
+                                             GNC-DENOM-AUTO 
+                                             (logior GNC-DENOM-REDUCE GNC-RND-NEVER))
                             (gnc:numeric-add b-units 
-                                             (caar b-list) 10000 GNC-RND-ROUND)
-                            10000 GNC-RND-ROUND)))
+                                             (caar b-list) 
+                                             GNC-DENOM-AUTO 
+                                             (logior GNC-DENOM-REDUCE GNC-RND-NEVER))
+                            GNC-DENOM-AUTO 
+                            (logior GNC-DENOM-REDUCE GNC-RND-NEVER))))
                (append b-list 
                        (list (cons b-units (gnc:numeric-div 
-                                            b-value b-units 10000 
-                                            GNC-RND-ROUND))))))
+                                            b-value b-units GNC-DENOM-AUTO 
+                                            (logior GNC-DENOM-REDUCE GNC-RND-NEVER)))))))
 	  (else (append b-list 
                         (list (cons b-units (gnc:numeric-div 
-                                             b-value b-units 10000 
-                                             GNC-RND-ROUND))))))
+                                             b-value b-units GNC-DENOM-AUTO 
+                                             (logior GNC-DENOM-REDUCE GNC-RND-NEVER)))))))
+
 	(if (not (eqv? b-list '()))
 	    (case b-method
 	      ((fifo-basis) 
@@ -232,11 +242,15 @@
                                (gnc:numeric-abs b-units) (caar b-list))))
                    (basis-builder (cdr b-list) (gnc:numeric-add 
                                                 b-units 
-                                                (caar b-list) 10000 GNC-RND-ROUND) 
+                                                (caar b-list) 
+                                                GNC-DENOM-AUTO 
+                                                (logior GNC-DENOM-REDUCE GNC-RND-NEVER)) 
                                   b-value b-method)
                    (append (list (cons (gnc:numeric-add 
                                         b-units 
-                                        (caar b-list) 10000 GNC-RND-ROUND) 
+                                        (caar b-list)
+                                        GNC-DENOM-AUTO 
+                                        (logior GNC-DENOM-REDUCE GNC-RND-NEVER)) 
                                        (cdar b-list))) (cdr b-list))))
 	      ((filo-basis) 
                (if (not (= -1 (gnc:numeric-compare 
@@ -245,16 +259,21 @@
                                   (gnc:numeric-add 
                                    b-units 
                                    (caar (reverse b-list)) 
-                                   10000 GNC-RND-ROUND) 
+                                   GNC-DENOM-AUTO (logior GNC-DENOM-REDUCE GNC-RND-NEVER)) 
                                   b-value b-method)
                    (append (cdr (reverse b-list)) 
                            (list (cons (gnc:numeric-add 
                                         b-units 
-                                        (caar (reverse b-list)) 10000 GNC-RND-ROUND) 
+                                        (caar (reverse b-list)) 
+                                        GNC-DENOM-AUTO 
+                                        (logior GNC-DENOM-REDUCE GNC-RND-NEVER)) 
                                        (cdar (reverse b-list)))))))
 	      ((average-basis) 
                (list (cons (gnc:numeric-add 
-                            (caar b-list) b-units 10000 GNC-RND-ROUND) 
+                            (caar b-list) 
+                            b-units 
+                            GNC-DENOM-AUTO 
+                            (logior GNC-DENOM-REDUCE GNC-RND-NEVER)) 
                            (cdar b-list)))))
 	    '()
 	    )
@@ -322,9 +341,9 @@
 		 (commod-currency (if price (gnc:price-get-currency price) currency))
                  (value (exchange-fn (gnc:make-gnc-monetary commodity units) currency))
 
-		 (txn-value (gnc:numeric-zero))
 		 (txn-date to-date)
 		 (pricing-txn #f)
+		 (last-price (gnc:numeric-zero))
 		 (use-txn #f)
 		 (basis-list '())
 		 (txn-units (gnc:numeric-zero))
@@ -334,9 +353,11 @@
 ;;          (gnc:debug "---" name "---")
 	    (for-each
 	     (lambda (split)
+                
 	       (set! work-done (+ 1 work-done))
 	       (gnc:report-percent-done (* 100 (/ work-done work-to-do)))
-	       (let ((parent (gnc:split-get-parent split)))
+	       (let ((parent (gnc:split-get-parent split))
+                     (txn-value (gnc:numeric-zero)))
 		 (if (gnc:timepair-le (gnc:transaction-get-date-posted parent) to-date)
 		     (begin
 		       (for-each
@@ -350,15 +371,14 @@
 
 			    ;;only change the commod-currency if price failed
 			    (if (not price) (set! commod-currency (gnc:account-get-commodity (gnc:split-get-account s))))
-			    (set! txn-value (gnc:numeric-abs (gnc:split-get-value s)));;FIXME use gnc:split-get-share-price
-			    (set! txn-date (gnc:transaction-get-date-posted parent))
+			    (set! txn-value (gnc:numeric-abs (gnc:split-get-value s))))
+			   ((same-account? current (gnc:split-get-account s))
+			    (set! txn-units (gnc:split-get-amount s))
+			    (set! last-price (gnc:split-get-share-price s))
 			    (set! pricing-txn parent)
-			    )
-			   ((same-account? current (gnc:split-get-account s))
-			    (set! txn-units (gnc:split-get-amount s)))
-			    
-			      )
+			    (set! txn-date (gnc:transaction-get-date-posted parent)))
 			  )
+			)
 
 			(gnc:transaction-get-splits parent))
 
@@ -437,13 +457,9 @@
 	    ;; okay we're using the txn, so make a new price, value etc. and warn the user
 	    (if use-txn
 		(begin
-		  (set! price (if (not (gnc:numeric-zero-p txn-units))
-				  (gnc:make-gnc-monetary commod-currency
-							 (gnc:numeric-div txn-value
-									  (gnc:numeric-abs txn-units)
-									  100 GNC-RND-ROUND))
-				  (gnc:make-gnc-monetary commod-currency (gnc:numeric-zero))))
-
+                  (set! price (if (not (gnc:numeric-zero-p last-price))
+                                  (gnc:make-gnc-monetary commod-currency last-price)
+                                  (gnc:make-gnc-monetary commod-currency (gnc:numeric-zero))))
 		  (set! value (if price (gnc:make-gnc-monetary commod-currency 
 						     (gnc:numeric-mul units 
 								      (gnc:gnc-monetary-amount price)
