Guide

Stock splits and mergers

Record a stock split with stock.split, which adds shares at no cost; record a merger by hand with ordinary transactions.

A stock split gives you more shares for the ones you have, without changing what the holding is worth: two-for-one doubles your shares and halves each one's price. The cost of the holding stays the same. A merger or takeover exchanges your shares of one company for shares of another, or for cash.

Stock split

  1. Work out how many shares you gain. A two-for-one split of 90 shares gives 90 more; the shares you pass is the increase, and a negative number records a reverse split.
  2. Call stock.split with the share account, the date and shares. Add price (the new price per share) if you want it recorded in the price database. It posts a transaction that adds shares with a value of zero, so no cash moves and the cost basis is unchanged.
  3. Check the new share count with account.balance.

If a different price is already stored for that day, blockingPrice shows it and the new price is not stored.

Merger

There is no merger method. Record one as ordinary transactions, which keeps your records easy to follow:

  1. In the old share account, post a transaction that takes out the old shares at their cost: old shares - (value the cost, amount the old share count).
  2. In a new share account for the new company, bring in the new shares with the same total value: new shares + (value the cost, amount the new shares).
  3. If you also received cash, add a cash split, and put any gain in an income account, as in Buy and sell shares.
  4. Add the new company's price with price.add.

Example

Example: with a copy of the reports/investment-lots example book open as book.gnucash.

JSON-RPC

Request:

{"jsonrpc":"2.0","id":1,"method":"stock.split","params":{"account":"Root:Assets:Broker:AAPL","date":"2021-01-01","shares":"90","price":"55.00"}}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "transaction": "…",
    "priceStatus": "added",
    "price": "…",
    "blockingPrice": null
  }
}

Request:

{"jsonrpc":"2.0","id":2,"method":"account.balance","params":{"account":"Root:Assets:Broker:AAPL"}}

Response:

{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "balances": {
      "commodity": "NASDAQ::AAPL",
      "balance": {
        "num": "180",
        "denom": "1"
      },
      "…": "…"
    },
    "…": "…"
  }
}

Command line

red-ale exec --book book.gnucash --script - <<'EOF'
stock.split {"account":"Root:Assets:Broker:AAPL","date":"2021-01-01","shares":"90","price":"55.00"}
account.balance {"account":"Root:Assets:Broker:AAPL"}
EOF

It prints:

[
  {
    "transaction": "…",
    "priceStatus": "added",
    "price": "…",
    "blockingPrice": null
  },
  {
    "balances": {
      "commodity": "NASDAQ::AAPL",
      "balance": {
        "num": "180",
        "denom": "1"
      },
      "…": "…"
    },
    "…": "…"
  }
]

MCP tool call

Tool call:

{"name":"stock.split","arguments":{"account":"Root:Assets:Broker:AAPL","date":"2021-01-01","shares":"90","price":"55.00"}}

Result:

{
  "structuredContent": {
    "transaction": "…",
    "priceStatus": "added",
    "price": "…",
    "blockingPrice": null
  }
}

Tool call:

{"name":"account.balance","arguments":{"account":"Root:Assets:Broker:AAPL"}}

Result:

{
  "structuredContent": {
    "balances": {
      "commodity": "NASDAQ::AAPL",
      "balance": {
        "num": "180",
        "denom": "1"
      },
      "…": "…"
    },
    "…": "…"
  }
}