> ## Documentation Index
> Fetch the complete documentation index at: https://khaos-ml.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Finance

> SEC filings: risk drift, event screening, insider activity.

## Track risk-factor drift year over year

**Problem:** spot companies whose risk disclosures changed the most between annual
reports. **Uses:** Khaos and NumPy.

```python theme={null}
import khaos
import numpy as np

nlp = khaos.load("sec_10k_core")

filings = {
    2023: "acme_10k_2023.html",
    2024: "acme_10k_2024.html",
    2025: "acme_10k_2025.html",
}
vectors = {year: nlp(path).vector for year, path in filings.items()}

def drift(a, b):
    return 1 - a @ b / (np.linalg.norm(a) * np.linalg.norm(b))

for y in (2024, 2025):
    print(y, round(drift(vectors[y - 1], vectors[y]), 3))
# 2024 0.041
# 2025 0.187   <- a large jump worth reading
```

## Screen 8-Ks for executive departures

**Problem:** flag a watchlist's current reports that mention a leadership change.
**Uses:** Khaos and pandas.

```python theme={null}
import khaos
import pandas as pd

events = khaos.load("sec_8k_events")

rows = []
for ticker, path in watchlist_filings.items():
    doc = events(path)
    for ent in doc.ents:
        rows.append({"ticker": ticker, "event": ent.type, "detail": ent.who})

df = pd.DataFrame(rows)
print(df[df.event == "ExecutiveDeparture"])
#   ticker               event detail
# 3   ACME  ExecutiveDeparture    CFO
# 9   GLBX  ExecutiveDeparture    COO
```

## Summarize insider selling

**Problem:** see which directors sold the most stock this quarter. **Uses:** Khaos,
pandas and Matplotlib.

```python theme={null}
import khaos
import pandas as pd
import matplotlib.pyplot as plt

form4 = khaos.load("sec_form4_insider")

trades = [t for path in form4_paths for t in form4(path).ents]
df = pd.DataFrame(trades)  # columns: role, kind, net_shares

net = df.groupby("role")["net_shares"].sum().sort_values()
net.plot.barh(title="Net shares by insider role")
plt.show()
print(net)
# role
# Director   -48000
# CFO        -12500
# CEO          3000
```

## Check an IPO's dilution

**Problem:** pull the lock-up and use-of-proceeds terms from an S-1. **Uses:** Khaos
alone.

```python theme={null}
doc = khaos.load("sec_s1_ipo")("path/to/s1.html")
for ent in doc.ents:
    print(ent)
# UseOfProceeds(purpose='debt repayment', share=0.40)
# LockUp(days=180)
# Dilution(per_share=3.20)
```

## Inputs and outputs for each model

These are real outputs of the v1 models, run through their exported ONNX files on held-out examples. The shapes listed are the exact ONNX inputs and outputs; `batch` and other named sizes are dynamic.

### `sec_10k_core`

Raw filing text in. The text is tokenized with the tokenizer saved next to the model, and the model returns a label for every token; `decode_entities` merges them into entities (it also returns character offsets, omitted here). The `gold` list is the dataset's own labels for comparison.

**Model inputs:** `input_ids int64 [batch, seq]; attention_mask int64 [batch, seq]`\
**Model outputs:** `logits float32 [batch, seq, 35]; vector float32 [batch, 768]`

**Input**

```python theme={null}
text = """
Each advance accrues interest at a per annum rate of interest equal to the greater
 of either ( i ) the “ prime rate ” as reported in The Wall Street Journal plus
4.75 % , and ( ii ) 10.25 % .
"""
```

**Output**

```json theme={null}
{
  "entities": [
    {
      "type": "INTEREST_RATE",
      "text": "4.75"
    },
    {
      "type": "INTEREST_RATE",
      "text": "10.25"
    }
  ],
  "gold": [
    {
      "type": "INTEREST_RATE",
      "text": "4.75"
    },
    {
      "type": "INTEREST_RATE",
      "text": "10.25"
    }
  ]
}
```

### `sec_8k_events`

Raw filing text in. The text is tokenized with the tokenizer saved next to the model, and the model returns a label for every token; `decode_entities` merges them into entities (it also returns character offsets, omitted here). The `gold` list is the dataset's own labels for comparison.

**Model inputs:** `input_ids int64 [batch, seq]; attention_mask int64 [batch, seq]`\
**Model outputs:** `logits float32 [batch, seq, 13]; vector float32 [batch, 768]`

**Input**

```python theme={null}
text = """
Net Income $ 17,950
<PAGE> 3
SIGNATURES
Pursuant to the requirements of the Securities Exchange Act of 1934,
the registrant has duly caused this report to be signed on its behalf by the
undersigned hereunto duly authorized.
THE COLONIAL BANCGROUP, INC.
----------------------------
(Registrant)
Date: April 15, 1998 /s/ W. Flake Oakley
----------------------------
W. Flake Oakley
Chief Financial Officer
"""
```

**Output**

```json theme={null}
{
  "entities": [
    {
      "type": "DATE",
      "text": "April 15, 1998"
    },
    {
      "type": "ROLE",
      "text": "Chief Financial Officer"
    }
  ],
  "gold": [
    {
      "type": "DATE",
      "text": "April 15, 1998"
    },
    {
      "type": "ROLE",
      "text": "Chief Financial Officer"
    }
  ]
}
```

### `sec_form4_insider`

Raw filing text in. The text is tokenized with the tokenizer saved next to the model, and the model returns a label for every token; `decode_entities` merges them into entities (it also returns character offsets, omitted here). The `gold` list is the dataset's own labels for comparison.

**Model inputs:** `input_ids int64 [batch, seq]; attention_mask int64 [batch, seq]`\
**Model outputs:** `logits float32 [batch, seq, 15]; vector float32 [batch, 768]`

**Input**

```python theme={null}
text = """
<nonDerivativeTransaction>
  <securityTitle>
    <value>Common Stock</value>
  </securityTitle>
  <transactionDate>
    <value>2012-12-12</value>
  </transactionDate>
  <transactionCoding>
    <transactionFormType>4</transactionFormType>
    <transactionCode>P</transactionCode>
    <equitySwapInvolved>0</equitySwapInvolved>
  </transactionCoding>
  <transactionAmounts>
    <transactionShares>
      <value>60900</value>
    </transactionShares>
    <transactionPricePerShare>
      <value>6.6062</value>
    </transactionPricePerShare>
    <transactionAcquiredDisposedCode>
      <value>A</value>
    </transactionAcquiredDisposedCode>
  </transactionAmounts>
  <postTransactionAmounts>
    <sharesOwnedFollowingTransaction>
      <value>300540</value>
    </sharesOwnedFollowingTransaction>
  </postTransactionAmounts>
  <ownershipNature>
    <directOrIndirectOwnership>
      <value>D</value>
    </directOrIndirectOwnership>
  </ownershipNature>
</nonDerivativeTransaction>
"""
```

**Output**

```json theme={null}
{
  "entities": [
    {
      "type": "SECURITY_TYPE",
      "text": "Common Stock"
    },
    {
      "type": "DATE",
      "text": "2012-12-12"
    },
    {
      "type": "TRANSACTION_CODE",
      "text": "P"
    },
    {
      "type": "SHARE_COUNT",
      "text": "60900"
    },
    {
      "type": "PRICE",
      "text": "6.6062"
    }
  ],
  "gold": [
    {
      "type": "SECURITY_TYPE",
      "text": "Common Stock"
    },
    {
      "type": "DATE",
      "text": "2012-12-12"
    },
    {
      "type": "TRANSACTION_CODE",
      "text": "P"
    },
    {
      "type": "SHARE_COUNT",
      "text": "60900"
    },
    {
      "type": "PRICE",
      "text": "6.6062"
    }
  ]
}
```

### `sec_s1_ipo`

Raw filing text in. The text is tokenized with the tokenizer saved next to the model, and the model returns a label for every token; `decode_entities` merges them into entities (it also returns character offsets, omitted here). The `gold` list is the dataset's own labels for comparison.

**Model inputs:** `input_ids int64 [batch, seq]; attention_mask int64 [batch, seq]`\
**Model outputs:** `logits float32 [batch, seq, 13]; vector float32 [batch, 768]`

**Input**

```python theme={null}
text = """
The “as adjusted” calculation equals $600,000,000 cash held in trust from the
proceeds of this offering and the sale of the private placement warrants, plus
$23,550 of actual stockholders’ equity as of December 31, 2019.
​
(3)
The “as adjusted” calculation includes $21,000,000 of deferred underwriting
commissions.
​
(4)
The “as adjusted” calculation equals the “as adjusted” total assets, less the “as
adjusted” total liabilities, less the “as adjusted” stockholders’ equity, which is
 set to approximate the minimum net tangible assets threshold of at least
$5,000,001.
​
(5)
"""
```

**Output**

```json theme={null}
{
  "entities": [
    {
      "type": "AMOUNT",
      "text": "$600,000,000"
    },
    {
      "type": "AMOUNT",
      "text": "$23,550"
    },
    {
      "type": "DATE",
      "text": "December 31, 2019"
    },
    {
      "type": "AMOUNT",
      "text": "$21,000,000"
    },
    {
      "type": "AMOUNT",
      "text": "$5,000,001"
    }
  ],
  "gold": [
    {
      "type": "AMOUNT",
      "text": "$600,000,000 "
    },
    {
      "type": "AMOUNT",
      "text": "$23,550 "
    },
    {
      "type": "DATE",
      "text": "December 31, 2019"
    },
    {
      "type": "AMOUNT",
      "text": "$21,000,000 "
    },
    {
      "type": "AMOUNT",
      "text": "$5,000,001"
    }
  ]
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.