Config-driven risk engine for trading systems
Project description
PyFortis
Config-driven risk engine for trading systems.
PyFortis lets you define limits, metrics, and circuit breakers in YAML, then validate orders and run risk checks through a simple Python API. It supports stateless validation, stateful monitors, and a full orchestrator with pluggable stores and handlers.
Install
pip install pyfortis
Optional extras (install what you need):
pip install pyfortis[metrics] # NumPy/SciPy for VaR, drawdown, etc.
pip install pyfortis[validation] # Pydantic for schema validation
pip install pyfortis[full] # All optional dependencies
| Extra | Purpose |
|---|---|
validation |
Pydantic-based config validation |
db |
SQLAlchemy + Alembic |
api |
FastAPI + Uvicorn |
kafka |
Confluent Kafka |
metrics |
NumPy/SciPy for risk metrics |
redis |
Redis client |
full |
All of the above |
Quick start
Load an engine from a YAML config, then validate orders:
from pathlib import Path
from pyfortis import Order, RiskEngine, Side
engine = RiskEngine.from_yaml(Path("risk_config.yaml"))
order = Order(
order_id="o-001",
instrument="AAPL",
side=Side.BUY,
quantity=100,
price=150.0,
portfolio="default",
)
result = engine.validate_order(order)
print(result.verdict.value, result.message)
See examples/basic_usage.py and examples/risk_config.yaml for a full walkthrough.
Concepts
- Limits — Pre-trade checks (position size, concentration, price tolerance, notional, etc.) with configurable severity (INFO, WARNING, CRITICAL, KILL).
- Metrics — Post-trade or periodic risk metrics (VaR, CVaR, drawdown, volatility, etc.) with optional breach thresholds.
- Circuit breakers — Halt trading when conditions are met (e.g. daily PnL loss, drawdown).
- Three layers:
- Engine — Stateless: load config, validate single orders without position context.
- Monitor — Stateful: hold positions in memory, validate orders and check circuit breakers.
- Orchestrator — Persistent: load/save positions and breaches via stores, run metrics, dispatch handlers (log, notify, block, etc.).
Config supports env-var substitution (e.g. ${VAR} or ${VAR:-default}) and a breach escalation policy per severity.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyfortis-0.0.1.tar.gz.
File metadata
- Download URL: pyfortis-0.0.1.tar.gz
- Upload date:
- Size: 36.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b10367702b3653aceaa11a12951d702213a39adbe1c4c20f6a01d86dc61ab8e2
|
|
| MD5 |
e8feaf262072559318b430b4353ef03f
|
|
| BLAKE2b-256 |
f822208f31e356a55a89f641366f8d237e6bba848271f06e357528ee17988f68
|
File details
Details for the file pyfortis-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pyfortis-0.0.1-py3-none-any.whl
- Upload date:
- Size: 30.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bc72b9f21bdd07a92b8110bbd4a91ea1720e44906bcb80cd160c095a64c0f4a
|
|
| MD5 |
65819d09bdb6fc9995f60e34f79313c0
|
|
| BLAKE2b-256 |
894466824a468dbaf20a4b4f9424be38ca7fd237cb57bfd18943bac752c85135
|