# How Does AI Berkshire Verify Market Capitalization? Inside the `verify_market_cap` Method

> Learn how AI Berkshire verifies market capitalization using its `verify_market_cap` method. Discover the precision checks and discrepancy thresholds for accurate validation.

- Repository: [Xbt Lin/ai-berkshire](https://github.com/xbtlin/ai-berkshire)
- Tags: how-to-guide
- Published: 2026-07-29

---

**AI Berkshire validates market capitalization by performing a high-precision arithmetic check in [`tools/financial_rigor.py`](https://github.com/xbtlin/ai-berkshire/blob/main/tools/financial_rigor.py) that compares price × shares against the reported figure, flagging discrepancies exceeding 1% as warnings and rejecting those over 5%.**

AI Berkshire employs rigorous financial data validation to ensure investment research relies on accurate fundamentals. At the core of this process is the `verify_market_cap` function located in [`tools/financial_rigor.py`](https://github.com/xbtlin/ai-berkshire/blob/main/tools/financial_rigor.py), which performs exact decimal arithmetic to detect inconsistencies between calculated and reported market capitalization values.

## Decimal-Based Calculation Pipeline

To avoid floating-point drift that could distort billion-dollar valuations, the verification process relies on Python's `decimal` module with a high-precision context.

### Exact Conversion via `exact()`

In [`tools/financial_rigor.py`](https://github.com/xbtlin/ai-berkshire/blob/main/tools/financial_rigor.py), the utility converts `price`, `shares`, and `reported_cap` inputs into `Decimal` objects using an `exact()` helper (lines 31-38). This conversion eliminates scientific notation ambiguities and ensures subsequent multiplication operates on exact numeric representations rather than binary floating-point approximations.

### High-Precision Multiplication

The function multiplies price by shares using a dedicated high-precision context `_CTX` (lines 74-80). This **calculated market capitalization** serves as the ground truth against which external reported values are benchmarked.

## Deviation Analysis and Threshold Logic

Once the calculated cap is determined, the system quantifies variance using a strict percentage-based methodology.

### Percentage Deviation Formula

The implementation computes deviation as:

```text
|calculated - reported| / reported × 100%

```

This calculation skips division safety checks when the reported value is zero (line 81).

### The Three-Tier Validation Threshold

The `verify_market_cap` function implements granular risk signaling (lines 93-104):

- **> 5% deviation**: Returns `False` and emits a hard warning (❌), suggesting potential unit mismatches (e.g., millions vs. billions) or data entry errors in share counts or prices.
- **1% – 5% deviation**: Returns `True` with a caution flag (⚠️), acknowledging acceptable variance from intraday market movements.
- **≤ 1% deviation**: Returns `True` with a success indicator (✅), confirming the reported figure aligns with the calculated valuation.

### Human-Readable Reporting

Before returning, the function prints a formatted diagnostic showing input parameters, the computed cap, reported cap, and the specific deviation percentage (lines 83-90). This creates an auditable trail for financial analysts reviewing the AI Berkshire research pipeline.

## Implementation Reference: [`tools/financial_rigor.py`](https://github.com/xbtlin/ai-berkshire/blob/main/tools/financial_rigor.py)

The core verification logic resides in the `verify_market_cap` function within [`tools/financial_rigor.py`](https://github.com/xbtlin/ai-berkshire/blob/main/tools/financial_rigor.py). Line 71 initiates the calculation sequence, while lines 93-104 handle the threshold comparison logic that determines validation pass or fail states. The companion test suite in [`tests/test_financial_rigor.py`](https://github.com/xbtlin/ai-berkshire/blob/main/tests/test_financial_rigor.py) confirms the accuracy of these warning thresholds under various edge cases.

## Practical Usage Examples

You can invoke the verification via command line or integrate it directly into Python research scripts.

### Command Line Interface

Run the standalone verification from the repository root:

```bash
python3 tools/financial_rigor.py verify-market-cap \
    --price 510 \
    --shares 9.11e9 \
    --reported 4.65e12 \
    --currency HKD

```

### Python API Integration

Import the function for programmatic validation:

```python
from tools import financial_rigor as F

# Example with tight alignment (deviation < 1%)

F.verify_market_cap(
    price=8.00,
    shares=500_000_000,
    reported_cap=4_000_000_000,
    currency='CNY'
)

# Example triggering hard warning (deviation > 5%)

F.verify_market_cap(
    price=8.00,
    shares=500_000_000,
    reported_cap=40.00,
    currency='CNY'
)

```

## Summary

- **AI Berkshire verify market capitalization** through exact decimal arithmetic in [`tools/financial_rigor.py`](https://github.com/xbtlin/ai-berkshire/blob/main/tools/financial_rigor.py), specifically via the `verify_market_cap` function.
- The process converts all inputs to `Decimal` objects using `exact()` (lines 31-38) to eliminate floating-point errors.
- Calculated market cap derives from high-precision multiplication of price × shares using `_CTX` (lines 74-80).
- Deviation tolerance follows a strict three-tier system: failures above 5% (returns `False`), warnings between 1-5%, and acceptance below 1% (lines 93-104).
- Both CLI and Python API interfaces support manual verification and automated pipeline integration.

## Frequently Asked Questions

### What tolerance thresholds does AI Berkshire use for market cap verification?

AI Berkshire applies a strict percentage-based hierarchy: discrepancies exceeding 5% trigger a hard failure and return `False`, indicating potential unit errors or data corruption. Variances between 1% and 5% generate cautionary warnings but pass validation, while deviations under 1% receive full acceptance marks.

### Why does the implementation use Python's Decimal module instead of standard floats?

The `verify_market_cap` function relies on `Decimal` conversion via `exact()` (lines 31-38) because standard floating-point arithmetic introduces binary representation errors that compound when multiplying large share counts by stock prices. The high-precision `_CTX` ensures billion-dollar valuations maintain exactitude required for financial rigor.

### What does the `verify_market_cap` function return when validation fails?

When the calculated market capitalization deviates by more than 5% from the reported figure, the function returns `False` (lines 93-104) alongside a formatted error message. For deviations of 5% or less, it returns `True`, though it distinguishes between cautionary (1-5%) and successful (≤1%) states through visual indicators in the output.

### How can I manually verify a market capitalization figure using AI Berkshire's tools?

Execute the CLI command `python3 tools/financial_rigor.py verify-market-cap` with `--price`, `--shares`, `--reported`, and `--currency` arguments, or import `verify_market_cap` from `tools.financial_rigor` in Python to validate figures programmatically within research notebooks or automated data pipelines.