# Fund holdings changes

**Result:** the script below compares a fund manager's last two 13F reports, and prints the ten biggest changes. A 13F lists the stocks a manager holds on a quarter's last day, and is filed up to 45 days later. For Berkshire Hathaway, June 30 to September 30, 2026, it printed:

```text
Position                          Shares 2026-06-30  Shares 2026-09-30  Change in value
BANK OF AMER CORP COM                   483,394,015        455,860,908  -$1,499 million
LENNAR CORP CL A                         13,111,741         26,034,436  +$1,054 million
VERISIGN INC COM                          8,989,880          5,922,136  -$865 million
BENDING SPOONS SPA COM SHS                        0         20,689,655  +$689 million
DELTA AIR LINES INC COM NEW              57,320,000         64,450,000  +$595 million
CAPITAL ONE FINL CORP COM                 3,000,000          1,150,000  -$357 million
KROGER CO COM                            39,000,000         35,000,000  -$234 million
NUCOR CORP COM                            1,857,752          1,580,776  -$65 million
DAVITA INC COM                           28,880,209         28,697,229  -$32 million
LENNAR CORP CL B                            298,117            553,000  +$20 million
```

A 0 means no shares.

- A 0 in the older quarter is a new position.
- A 0 in the newer quarter means the manager sold the whole position or did not report it: a 13F leaves out short positions, and the SEC can let a manager keep a position confidential for a time.

**Change in value** estimates each trade's size from the reported value per share, not what the fund paid.

## The script

**Run it:**

- Save the script as `fund.py` beside [`helper.py`](https://www.secblast.com/docs/workflows#helper-used-by-every-example), and run `python fund.py`.
- It makes 4 requests for Berkshire Hathaway: 1 for its CIK, 1 for the quarters, and 1 for each quarter's holdings. A quarter with more than 1,000 holding rows takes 1 more request per 1,000 rows. Runs on the Free plan ([limits](https://www.secblast.com/docs/rate-limits)).

**First call:** step 1 of the script as a curl command, with your key in the `Authorization: Bearer` header. It returned:

```bash
curl -sS -H "Authorization: Bearer $SECBLAST_API_KEY" \
  'https://api.secblast.com/v3/entities/BRK.B'
```

```json
{"cik":"0001067983","name":"BERKSHIRE HATHAWAY INC"}
```

```python
from collections import defaultdict

from helper import get  # helper.py: www.secblast.com/docs/workflows

MANAGER = "BRK.B"  # the manager's ticker, or its CIK if it has no ticker
EMPTY = {"name": "", "shares": 0, "value": 0}

def positions(cik, period):
    """The manager's share positions for one quarter, by CUSIP."""
    out = defaultdict(lambda: dict(EMPTY))
    cursor = None
    while True:
        page = get(
            f"/v3/ownership/institutional/managers/{cik}/holdings",
            period=period,
            limit=1000,
            cursor=cursor,
        ).json()
        for row in page["data"]:
            # Shares only: options (put_call set) and bonds (PRN) are left out.
            if row["put_call"] or row["amount_type"] != "SH":
                continue
            # One position can take several rows: add them up.
            p = out[row["cusip"]]
            p["name"] = f"{row['name_of_issuer']} {row['title_of_class']}"
            p["shares"] += int(float(row["shares_or_principal"]))
            p["value"] += float(row["value_usd"])
        cursor = page["next_cursor"]
        if not page["has_more"]:
            break
    return out

# 1. Find the manager's CIK.
cik = int(get(f"/v3/entities/{MANAGER}").json()["cik"])

# 2. Find its two newest quarters.
quarters = get(
    f"/v3/ownership/institutional/managers/{cik}/periods", limit=2
).json()["data"]
if len(quarters) < 2:
    raise SystemExit(f"{MANAGER} has filed fewer than two 13F reports.")
older, newer = sorted(q["period"] for q in quarters)

# 3. Get the positions of both quarters.
now, before = positions(cik, newer), positions(cik, older)

# 4. Value each change in shares at the price per share (value / shares),
# and print the ten biggest, bought or sold.
changes = []
for cusip in now.keys() | before.keys():
    a, b = before.get(cusip, EMPTY), now.get(cusip, EMPTY)
    shares = b["shares"] - a["shares"]
    if shares == 0:
        continue
    held = b if b["shares"] else a  # a position sold out: the older price
    dollars = shares * held["value"] / held["shares"]
    changes.append((dollars, held["name"], a["shares"], b["shares"]))

head = ("Position", f"Shares {older}", f"Shares {newer}", "Change in value")
print(f"{head[0]:32} {head[1]:>18} {head[2]:>18}  {head[3]}")
biggest = sorted(changes, key=lambda c: -abs(c[0]))[:10]
for dollars, name, was, is_now in biggest:
    sign = "-" if dollars < 0 else "+"
    change = f"{sign}${abs(dollars) / 1e6:,.0f} million"
    print(f"{name:32} {was:>18,} {is_now:>18,}  {change}")

```

## What each step returns

**1. Find the manager's CIK.** The 13F routes take a manager's CIK, the SEC's ID number for a filer. The entities route takes a ticker or a CIK and returns the CIK and name, here `BERKSHIRE HATHAWAY INC`. Most managers have no ticker; for those, set `MANAGER` to the CIK ([find a CIK](https://www.secblast.com/docs/reference/get-entities)). The first call above shows its answer.

**2. Find the two newest quarters.** The periods route lists a manager's quarters, newest first, each by its last day. `limit=2` keeps two.

```json
{"data":[{"period":"2026-09-30"},{"period":"2026-06-30"}]}
```

**3. Get the holdings.** The holdings route lists a quarter's holdings. Each row has the security's CUSIP, its 9-character ID ([SEC terms](https://www.secblast.com/docs/sec-terms#ownership)), its shares (`shares_or_principal`), and its value in dollars (`value_usd`).

- One position can take several rows, so the script adds them up by CUSIP. Lennar Class A takes the 3 rows of the sample on September 30, 2026, 26,034,436 shares in all.
- The script leaves out rows that are not shares: options (`put_call` set) and bonds (`amount_type` `PRN`).
- When the manager amends a report, the route lists the amended rows in place of the ones they restate, so no position counts twice.
- `limit` is 1,000, the most a page holds. While `has_more` is `true`, the script passes `next_cursor` back as `cursor`.

It returned (3 of 89 shown):

```json
{
  "data": [
    {
      "cusip": "526057104",
      "name_of_issuer": "LENNAR CORP",
      "title_of_class": "CL A",
      "amount_type": "SH",
      "put_call": null,
      "shares_or_principal": "3625000",
      "value_usd": "295763750"
    },
    {
      "cusip": "526057104",
      "name_of_issuer": "LENNAR CORP",
      "title_of_class": "CL A",
      "amount_type": "SH",
      "put_call": null,
      "shares_or_principal": "4532087",
      "value_usd": "369772978"
    },
    {
      "cusip": "526057104",
      "name_of_issuer": "LENNAR CORP",
      "title_of_class": "CL A",
      "amount_type": "SH",
      "put_call": null,
      "shares_or_principal": "17877349",
      "value_usd": "1458612905"
    }
  ],
  "has_more": false,
  "next_cursor": null
}
```

**4. Compare the quarters.** **Change in value** is the change in shares times the price per share (reported value divided by shares); a position sold out takes the older quarter's price. The script prints the ten biggest changes, bought or sold.

## Going further

- **Options and bonds:** keep the rows with `put_call` set or `amount_type` `PRN` to see those positions too.
- **More quarters:** a higher `limit` on the periods route lists more quarters to compare.
