Functional Weave
Code in TypeScript

invest.section-104-pool@1.0.1

README.md

5,320 bytes · view raw

# invest.section-104-pool

**Status: needs review by a tax professional before it is published.**

Works out the allowable cost of every disposal of one holding of shares under
the UK share identification rules for individuals, for disposals on or after
6 April 2008. Give it every purchase and sale of one class of shares in one
company, in date order and in sterling; it returns each day's disposal with
the shares it was matched against, the proceeds and cost of each match, the
gain or loss, and the Section 104 holding left at the end.

## The rules

Each disposal is identified with acquisitions in this order:

1. **Same day.** Shares bought on the same day as the disposal
   (TCGA 1992 s105(1)(b)). All purchases on one day are one acquisition and
   all sales on one day are one disposal (s105(1)(a)), so the result has one
   disposal per day however many trades there were.
2. **The next 30 days** ("bed and breakfasting"). Shares bought in the 30 days
   after the disposal, earliest purchase first (s106A(5)). Day 30 counts; day
   31 does not. Where two disposals could both claim one later purchase, the
   earlier disposal is matched first.
3. **The Section 104 holding.** Everything else comes out of the pool at its
   average cost (s104). Shares matched under 1 or 2 never enter the pool
   (CG51550).

Same-day matching is settled for every day before any 30-day matching, so a
purchase is taken by a sale on its own day before it can be claimed by an
earlier sale's 30-day window.

## Rounding

HMRC's own guidance apportions pool cost "by reference to the number of shares
sold" (CG51575). Here the cost of a part of a purchase or of the pool is
`cost left × shares taken / shares left`, rounded half-up to the penny, and
taken from what is left, so the pieces always add back to the whole: selling
the last share takes the last pennies. The day's proceeds are split across
its matches the same way, so each match has its own gain or loss, as in the
HS284 example. HMRC's worked examples use whole pounds; a reviewer should
confirm the penny rounding.

## Edge cases and limits

- A sale of more shares than are held at the end of that day is refused, even
  when a later purchase would be matched with it (a short sale).
- Disposals before 6 April 2008 are refused: they followed different
  identification rules (and indexation). Purchases may be any date; for
  shares held on 31 March 1982, pass the purchase at its 31 March 1982 market
  value (CG51550).
- Amounts are in GBP pence. Convert foreign-currency costs and proceeds at the
  rate on each transaction date before calling.
- Out of scope: bonus and rights issues, reorganisations, takeovers,
  employee share schemes, the non-resident and trading-company variants of
  the 30-day rule (s106A(5A)), and the older "kink test". A buy's `amount`
  is its full allowable cost including dealing costs and stamp duty; a sell's
  is the proceeds after dealing costs.

## Sources

Read on 2026-09-23:

- HMRC Capital Gains Manual CG51550, "Shares and securities: identification
  rules: shares pooling from 6 April 2008":
  https://www.gov.uk/hmrc-internal-manuals/capital-gains-manual/cg51550
- CG51560, "Identification rules for individuals from 6 April 2008" (same day,
  then 30 days, then Section 104; TCGA92/S105(1), S106A(5) and (5A)):
  https://www.gov.uk/hmrc-internal-manuals/capital-gains-manual/cg51560
- CG51575, "Section 104 holding: part disposal" (apportion by number of
  shares): https://www.gov.uk/hmrc-internal-manuals/capital-gains-manual/cg51575
- CG51590, Example 1 (Ms Davy), used as a vector:
  https://www.gov.uk/hmrc-internal-manuals/capital-gains-manual/cg51590
- HS284 "Shares and Capital Gains Tax (2025)", Example 2 (Mr Schneider), used
  as a vector with a pool cost of our own (the helpsheet gives none):
  https://www.gov.uk/government/publications/shares-and-capital-gains-tax-hs284-self-assessment-helpsheet/hs284-shares-and-capital-gains-tax-2025

## What a reviewer should check

- Penny rounding of apportioned costs and proceeds.
- That refusing short sales, rather than matching them with later purchases,
  is the right default.
- The order of 30-day matching when several disposals and purchases overlap.

## Before you rely on this

**Not professional advice.** This capability calculates investment figures from published rules. It is a software component for developers, not financial advice. Rules change and every rate here has an effective date. Check that the dates cover your case. Verify results against the official sources listed above, and have a tax adviser (CTA) review how you use it, before anyone relies on the output. Provided "as is" under its licence, without warranty.

**Unreviewed.** This capability's implementations agree in every language and pass its published test vectors, which were worked out from the official sources cited. But no qualified tax adviser (CTA) has yet checked those vectors, or confirmed that the capability covers the cases it claims. Treat it as a draft. Do not use it for real people, money or decisions without your own expert review. Once a qualified reviewer signs off, this notice is replaced with their name, qualification and the date. Each new version needs fresh sign-off.

1.0.1 marks it unreviewed. The code and the tests are unchanged.