# angusmit/qpricer architecture

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

- Interactive diagram: https://gitdiagram.com/angusmit/qpricer
- Repository: https://github.com/angusmit/qpricer

## Overview

1. **Overall shape**
   - This is a single q/kdb+ monorepo organized as a **layered research and pricing platform**.
   - Dependencies flow “downward only”: infrastructure and shared primitives at the bottom, then market-data/state/curve abstractions, then pricing models and analytics, then backtesting/governance/workflow layers on top.

2. **Runtime and bootstrap**
   - Everything is loaded through `core/init.q`, which acts as the **bootstrap entry point**.
   - `core` contains the low-level runtime support: math, RNG, stats, timing, caching, utilities, config loading, and the registry spine used for plugin-style conformance checks.
   - `config/` provides environment-specific `.q` value files (`base.q`, `dev.q`) that feed the system configuration layer.

3. **Data ingress and persistence boundary**
   - `data/` is the ingestion boundary: parsers, date-built splayed HDB layout, and backtest/commodity data helpers.
   - The repo currently treats HDB as a structured storage target, but the README makes clear persistence is not yet a fully built production service; it is a local repository-level data layer.

4. **Point-in-time market state and curve abstraction**
   - `state/` is the **single as-of door** to history: it materializes point-in-time market state objects.
   - `curve/` sits above that and computes derived curve features, roll yield/slope/curvature, shock scenarios, and immutable snapshots.
   - These modules are the bridge from raw stored data to analyzable market state.

5. **Roll discipline and tradable continuous views**
   - `roll/` separates **as-of active contract logic** from **analytics-only continuous views**.
   - This is important for architecture because it prevents backtest/risk logic from confusing live contract selection with stitched continuous series used for analysis.

6. **Pricing and model core**
   - `models/` is the central quantitative engine: Black-Scholes/FDM, American/barrier/grid solvers, local vol, stochastic vol, jump diffusion, commodity models, payoffs, Greeks, and validation helpers.
   - The readme emphasizes that the equity finite-difference path is the correctness-validation case, while commodity and multi-asset models are the strategic target.
   - The public pricing API is exposed through `engine.q`, with solver behavior delegated to `grid`, `boundary`, `solver`, and `payoff`.

7. **Calibration subsystem**
   - `calibration/` handles implied vol, volatility surfaces, curve calibration, objective functions, Kalman-style two-factor estimation, model comparison, and reporting.
   - This layer consumes market state and model outputs, then produces calibrated parameters or diagnostics for use by pricing, risk, and research workflows.

8. **Risk, reporting, and analytics**
   - `analytics/` is the aggregation layer for scenario risk, VaR/ES, portfolio analytics, stress testing, limit checks, historical replay, and performance diagnostics.
   - It operates on pricing outputs and market-state snapshots, turning them into batch reports rather than single-trade numbers.

9. **Strategy simulation and execution**
   - `backtest/` contains the strategy engine, commodity strategy suite, walk-forward logic, and an event-driven replay engine.
   - `execution/` models daily fill-and-cost behavior, including slippage and participation/cost attribution.
   - The architectural boundary here is that backtest computes strategy behavior while execution adds market realism to fills and PnL.

10. **Evidence and research governance**
   - `evidence/` is a deterministic audit/verifier around replay runs, including a fail-safe gated-run mechanism.
   - `gov/` provides research governance: registry/ledger, deflated Sharpe, gate cascade, and verdict handling.
   - Together they enforce that research outputs are reproducible and admissible before being promoted.

11. **Domain-specific research layers**
   - `season/`, `carry/`, `signals/`, `regime/`, `factor/`, `attribution/`, and `portfolio/` are specialized analytical layers on top of the core platform.
   - `season` focuses on causal seasonality signals; `carry` models storage economics and convenience yield; `regime` builds market-state fingerprints and analogue libraries; `factor` decomposes curve structure; `attribution` explains PnL and curve risk; `portfolio` allocates strategies and compares walk-forward outcomes.
   - These are not duplicate pricing engines; they are higher-level decision and explanation layers built from pricing/state outputs.

12. **Templates, cards, and workflow orchestration**
   - `templates/` contains research-shape templates for repeatable study patterns.
   - `cards/` holds model cards as a knowledge/plugin layer tying together contract, edge cases, validation, and governance-derived audit info.
   - `workflow/` composes governance, cards, templates, and regime logic into a bounded research loop, including the replay-oriented path referenced in the README.

13. **Applications, scripts, and agents**
   - `apps/` contains standalone demos and worked examples, effectively serving as executable documentation for pricing, calibration, backtesting, and risk scenarios.
   - `scripts/` is reserved for ingestion/build tooling, and `services/` is explicitly reserved for future IPC/gateway/HDB-worker infrastructure.
   - `agents/` and `.claude/` are repository-local orchestration prompts and meta-workflow artifacts rather than runtime application code.

14. **Test architecture**
   - `tests/` is extensive and mirrors the subsystem structure: pricing, calibration, market data, regime, risk, backtest, strategy, workflow, etc.
   - The tests validate both numerical correctness and architectural contracts, especially around as-of behavior, model limits, replay determinism, and portfolio/risk aggregation.
   - In diagram terms, tests are a cross-cutting verification layer over the whole stack, not a separate subsystem.

15. **Primary end-to-end data flow**
   - The main flow is: ingest data → store in HDB → derive point-in-time state → build curves/roll views → price/calibrate models → generate Greeks/scenarios/risk → backtest or replay strategies → execute fills → attribute PnL → govern/audit results → package into workflow/cards/templates.
   - Commodity research is the clearest end-to-end use case, but the same structure supports equity option pricing and multi-asset extensions.

Main entry points: [`models/engine.q`](https://github.com/angusmit/qpricer/blob/main/models/engine.q) (Pricing API), [`state/state.q`](https://github.com/angusmit/qpricer/blob/main/state/state.q) (Market state), [`analytics`](https://github.com/angusmit/qpricer/tree/main/analytics) (Analytics), [`workflow/workflow.q`](https://github.com/angusmit/qpricer/blob/main/workflow/workflow.q) (Workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_core["Core platform"]
  node_node_core_init["Bootstrap<br/>[init.q]"]
  node_node_core_runtime["Runtime core<br/>shared primitives"]
  node_node_core_config["Config layer<br/>env config"]
end

subgraph group_group_market["Market data flow"]
  node_node_data_ingest[("Data ingest<br/>ingestion boundary")]
  node_node_state["Market state<br/>as-of state<br/>[state.q]"]
  node_node_curve["Curve engine<br/>derived curves<br/>[curve.q]"]
  node_node_roll["Roll views<br/>contract roll<br/>[roll.q]"]
end

subgraph group_group_pricing["Pricing engine"]
  node_node_models_engine["Pricing API<br/>pricing facade<br/>[engine.q]"]
  node_node_models_solvers["Solver stack<br/>fdm/solver"]
  node_node_models_families["Model families<br/>quant models"]
  node_node_calibration["Calibration<br/>surface/model fit<br/>[calibration.q]"]
end

subgraph group_group_risk["Risk and analytics"]
  node_node_analytics["Analytics<br/>risk/reporting"]
  node_node_attribution["Attribution<br/>pnl explain<br/>[attribution.q]"]
end

subgraph group_group_research["Research workflow"]
  node_node_backtest["Backtest<br/>strategy engine"]
  node_node_execution["Execution model<br/>fills/costs<br/>[execution.q]"]
  node_node_evidence["Evidence<br/>audit verifier<br/>[evidence.q]"]
  node_node_gov["Governance<br/>research gates<br/>[gov.q]"]
  node_node_cards["Model cards<br/>knowledge/plugin<br/>[cards.q]"]
  node_node_workflow["Workflow<br/>research loop<br/>[workflow.q]"]
end

subgraph group_group_domain["Domain layers"]
  node_node_season["Seasonality<br/>signal research<br/>[season.q]"]
  node_node_carry["Carry<br/>storage economics<br/>[carry.q]"]
  node_node_signals_regime_factor["Regime and factors<br/>analytical layer<br/>[regime.q]"]
end

subgraph group_group_ops["Ops and examples"]
  node_node_apps_scripts["Apps and scripts<br/>demos/tools"]
end

node_node_core_init -->|"loads"| node_node_core_runtime
node_node_core_init -->|"reads"| node_node_core_config
node_node_data_ingest -->|"feeds"| node_node_state
node_node_state -->|"drives"| node_node_curve
node_node_roll -->|"selects"| node_node_state
node_node_roll -->|"publishes"| node_node_curve
node_node_curve -->|"inputs"| node_node_models_engine
node_node_models_engine -->|"delegates"| node_node_models_solvers
node_node_models_engine -->|"prices"| node_node_models_families
node_node_models_families -->|"fit by"| node_node_calibration
node_node_state -->|"supplies"| node_node_calibration
node_node_models_engine -->|"reports"| node_node_analytics
node_node_analytics -->|"explains"| node_node_attribution
node_node_backtest -->|"costs"| node_node_execution
node_node_backtest -->|"audited by"| node_node_evidence
node_node_evidence -->|"gates"| node_node_gov
node_node_gov -->|"records"| node_node_cards
node_node_cards -->|"orchestrates"| node_node_workflow
node_node_workflow -->|"runs"| node_node_backtest
node_node_workflow -->|"verifies"| node_node_evidence
node_node_season -->|"composes"| node_node_signals_regime_factor
node_node_carry -->|"composes"| node_node_signals_regime_factor
node_node_data_ingest -->|"demoed by"| node_node_apps_scripts
node_node_models_engine -->|"demoed by"| node_node_apps_scripts
node_node_analytics -->|"demoed by"| node_node_apps_scripts

click node_node_core_init "https://github.com/angusmit/qpricer/blob/main/core/init.q"
click node_node_core_runtime "https://github.com/angusmit/qpricer/tree/main/core"
click node_node_core_config "https://github.com/angusmit/qpricer/tree/main/config"
click node_node_data_ingest "https://github.com/angusmit/qpricer/tree/main/data"
click node_node_state "https://github.com/angusmit/qpricer/blob/main/state/state.q"
click node_node_curve "https://github.com/angusmit/qpricer/blob/main/curve/curve.q"
click node_node_roll "https://github.com/angusmit/qpricer/blob/main/roll/roll.q"
click node_node_models_engine "https://github.com/angusmit/qpricer/blob/main/models/engine.q"
click node_node_models_solvers "https://github.com/angusmit/qpricer/tree/main/models"
click node_node_models_families "https://github.com/angusmit/qpricer/tree/main/models"
click node_node_calibration "https://github.com/angusmit/qpricer/blob/main/calibration/calibration.q"
click node_node_analytics "https://github.com/angusmit/qpricer/tree/main/analytics"
click node_node_attribution "https://github.com/angusmit/qpricer/blob/main/attribution/attribution.q"
click node_node_backtest "https://github.com/angusmit/qpricer/tree/main/backtest"
click node_node_execution "https://github.com/angusmit/qpricer/blob/main/execution/execution.q"
click node_node_evidence "https://github.com/angusmit/qpricer/blob/main/evidence/evidence.q"
click node_node_gov "https://github.com/angusmit/qpricer/blob/main/gov/gov.q"
click node_node_cards "https://github.com/angusmit/qpricer/blob/main/cards/cards.q"
click node_node_workflow "https://github.com/angusmit/qpricer/blob/main/workflow/workflow.q"
click node_node_season "https://github.com/angusmit/qpricer/blob/main/season/season.q"
click node_node_carry "https://github.com/angusmit/qpricer/blob/main/carry/carry.q"
click node_node_signals_regime_factor "https://github.com/angusmit/qpricer/blob/main/regime/regime.q"
click node_node_apps_scripts "https://github.com/angusmit/qpricer/tree/main/apps"

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_node_core_init,node_node_core_runtime,node_node_core_config,node_node_apps_scripts toneBlue
class node_node_data_ingest,node_node_state,node_node_curve,node_node_roll toneAmber
class node_node_models_engine,node_node_models_solvers,node_node_models_families,node_node_calibration toneMint
class node_node_analytics,node_node_attribution toneRose
class node_node_backtest,node_node_execution,node_node_evidence,node_node_gov,node_node_cards,node_node_workflow toneIndigo
class node_node_season,node_node_carry,node_node_signals_regime_factor toneTeal
```

## Components

### Core platform

Bootstrap, runtime support, config, and shared primitives.

- [Bootstrap](https://github.com/angusmit/qpricer/blob/main/core/init.q): q bootstrap · Repository entry point that initializes the runtime and loads the stack. · `core/init.q`
- [Runtime core](https://github.com/angusmit/qpricer/tree/main/core): shared primitives · Low-level math, RNG, stats, timing, cache, utilities, and conformance registry spine. · `core`
- [Config layer](https://github.com/angusmit/qpricer/tree/main/config): env config · Base and dev value files plus configuration loading helpers. · `config`

### Market data flow

Ingestion, point-in-time state, roll discipline, and derived curve views.

- [Data ingest](https://github.com/angusmit/qpricer/tree/main/data): ingestion boundary · Parsers and helpers for futures, backtest, and commodity data with HDB-facing layout. · `data`
- [Market state](https://github.com/angusmit/qpricer/blob/main/state/state.q): as-of state · Point-in-time accessor and history materialization boundary. · `state/state.q`
- [Curve engine](https://github.com/angusmit/qpricer/blob/main/curve/curve.q): derived curves · Roll yield, slope, curvature, shock scenarios, and immutable curve snapshots. · `curve/curve.q`
- [Roll views](https://github.com/angusmit/qpricer/blob/main/roll/roll.q): contract roll · Active contract logic and analytics-only continuous series for stitched views. · `roll/roll.q`

### Pricing engine

Model families, solver stack, and calibration layer.

- [Pricing API](https://github.com/angusmit/qpricer/blob/main/models/engine.q): pricing facade · Public pricing entry point that dispatches to model and solver components. · `models/engine.q`
- [Solver stack](https://github.com/angusmit/qpricer/tree/main/models): fdm/solver · Grid, boundary, solver, payoff, and validation components for numerical pricing. · `models`
- [Model families](https://github.com/angusmit/qpricer/tree/main/models): quant models · Black-Scholes, American, barrier, local vol, stochastic vol, jump diffusion, commodity, and basket models. · `models`
- [Calibration](https://github.com/angusmit/qpricer/blob/main/calibration/calibration.q): surface/model fit · Implied vol, surface fitting, objective functions, model comparison, and reporting. · `calibration/calibration.q`

### Risk and analytics

Scenario, risk, attribution, reporting, and portfolio analytics.

- [Analytics](https://github.com/angusmit/qpricer/tree/main/analytics): risk/reporting · Scenario risk, VaR/ES, stress, replay, limits, PnL, and batch report aggregation. · `analytics`
- [Attribution](https://github.com/angusmit/qpricer/blob/main/attribution/attribution.q): pnl explain · PnL explanation and decomposition layer. · `attribution/attribution.q`

### Research workflow

Backtesting, governance, evidence, templates, and cards.

- [Backtest](https://github.com/angusmit/qpricer/tree/main/backtest): strategy engine · Strategy simulation, commodity strategy suite, and walk-forward replay logic. · `backtest`
- [Execution model](https://github.com/angusmit/qpricer/blob/main/execution/execution.q): fills/costs · Daily fill, slippage, participation, and cost attribution realism layer. · `execution/execution.q`
- [Evidence](https://github.com/angusmit/qpricer/blob/main/evidence/evidence.q): audit verifier · Deterministic replay audit and gated-run verification. · `evidence/evidence.q`
- [Governance](https://github.com/angusmit/qpricer/blob/main/gov/gov.q): research gates · Registry, ledger, deflated Sharpe, gate cascade, and verdict handling. · `gov/gov.q`
- [Model cards](https://github.com/angusmit/qpricer/blob/main/cards/cards.q): knowledge/plugin · Contract, validation, edge-case, and audit metadata for models and research artifacts. · `cards/cards.q`
- [Workflow](https://github.com/angusmit/qpricer/blob/main/workflow/workflow.q): research loop · Bounded research loop composing governance, cards, templates, and replay-oriented paths. · `workflow/workflow.q`

### Domain layers

Specialized strategy and signal layers for commodity and regime research.

- [Seasonality](https://github.com/angusmit/qpricer/blob/main/season/season.q): signal research · Causal seasonality research and overlays. · `season/season.q`
- [Carry](https://github.com/angusmit/qpricer/blob/main/carry/carry.q): storage economics · Convenience yield and carry modeling for commodities. · `carry/carry.q`
- [Regime and factors](https://github.com/angusmit/qpricer/blob/main/regime/regime.q): analytical layer · Regime fingerprints, analogues, factor decomposition, signals, portfolio construction, and strategy attribution helpers. · `regime/regime.q`

### Ops and examples

Executable demos, build scripts, and orchestration artifacts.

- [Apps and scripts](https://github.com/angusmit/qpricer/tree/main/apps): demos/tools · Standalone examples, build scripts, and repository tooling for ingestion, cards, and regime library generation. · `apps`

## Connections

- Bootstrap → Runtime core: loads · Bootstrap initializes the shared runtime and registry spine.
- Bootstrap → Config layer: reads · Bootstrap pulls environment-specific configuration.
- Data ingest → Market state: feeds · Ingested data is materialized into point-in-time market state.
- Market state → Curve engine: drives · Market state is transformed into derived curve features and snapshots.
- Roll views → Market state: selects · Roll logic depends on as-of state for active contract selection.
- Roll views → Curve engine: publishes · Continuous views are used by analytics and research layers.
- Curve engine → Pricing API: inputs · Curves and shocks feed pricing requests.
- Pricing API → Solver stack: delegates · Pricing facade delegates numerical work to grid/solver components.
- Pricing API → Model families: prices · The engine exposes the model families to consumers.
- Model families → Calibration: fit by · Model outputs are calibrated against market surfaces and objectives.
- Market state → Calibration: supplies · Calibration consumes market-state and curve observations.
- Pricing API → Analytics: reports · Pricing outputs are turned into scenario and risk analytics.
- Analytics → Attribution: explains · Analytics feed PnL attribution and decomposition.
- Backtest → Execution model: costs · Backtests use execution realism for fills and transaction costs.
- Backtest → Evidence: audited by · Replay and strategy runs are verified for determinism.
- Evidence → Governance: gates · Audited runs are evaluated by governance rules.
- Governance → Model cards: records · Governance results are captured in model cards and registry artifacts.
- Model cards → Workflow: orchestrates · Cards participate in the bounded research workflow.
- Workflow → Backtest: runs · Workflow triggers replay and backtest studies.
- Workflow → Evidence: verifies · Workflow includes deterministic evidence checks.
- Seasonality → Regime and factors: composes · Seasonality is one of the higher-level research signal layers.
- Carry → Regime and factors: composes · Carry joins the broader research and factor layer.
- Data ingest → Apps and scripts: demoed by · Examples and scripts exercise ingestion and build workflows.
- Pricing API → Apps and scripts: demoed by · Examples provide executable documentation for pricing.
- Analytics → Apps and scripts: demoed by · Examples cover risk, replay, and reporting workflows.
