Buy, Add and Sell Part: Reconcile Average Cost and Realized Profit

Reproduce three fictional trades with fees: 150 shares remaining, USD11.02 average cost and USD198 realized gain. Compare portfolio cost with cash recovered and a hypothetical valuation.

The key idea

Selling shares removes their allocated historical cost. Sale proceeds are not simply subtracted from the cost of every remaining share.

Choose one stated accounting convention

DividenNote uses moving weighted-average cost for its analytical ledger. Purchases add price × shares plus the entered fee to cost. A sale removes the sold fraction of the pre-sale cost; net sale cash minus that removed cost is realized gain or loss. This is the tool’s convention, not a universal broker display or tax-lot rule.

Investor.gov’s statement guide explains cost basis and realized versus unrealized results as account concepts. Actual broker records may use different lots, corporate-action adjustments or reporting conventions. Use official broker and applicable tax documents for reporting; this exercise does not calculate a tax liability or prescribe a permitted tax method.

Background source: Investor.gov: cost basis and realized/unrealized account information

Start with two buys and include the fees once

On 2 January 2026, the fictional NBRDEMO position buys 100 shares at USD10 with a USD2 fee: cost USD1,002. On 2 February it buys another 100 at USD12 with a USD2 fee: another USD1,202. Total shares are 200 and total cost is USD2,204, giving USD11.02 per share.

The name is an invented practice identifier, not a live stock recommendation or quotation. There is no opening holding in the JSON: the two buys already establish the shares. Adding a separate 200-share opening balance as well would double-count the position. Enter fees separately only if they are not already included in your stated price/cost convention.

Remove cost before interpreting the sale

On 2 March, sell 50 shares at USD15 with a USD1 selling fee. Gross proceeds are USD750 and net cash is USD749. The sale removes 50 ÷ 200 of USD2,204, or USD551 of cost. Realized gain is USD749 − USD551 = USD198.

The remaining 150 shares carry USD2,204 − USD551 = USD1,653 cost. USD1,653 ÷ 150 is still USD11.02 per share. A proportional partial sale does not itself change the moving average of the remaining shares. A later purchase at a different price can change it again.

Illustrative comparison — unchanged assumptions
StepShares after stepCost / result USD
First buy, fee included1001,002.00
Second buy, cumulative cost2002,204.00
Sell 50, remaining cost1501,653.00
Remaining average15011.02
Realized gain on sale50198.00

Check why a cash-recovered figure says USD9.70

If you subtract all sale cash from all historical purchases, USD2,204 − USD749 = USD1,455. Dividing by 150 gives USD9.70. That is an unrecovered-net-cash calculation in this restricted exercise, not the remaining book cost. The USD198 already realized explains the difference between USD1,653 book cost and USD1,455 unrecovered cash.

Neither number should be labelled as the other. Deposits, dividends, withdrawals, currency conversion and other securities would change a broader account cash calculation. The example excludes them so you can see the partial-sale distinction without accidentally calling a cash-flow figure a tax basis or holding cost.

Reproduce by backup or trades, not both

Back up your own journal first. The simplest route is a full restore of average-cost-practice.json in a practice journal. It includes the three trades, USD base currency and a clearly hypothetical saved price of USD13 dated 1 October 2026. Check 150 shares, cost USD1,653, average USD11.02 and realized gain USD198.

The alternative route is to import average-cost-practice-trades.csv into an empty practice journal through the trade importer, mapping the filled-trade fields. Do not also restore the JSON into that same exercise as an additional set of trades. The CSV has no saved quote, so enter the hypothetical price USD13 separately if you want to reproduce the valuation below. These generic files are not a certified Moomoo export.

Keep realized and unrealized results separate

At the hypothetical USD13 price, the remaining position is worth 150 × 13 = USD1,950. Unrealized gain is USD1,950 − USD1,653 = USD297. Add the USD198 realized gain to get USD495 total trade-and-valuation gain for this closed example. Independently, USD749 sale cash + USD1,950 remaining value − USD2,204 purchase cost also equals USD495.

The tool’s holding gain is the unrealized USD297, not automatically a whole-account total-return report. The USD13 price is not refreshed market data. Real statements can differ because of quote time, FX, missing trades, lot selection, fees or corporate actions. Preserve the source records and resolve those differences before treating either display as wrong.

Download the practice and audit files

Put it into practice

Use the full JSON in a backed-up practice journal, or import the CSV into an empty one. Check the cost and sale calculations before looking at the hypothetical quote.

Open DividenNote

Continue this practical series

Found an error? Contact NumNum

Understand charts and option obligations