# microprediction/allocation architecture

> Architecture diagram of the GitHub repository microprediction/allocation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/microprediction/allocation
- Repository: https://github.com/microprediction/allocation

## Overview

allocation is a Python library for online portfolio construction, exposing batch-style estimators and keyed streaming counterparts for changing asset universes. The main workflow accepts return observations, estimates covariance, computes portfolio weights, and updates those weights as new data arrives. Major method families include baselines and convex allocators, Schur/HRP bridges, and Thurstone ability tilts. The graph follows documented behavior and sampled source references; unsampled estimator internals and optional integrations are represented only where the README supports them.

Main entry points: [`allocation/base.py`](https://github.com/microprediction/allocation/blob/main/allocation/base.py) (Portfolio weights), [`allocation/thurstone.py`](https://github.com/microprediction/allocation/blob/main/allocation/thurstone.py) (Thurstone portfolio), [`allocation/keyed.py`](https://github.com/microprediction/allocation/blob/main/allocation/keyed.py) (Keyed streaming), [`allocation/bridge.py`](https://github.com/microprediction/allocation/blob/main/allocation/bridge.py) (Schur bridges)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["Estimator API"]
  node_batch["Batch estimators<br/>[base.py]"]
  node_covariance["Covariance estimates<br/>[moments.py]"]
  node_weights["Portfolio weights<br/>[base.py]"]
end

subgraph group_methods["Allocation Methods"]
  node_baselines["Baselines and ERC<br/>[baselines.py]"]
  node_convex["Convex allocators<br/>[convex.py]"]
  node_schur["Schur and HRP<br/>[schur.py]"]
  node_bridges["Schur bridges<br/>[bridge.py]"]
  node_thurstone["Thurstone portfolio<br/>[thurstone.py]"]
end

subgraph group_stream["Streaming Universe"]
  node_keyed["Keyed streaming<br/>[keyed.py]"]
  node_universe["Universe mapping<br/>[universe.py]"]
end

subgraph group_internals["Method Internals"]
  node_calibration["Ability calibration<br/>[calibrate.py]"]
  node_corrprep["Correlation preparation<br/>[covariance.py]"]
  node_race["Race transport<br/>[transport.py]"]
  node_seriation["Fiedler seriation<br/>[seriation.py]"]
  node_schurengine["Schur conditioning<br/>[bridge.py]"]
end

node_user(("Portfolio user"))

node_user -->|"fits returns"| node_batch
node_batch -->|"updates covariance"| node_covariance
node_batch -->|"produces weights"| node_weights
node_user -->|"streams observations"| node_keyed
node_keyed -.->|"handles changing IDs"| node_universe
node_keyed -->|"orders assets"| node_seriation
node_keyed -->|"updates covariance"| node_covariance
node_baselines -->|"allocates weights"| node_weights
node_convex -->|"optimizes weights"| node_weights
node_schur -->|"uses Fiedler order"| node_seriation
node_schur -->|"allocates weights"| node_weights
node_bridges -->|"uses conditioning"| node_schurengine
node_bridges -->|"partitions assets"| node_seriation
node_bridges -->|"bridges portfolios"| node_weights
node_thurstone -->|"calibrates abilities"| node_calibration
node_thurstone -->|"prepares correlation"| node_corrprep
node_thurstone -->|"transports race"| node_race
node_thurstone -->|"returns win weights"| node_weights
node_calibration -->|"uses correlation tools"| node_corrprep
node_race -->|"uses matrix utilities"| node_corrprep

click node_batch "https://github.com/microprediction/allocation/blob/main/allocation/base.py"
click node_covariance "https://github.com/microprediction/allocation/blob/main/allocation/moments.py"
click node_weights "https://github.com/microprediction/allocation/blob/main/allocation/base.py"
click node_baselines "https://github.com/microprediction/allocation/blob/main/allocation/baselines.py"
click node_convex "https://github.com/microprediction/allocation/blob/main/allocation/convex.py"
click node_schur "https://github.com/microprediction/allocation/blob/main/allocation/schur.py"
click node_bridges "https://github.com/microprediction/allocation/blob/main/allocation/bridge.py"
click node_thurstone "https://github.com/microprediction/allocation/blob/main/allocation/thurstone.py"
click node_keyed "https://github.com/microprediction/allocation/blob/main/allocation/keyed.py"
click node_universe "https://github.com/microprediction/allocation/blob/main/allocation/universe.py"
click node_calibration "https://github.com/microprediction/allocation/blob/main/allocation/_thurstone/calibrate.py"
click node_corrprep "https://github.com/microprediction/allocation/blob/main/allocation/_thurstone/covariance.py"
click node_race "https://github.com/microprediction/allocation/blob/main/allocation/_thurstone/transport.py"
click node_seriation "https://github.com/microprediction/allocation/blob/main/allocation/_schur/seriation.py"
click node_schurengine "https://github.com/microprediction/allocation/blob/main/allocation/_schur/bridge.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_batch,node_covariance,node_weights,node_user toneBlue
class node_baselines,node_convex,node_schur,node_bridges,node_thurstone toneAmber
class node_keyed,node_universe toneMint
class node_calibration,node_corrprep,node_race,node_seriation,node_schurengine toneRose
```

## Components

### Estimator API

- [Batch estimators](https://github.com/microprediction/allocation/blob/main/allocation/base.py): `allocation/base.py`
- [Covariance estimates](https://github.com/microprediction/allocation/blob/main/allocation/moments.py): `allocation/moments.py`
- [Portfolio weights](https://github.com/microprediction/allocation/blob/main/allocation/base.py): `allocation/base.py`

### Allocation Methods

- [Baselines and ERC](https://github.com/microprediction/allocation/blob/main/allocation/baselines.py): `allocation/baselines.py`
- [Convex allocators](https://github.com/microprediction/allocation/blob/main/allocation/convex.py): `allocation/convex.py`
- [Schur and HRP](https://github.com/microprediction/allocation/blob/main/allocation/schur.py): `allocation/schur.py`
- [Schur bridges](https://github.com/microprediction/allocation/blob/main/allocation/bridge.py): `allocation/bridge.py`
- [Thurstone portfolio](https://github.com/microprediction/allocation/blob/main/allocation/thurstone.py): `allocation/thurstone.py`

### Streaming Universe

- [Keyed streaming](https://github.com/microprediction/allocation/blob/main/allocation/keyed.py): `allocation/keyed.py`
- [Universe mapping](https://github.com/microprediction/allocation/blob/main/allocation/universe.py): `allocation/universe.py`

### Method Internals

- [Ability calibration](https://github.com/microprediction/allocation/blob/main/allocation/_thurstone/calibrate.py): `allocation/_thurstone/calibrate.py`
- [Correlation preparation](https://github.com/microprediction/allocation/blob/main/allocation/_thurstone/covariance.py): `allocation/_thurstone/covariance.py`
- [Race transport](https://github.com/microprediction/allocation/blob/main/allocation/_thurstone/transport.py): `allocation/_thurstone/transport.py`
- [Fiedler seriation](https://github.com/microprediction/allocation/blob/main/allocation/_schur/seriation.py): `allocation/_schur/seriation.py`
- [Schur conditioning](https://github.com/microprediction/allocation/blob/main/allocation/_schur/bridge.py): `allocation/_schur/bridge.py`

### Other components

- **Portfolio user**

## Connections

- Portfolio user → Batch estimators: fits returns
- Batch estimators → Covariance estimates: updates covariance (evidence: `allocation/base.py`)
- Batch estimators → Portfolio weights: produces weights (evidence: `allocation/base.py`)
- Portfolio user → Keyed streaming: streams observations
- Keyed streaming → Universe mapping: handles changing IDs
- Keyed streaming → Fiedler seriation: orders assets (evidence: `allocation/keyed.py`)
- Keyed streaming → Covariance estimates: updates covariance (evidence: `allocation/keyed.py`)
- Baselines and ERC → Portfolio weights: allocates weights (evidence: `allocation/baselines.py`)
- Convex allocators → Portfolio weights: optimizes weights (evidence: `allocation/convex.py`)
- Schur and HRP → Fiedler seriation: uses Fiedler order
- Schur and HRP → Portfolio weights: allocates weights
- Schur bridges → Schur conditioning: uses conditioning (evidence: `allocation/bridge.py`)
- Schur bridges → Fiedler seriation: partitions assets (evidence: `allocation/bridge.py`)
- Schur bridges → Portfolio weights: bridges portfolios (evidence: `allocation/bridge.py`)
- Thurstone portfolio → Ability calibration: calibrates abilities (evidence: `allocation/thurstone.py`)
- Thurstone portfolio → Correlation preparation: prepares correlation (evidence: `allocation/thurstone.py`)
- Thurstone portfolio → Race transport: transports race (evidence: `allocation/thurstone.py`)
- Thurstone portfolio → Portfolio weights: returns win weights (evidence: `allocation/thurstone.py`)
- Ability calibration → Correlation preparation: uses correlation tools (evidence: `allocation/_thurstone/calibrate.py`)
- Race transport → Correlation preparation: uses matrix utilities (evidence: `allocation/_thurstone/transport.py`)
