How angusmit/qpricer works
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: engine.q Pricing API · state.q Market state · analytics Analytics · workflow.q Workflow
Components 23
Core platform
Bootstrap, runtime support, config, and shared primitives.
- Bootstrap · Repository entry point that initializes the runtime and loads the stack.
core/init.q - Runtime core · Low-level math, RNG, stats, timing, cache, utilities, and conformance registry spine.
core - Config layer · 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 · Parsers and helpers for futures, backtest, and commodity data with HDB-facing layout.
data - Market state · Point-in-time accessor and history materialization boundary.
state/state.q - Curve engine · Roll yield, slope, curvature, shock scenarios, and immutable curve snapshots.
curve/curve.q - Roll views · 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 · Public pricing entry point that dispatches to model and solver components.
models/engine.q - Solver stack · Grid, boundary, solver, payoff, and validation components for numerical pricing.
models - Model families · Black-Scholes, American, barrier, local vol, stochastic vol, jump diffusion, commodity, and basket models.
models - Calibration · Implied vol, surface fitting, objective functions, model comparison, and reporting.
calibration/calibration.q
Risk and analytics
Scenario, risk, attribution, reporting, and portfolio analytics.
- Analytics · Scenario risk, VaR/ES, stress, replay, limits, PnL, and batch report aggregation.
analytics - Attribution · PnL explanation and decomposition layer.
attribution/attribution.q
Research workflow
Backtesting, governance, evidence, templates, and cards.
- Backtest · Strategy simulation, commodity strategy suite, and walk-forward replay logic.
backtest - Execution model · Daily fill, slippage, participation, and cost attribution realism layer.
execution/execution.q - Evidence · Deterministic replay audit and gated-run verification.
evidence/evidence.q - Governance · Registry, ledger, deflated Sharpe, gate cascade, and verdict handling.
gov/gov.q - Model cards · Contract, validation, edge-case, and audit metadata for models and research artifacts.
cards/cards.q - Workflow · 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 · Causal seasonality research and overlays.
season/season.q - Carry · Convenience yield and carry modeling for commodities.
carry/carry.q - Regime and factors · 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 · Standalone examples, build scripts, and repository tooling for ingestion, cards, and regime library generation.
apps
Connections 25
- 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.