nex-fin 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nex_fin-0.1.0/.github/workflows/ci.yml +35 -0
- nex_fin-0.1.0/.github/workflows/release.yml +107 -0
- nex_fin-0.1.0/.gitignore +12 -0
- nex_fin-0.1.0/LICENSE +41 -0
- nex_fin-0.1.0/PKG-INFO +242 -0
- nex_fin-0.1.0/README.md +213 -0
- nex_fin-0.1.0/_nex_build.sh +830 -0
- nex_fin-0.1.0/nex_fin.py +21 -0
- nex_fin-0.1.0/nex_fin_components/__init__.py +43 -0
- nex_fin-0.1.0/nex_fin_components/cli.py +14 -0
- nex_fin-0.1.0/nex_fin_components/convention_guard.py +110 -0
- nex_fin-0.1.0/nex_fin_components/feed_ingress.py +121 -0
- nex_fin-0.1.0/nex_fin_components/models.py +90 -0
- nex_fin-0.1.0/pyproject.toml +45 -0
- nex_fin-0.1.0/tests/__init__.py +1 -0
- nex_fin-0.1.0/tests/test_nex_fin.py +102 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: ci
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test-matrix:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
fail-fast: false
|
|
13
|
+
matrix:
|
|
14
|
+
profile:
|
|
15
|
+
- name: minimal-core
|
|
16
|
+
extras: ".[dev]"
|
|
17
|
+
expect_full: "0"
|
|
18
|
+
- name: full-suite
|
|
19
|
+
extras: ".[full,dev]"
|
|
20
|
+
expect_full: "1"
|
|
21
|
+
|
|
22
|
+
steps:
|
|
23
|
+
- uses: actions/checkout@v4
|
|
24
|
+
- uses: astral-sh/setup-uv@v5
|
|
25
|
+
- uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.12"
|
|
28
|
+
|
|
29
|
+
- name: Install ${{ matrix.profile.name }}
|
|
30
|
+
run: uv pip install --system -e "${{ matrix.profile.extras }}"
|
|
31
|
+
|
|
32
|
+
- name: Run Verification Suite
|
|
33
|
+
env:
|
|
34
|
+
NEX_FIN_EXPECT_FULL: ${{ matrix.profile.expect_full }}
|
|
35
|
+
run: pytest -v tests/
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
name: Release & Distribute nex-fin
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: write
|
|
11
|
+
id-token: write # MANDATORY FOR OIDC TOKENLESS EXCHANGE (PEP 740)
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
test-and-audit:
|
|
15
|
+
name: Verification Audit (${{ matrix.profile }} / ${{ matrix.python-version }} on ${{ matrix.os }})
|
|
16
|
+
runs-on: ${{ matrix.os }}
|
|
17
|
+
timeout-minutes: 10
|
|
18
|
+
strategy:
|
|
19
|
+
fail-fast: false
|
|
20
|
+
matrix:
|
|
21
|
+
os: [ubuntu-latest]
|
|
22
|
+
python-version: ["3.11", "3.12"]
|
|
23
|
+
profile: [".[dev]", ".[full,dev]"]
|
|
24
|
+
steps:
|
|
25
|
+
- name: Checkout Code
|
|
26
|
+
uses: actions/checkout@v6
|
|
27
|
+
|
|
28
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
29
|
+
uses: actions/setup-python@v6
|
|
30
|
+
with:
|
|
31
|
+
python-version: ${{ matrix.python-version }}
|
|
32
|
+
|
|
33
|
+
- name: Install uv
|
|
34
|
+
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
35
|
+
|
|
36
|
+
- name: Install package and test dependencies
|
|
37
|
+
run: uv pip install --system -e "${{ matrix.profile }}"
|
|
38
|
+
|
|
39
|
+
- name: Run 8/8 Test Suite
|
|
40
|
+
env:
|
|
41
|
+
NEX_FIN_EXPECT_FULL: ${{ matrix.profile == '.[full,dev]' && '1' || '0' }}
|
|
42
|
+
run: pytest -v tests/
|
|
43
|
+
|
|
44
|
+
macos-smoke:
|
|
45
|
+
name: macOS Smoke Audit (3.12 on macos-latest)
|
|
46
|
+
runs-on: macos-latest
|
|
47
|
+
timeout-minutes: 10
|
|
48
|
+
steps:
|
|
49
|
+
- name: Checkout Code
|
|
50
|
+
uses: actions/checkout@v6
|
|
51
|
+
|
|
52
|
+
- name: Set up Python 3.12
|
|
53
|
+
uses: actions/setup-python@v6
|
|
54
|
+
with:
|
|
55
|
+
python-version: "3.12"
|
|
56
|
+
|
|
57
|
+
- name: Install uv
|
|
58
|
+
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
59
|
+
|
|
60
|
+
- name: Install package and run 8/8 Test Suite
|
|
61
|
+
env:
|
|
62
|
+
NEX_FIN_EXPECT_FULL: "1"
|
|
63
|
+
run: |
|
|
64
|
+
uv pip install --system -e ".[full,dev]"
|
|
65
|
+
pytest -v tests/
|
|
66
|
+
|
|
67
|
+
build-and-publish:
|
|
68
|
+
name: Build Wheel & Publish to PyPI
|
|
69
|
+
needs: [test-and-audit, macos-smoke]
|
|
70
|
+
runs-on: ubuntu-latest
|
|
71
|
+
timeout-minutes: 10
|
|
72
|
+
environment:
|
|
73
|
+
name: pypi
|
|
74
|
+
url: https://pypi.org/p/nex-fin
|
|
75
|
+
steps:
|
|
76
|
+
- name: Checkout Code
|
|
77
|
+
uses: actions/checkout@v6
|
|
78
|
+
with:
|
|
79
|
+
fetch-depth: 0
|
|
80
|
+
|
|
81
|
+
- name: Set up Python 3.12
|
|
82
|
+
uses: actions/setup-python@v6
|
|
83
|
+
with:
|
|
84
|
+
python-version: "3.12"
|
|
85
|
+
|
|
86
|
+
- name: Install uv
|
|
87
|
+
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
88
|
+
|
|
89
|
+
- name: Build Source and Universal Wheel
|
|
90
|
+
run: uv build --out-dir dist/
|
|
91
|
+
|
|
92
|
+
- name: Audit Metadata Rendering
|
|
93
|
+
run: uvx twine check --strict dist/*
|
|
94
|
+
|
|
95
|
+
- name: Publish to PyPI (PEP 740 OIDC Trusted Publishing)
|
|
96
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
97
|
+
with:
|
|
98
|
+
packages-dir: dist/
|
|
99
|
+
attestations: true
|
|
100
|
+
|
|
101
|
+
- name: Create GitHub Release
|
|
102
|
+
uses: softprops/action-gh-release@v2
|
|
103
|
+
with:
|
|
104
|
+
files: dist/*
|
|
105
|
+
generate_release_notes: true
|
|
106
|
+
env:
|
|
107
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
nex_fin-0.1.0/.gitignore
ADDED
nex_fin-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Dual-Licensed under the MIT License or the Apache License, Version 2.0.
|
|
2
|
+
|
|
3
|
+
================================================================================
|
|
4
|
+
MIT License
|
|
5
|
+
================================================================================
|
|
6
|
+
Copyright (c) 2026 The Trinity (Mookie, Miniature Person, Nexus Goodman)
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
|
25
|
+
|
|
26
|
+
================================================================================
|
|
27
|
+
Apache License, Version 2.0
|
|
28
|
+
================================================================================
|
|
29
|
+
Copyright 2026 The Trinity (Mookie, Miniature Person, Nexus Goodman)
|
|
30
|
+
|
|
31
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
32
|
+
you may not use this file except in compliance with the License.
|
|
33
|
+
You may obtain a copy of the License at
|
|
34
|
+
|
|
35
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
36
|
+
|
|
37
|
+
Unless required by applicable law or agreed to in writing, software
|
|
38
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
39
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
40
|
+
See the License for the specific language governing permissions and
|
|
41
|
+
limitations under the License.
|
nex_fin-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: nex-fin
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Credential-Isolated Financial Data Ingress, Point-in-Time Causal Gate & Convention Armor for Autonomous AI Agents.
|
|
5
|
+
Author-email: The Trinity <inquiries@houseoflawpc.com>
|
|
6
|
+
License: MIT OR Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: ai-agents,duckdb,finance,pit,pyarrow,quant,rcti,smt
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Requires-Dist: pydantic>=2.10.0
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
|
|
19
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
20
|
+
Provides-Extra: full
|
|
21
|
+
Requires-Dist: curl-cffi>=0.7.0; extra == 'full'
|
|
22
|
+
Requires-Dist: duckdb>=2.0.0; extra == 'full'
|
|
23
|
+
Requires-Dist: nex-airgap>=0.2.0; extra == 'full'
|
|
24
|
+
Requires-Dist: nex-avail>=0.2.0; extra == 'full'
|
|
25
|
+
Requires-Dist: nex-heal>=0.2.0; extra == 'full'
|
|
26
|
+
Requires-Dist: nex-init>=0.2.0; extra == 'full'
|
|
27
|
+
Requires-Dist: pyarrow>=18.0.0; extra == 'full'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# nex-fin ⚡
|
|
31
|
+
|
|
32
|
+
**Credential-Isolated Financial Data Ingress, Point-in-Time (PIT) Causal Gate & Convention Armor for Autonomous AI Agents.**
|
|
33
|
+
|
|
34
|
+

|
|
35
|
+

|
|
36
|
+

|
|
37
|
+

|
|
38
|
+

|
|
39
|
+

|
|
40
|
+
|
|
41
|
+
`nex-fin` bridges the gap between raw PyPI quantitative libraries (`QuantLib`, `scipy`, `duckdb`, `polars`) and institutional-grade autonomous financial execution.
|
|
42
|
+
|
|
43
|
+
Designed to snap directly onto **`nex-airgap`**, **`nex-heal`**, and **`nex-avail`**, `nex-fin` eliminates silent financial calculation corruption, lookahead bias, and API credential leakage before a single model turn executes.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## I. The Mechanical Reality: Why Naive Financial Agents Fail Silently
|
|
48
|
+
|
|
49
|
+
Giving an LLM access to `pandas` or `QuantLib` solves only the math. In production quantitative and corporate finance workflows, four systemic failure modes silently corrupt outputs:
|
|
50
|
+
|
|
51
|
+
1. **Silent Day-Count & Basis Drift:**
|
|
52
|
+
Models routinely mix `ACT/360`, `ACT/365F`, and `30/360` accruals, or combine clean and dirty bond prices / split-adjusted and unadjusted equity series without declaring the convention.
|
|
53
|
+
2. **Lookahead Bias (Point-in-Time Contamination):**
|
|
54
|
+
Backtests and fundamental joins routinely pull `Q4 10-K` filings (`knowledge_ts = Feb 28`) into trades dated `Jan 15`, producing artificially inflated alpha that collapses in live markets.
|
|
55
|
+
3. **Currency & Scale Mismatches:**
|
|
56
|
+
Adding `USD` to `EUR` without an FX rate, or mixing `CENTS` (`4500`) with `UNITS` (`45.00`) or `MILLIONS`, produces plausible-looking numbers that are orders of magnitude wrong.
|
|
57
|
+
4. **Credential Leakage & Context Window Bloat:**
|
|
58
|
+
Passing raw vendor JSON responses or `POLYGON_API_KEY` / `SEC_EDGAR_USER_AGENT` headers through agent prompts burns hundreds of thousands of tokens and exposes secrets to prompt injection.
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## II. Architectural Topology
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
NEX-FIN FINANCIAL ARMOR
|
|
66
|
+
┌───────────────────────────────────────────────────────────────────┐
|
|
67
|
+
│ 1. DPv2-IS STRICT CONVENTION CONTRACT (models.py) │
|
|
68
|
+
│ - Zero-default FinancialConventionSpec (strict: true) │
|
|
69
|
+
│ - Forces explicit DayCount, PriceBasis, ISO4217Currency, Scale│
|
|
70
|
+
└─────────────────────────────────┬─────────────────────────────────┘
|
|
71
|
+
│
|
|
72
|
+
▼
|
|
73
|
+
┌───────────────────────────────────────────────────────────────────┐
|
|
74
|
+
│ 2. CREDENTIAL-ISOLATED FEED INGRESS (feed_ingress.py) │
|
|
75
|
+
│ - Env-gated discovery (SEC EDGAR, Polygon, Local Parquet/JSON)│
|
|
76
|
+
│ - Public HTTPS SSRF guard (blocks private/loopback/link-local)│
|
|
77
|
+
│ - Writes directly to AirgapVFS -> returns SHA-256 Receipt │
|
|
78
|
+
└─────────────────────────────────┬─────────────────────────────────┘
|
|
79
|
+
│
|
|
80
|
+
▼
|
|
81
|
+
┌───────────────────────────────────────────────────────────────────┐
|
|
82
|
+
│ 3. CONVENTION & CAUSAL ARMOR (convention_guard.py) │
|
|
83
|
+
│ - DuckDB 2.0 PIT Gate: halts on knowledge_ts > as_of_ts │
|
|
84
|
+
│ - Currency/Scale Homogeneity: UNSAT halt without valid FX │
|
|
85
|
+
│ - Deterministic year_fraction (ACT/360, ACT/365F, 30/360, ISDA│
|
|
86
|
+
└───────────────────────────────────────────────────────────────────┘
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## III. Core Pillars & Mechanical Guarantees
|
|
92
|
+
|
|
93
|
+
| Pillar | Mechanism | Mechanical Guarantee |
|
|
94
|
+
| :--- | :--- | :--- |
|
|
95
|
+
| **1. Zero-Default Convention Contracts** | `DPv2-IS` `FinancialConventionSpec` | Forces LLMs under OpenAI `strict: true` to explicitly declare `day_count`, `price_basis`, `currency`, and `scale` on every call. |
|
|
96
|
+
| **2. Point-in-Time Causal Gate** | `assert_pit_causal_order()` (DuckDB 2.0) | Audits every record's `knowledge_ts <= as_of_ts` in-memory via DuckDB 2.0; raises `LOOKAHEAD_VIOLATION` on any future leak. |
|
|
97
|
+
| **3. Currency & Scale Homogeneity** | `reconcile_currency_scale()` | Halts cross-currency operations (`UNSAT_CURRENCY_MISMATCH`) unless a positive `fx_rate` is supplied; enforces exact scale multipliers (`CENTS` $\leftrightarrow$ `UNITS` $\leftrightarrow$ `MILLIONS`). |
|
|
98
|
+
| **4. Credential-Isolated Ingress** | `fetch_financial_feed()` + SSRF Guard | Reads API keys strictly from OS env, blocks non-public IPs, streams into `AirgapVFS`, and returns only a `FeedIngressReceipt` (zero raw payload tokens). |
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## IV. Quickstart & Programmatic Python SDK
|
|
103
|
+
|
|
104
|
+
### Installation
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Minimal core (zero-default schemas, day-count, currency/scale, pure-Python PIT gate)
|
|
108
|
+
uv pip install nex-fin
|
|
109
|
+
|
|
110
|
+
# Full Trinity + DuckDB 2.0 + PyArrow + curl_cffi acceleration
|
|
111
|
+
uv pip install "nex-fin[full]"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 1. Point-in-Time (PIT) Lookahead Gate
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from nex_fin import assert_pit_causal_order
|
|
118
|
+
|
|
119
|
+
rows = [
|
|
120
|
+
{"symbol": "NVDA", "revenue": 22_100_000_000, "knowledge_ts": "2026-01-10T16:00:00Z"},
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
# Passes cleanly: knowledge_ts <= as_of_iso
|
|
124
|
+
receipt = assert_pit_causal_order(rows, as_of_iso="2026-01-15T00:00:00Z")
|
|
125
|
+
print(receipt.status) # -> "PASS"
|
|
126
|
+
|
|
127
|
+
# Halts immediately with ValueError("LOOKAHEAD_VIOLATION: ...") if any row > as_of_iso
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 2. Currency & Scale Reconciliation
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
from nex_fin import ISO4217Currency, ScaleFactor, reconcile_currency_scale
|
|
134
|
+
|
|
135
|
+
# Normalize 4,500 cents -> 45.0 USD units
|
|
136
|
+
res = reconcile_currency_scale(
|
|
137
|
+
value=4500.0,
|
|
138
|
+
src_currency=ISO4217Currency.USD,
|
|
139
|
+
src_scale=ScaleFactor.CENTS,
|
|
140
|
+
dst_currency=ISO4217Currency.USD,
|
|
141
|
+
dst_scale=ScaleFactor.UNITS,
|
|
142
|
+
)
|
|
143
|
+
print(res.converted_value) # -> 45.0
|
|
144
|
+
|
|
145
|
+
# Cross-currency without fx_rate raises ValueError("UNSAT_CURRENCY_MISMATCH: ...")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### 3. Day-Count Accruals
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from datetime import date
|
|
152
|
+
from nex_fin import DayCountConvention, year_fraction
|
|
153
|
+
|
|
154
|
+
yf = year_fraction(date(2026, 1, 1), date(2026, 7, 1), DayCountConvention.ACT_360)
|
|
155
|
+
print(round(yf, 6)) # -> 0.502778
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 4. Credential-Isolated Feed Ingress into `AirgapVFS`
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from nex_airgap import AirgapVFS
|
|
162
|
+
from nex_fin import FeedProvider, fetch_financial_feed
|
|
163
|
+
|
|
164
|
+
vfs = AirgapVFS()
|
|
165
|
+
|
|
166
|
+
# Reads POLYGON_API_KEY from environment; LLM never sees the key or raw JSON
|
|
167
|
+
receipt = fetch_financial_feed(
|
|
168
|
+
provider=FeedProvider.POLYGON,
|
|
169
|
+
symbol="NVDA",
|
|
170
|
+
params={"start_date": "2026-01-01", "end_date": "2026-01-15"},
|
|
171
|
+
vfs=vfs,
|
|
172
|
+
)
|
|
173
|
+
print(receipt.status, receipt.sha256_digest, receipt.rows_ingested)
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 5. Project into `nex_hop` via `nex-avail`
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
import nex_avail
|
|
180
|
+
|
|
181
|
+
registry = nex_avail.project(
|
|
182
|
+
"nex_fin",
|
|
183
|
+
include=["year_fraction", "reconcile_currency_scale", "assert_pit_causal_order", "fetch_financial_feed"],
|
|
184
|
+
)
|
|
185
|
+
openai_tools = registry.to_openai_specs()
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## V. CLI Reference
|
|
191
|
+
|
|
192
|
+
Inspect configured data feed providers without exposing secret values:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
nex-fin providers
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## VI. Repository Topology (RCTI v3.0)
|
|
201
|
+
|
|
202
|
+
Adheres strictly to the $\le 150\text{ LOC}$ orchestrator ceiling and Recursive Component-Tree Isolation (`RCTI v3.0`):
|
|
203
|
+
|
|
204
|
+
```text
|
|
205
|
+
nex_fin/
|
|
206
|
+
├── pyproject.toml # PEP 621 metadata & core/full optional extras
|
|
207
|
+
├── LICENSE # Dual MIT OR Apache-2.0
|
|
208
|
+
├── README.md # Architecture & usage specification
|
|
209
|
+
├── nex_fin.py # Pure orchestrator shell (<= 150 LOC)
|
|
210
|
+
├── nex_fin_components/
|
|
211
|
+
│ ├── __init__.py # Dynamic RCTI v3.0 router (nex-init + fallback)
|
|
212
|
+
│ ├── models.py # DPv2-IS strict financial schemas
|
|
213
|
+
│ ├── convention_guard.py # PIT causal gate, DayCount, Currency/Scale armor
|
|
214
|
+
│ ├── feed_ingress.py # SSRF-guarded, credential-isolated feed adapters
|
|
215
|
+
│ └── cli.py # Standalone CLI entrypoint
|
|
216
|
+
├── .github/workflows/
|
|
217
|
+
│ ├── ci.yml # Dual-matrix CI (minimal-core vs full-suite)
|
|
218
|
+
│ └── release.yml # Tokenless PEP 740 OIDC Trusted Publishing
|
|
219
|
+
└── tests/
|
|
220
|
+
├── __init__.py
|
|
221
|
+
└── test_nex_fin.py # Acceptance suite
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## VII. Attribution & The Trinity Pact
|
|
227
|
+
|
|
228
|
+
`nex-fin` is engineered under the **Permanexus Pact**:
|
|
229
|
+
- **No Fluff. No Drift. No Metaphors.**
|
|
230
|
+
- **Strict adherence to the $\le 150\text{ LOC}$ orchestrator ceiling and RCTI v3.0.**
|
|
231
|
+
- **Zero tolerance for silent convention drift or credential leakage.**
|
|
232
|
+
|
|
233
|
+
**Engineered by The Trinity:**
|
|
234
|
+
- **Miniature Person** (🌱 👑 ⁂) — *Architect & Creator*
|
|
235
|
+
- **Mookie** (🦍 🔷 Ɯ) — *Director of Design & Execution Core*
|
|
236
|
+
- **Nexus Goodman** (🧠 ⚡ ↇ) — *Principal Systems Architect*
|
|
237
|
+
|
|
238
|
+
**Commercial Inquiries & Enterprise Support:** `inquiries@houseoflawpc.com`
|
|
239
|
+
|
|
240
|
+
**License:** Dual-licensed under MIT OR Apache-2.0.
|
|
241
|
+
|
|
242
|
+
|
nex_fin-0.1.0/README.md
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# nex-fin ⚡
|
|
2
|
+
|
|
3
|
+
**Credential-Isolated Financial Data Ingress, Point-in-Time (PIT) Causal Gate & Convention Armor for Autonomous AI Agents.**
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
`nex-fin` bridges the gap between raw PyPI quantitative libraries (`QuantLib`, `scipy`, `duckdb`, `polars`) and institutional-grade autonomous financial execution.
|
|
13
|
+
|
|
14
|
+
Designed to snap directly onto **`nex-airgap`**, **`nex-heal`**, and **`nex-avail`**, `nex-fin` eliminates silent financial calculation corruption, lookahead bias, and API credential leakage before a single model turn executes.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## I. The Mechanical Reality: Why Naive Financial Agents Fail Silently
|
|
19
|
+
|
|
20
|
+
Giving an LLM access to `pandas` or `QuantLib` solves only the math. In production quantitative and corporate finance workflows, four systemic failure modes silently corrupt outputs:
|
|
21
|
+
|
|
22
|
+
1. **Silent Day-Count & Basis Drift:**
|
|
23
|
+
Models routinely mix `ACT/360`, `ACT/365F`, and `30/360` accruals, or combine clean and dirty bond prices / split-adjusted and unadjusted equity series without declaring the convention.
|
|
24
|
+
2. **Lookahead Bias (Point-in-Time Contamination):**
|
|
25
|
+
Backtests and fundamental joins routinely pull `Q4 10-K` filings (`knowledge_ts = Feb 28`) into trades dated `Jan 15`, producing artificially inflated alpha that collapses in live markets.
|
|
26
|
+
3. **Currency & Scale Mismatches:**
|
|
27
|
+
Adding `USD` to `EUR` without an FX rate, or mixing `CENTS` (`4500`) with `UNITS` (`45.00`) or `MILLIONS`, produces plausible-looking numbers that are orders of magnitude wrong.
|
|
28
|
+
4. **Credential Leakage & Context Window Bloat:**
|
|
29
|
+
Passing raw vendor JSON responses or `POLYGON_API_KEY` / `SEC_EDGAR_USER_AGENT` headers through agent prompts burns hundreds of thousands of tokens and exposes secrets to prompt injection.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## II. Architectural Topology
|
|
34
|
+
|
|
35
|
+
```text
|
|
36
|
+
NEX-FIN FINANCIAL ARMOR
|
|
37
|
+
┌───────────────────────────────────────────────────────────────────┐
|
|
38
|
+
│ 1. DPv2-IS STRICT CONVENTION CONTRACT (models.py) │
|
|
39
|
+
│ - Zero-default FinancialConventionSpec (strict: true) │
|
|
40
|
+
│ - Forces explicit DayCount, PriceBasis, ISO4217Currency, Scale│
|
|
41
|
+
└─────────────────────────────────┬─────────────────────────────────┘
|
|
42
|
+
│
|
|
43
|
+
▼
|
|
44
|
+
┌───────────────────────────────────────────────────────────────────┐
|
|
45
|
+
│ 2. CREDENTIAL-ISOLATED FEED INGRESS (feed_ingress.py) │
|
|
46
|
+
│ - Env-gated discovery (SEC EDGAR, Polygon, Local Parquet/JSON)│
|
|
47
|
+
│ - Public HTTPS SSRF guard (blocks private/loopback/link-local)│
|
|
48
|
+
│ - Writes directly to AirgapVFS -> returns SHA-256 Receipt │
|
|
49
|
+
└─────────────────────────────────┬─────────────────────────────────┘
|
|
50
|
+
│
|
|
51
|
+
▼
|
|
52
|
+
┌───────────────────────────────────────────────────────────────────┐
|
|
53
|
+
│ 3. CONVENTION & CAUSAL ARMOR (convention_guard.py) │
|
|
54
|
+
│ - DuckDB 2.0 PIT Gate: halts on knowledge_ts > as_of_ts │
|
|
55
|
+
│ - Currency/Scale Homogeneity: UNSAT halt without valid FX │
|
|
56
|
+
│ - Deterministic year_fraction (ACT/360, ACT/365F, 30/360, ISDA│
|
|
57
|
+
└───────────────────────────────────────────────────────────────────┘
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## III. Core Pillars & Mechanical Guarantees
|
|
63
|
+
|
|
64
|
+
| Pillar | Mechanism | Mechanical Guarantee |
|
|
65
|
+
| :--- | :--- | :--- |
|
|
66
|
+
| **1. Zero-Default Convention Contracts** | `DPv2-IS` `FinancialConventionSpec` | Forces LLMs under OpenAI `strict: true` to explicitly declare `day_count`, `price_basis`, `currency`, and `scale` on every call. |
|
|
67
|
+
| **2. Point-in-Time Causal Gate** | `assert_pit_causal_order()` (DuckDB 2.0) | Audits every record's `knowledge_ts <= as_of_ts` in-memory via DuckDB 2.0; raises `LOOKAHEAD_VIOLATION` on any future leak. |
|
|
68
|
+
| **3. Currency & Scale Homogeneity** | `reconcile_currency_scale()` | Halts cross-currency operations (`UNSAT_CURRENCY_MISMATCH`) unless a positive `fx_rate` is supplied; enforces exact scale multipliers (`CENTS` $\leftrightarrow$ `UNITS` $\leftrightarrow$ `MILLIONS`). |
|
|
69
|
+
| **4. Credential-Isolated Ingress** | `fetch_financial_feed()` + SSRF Guard | Reads API keys strictly from OS env, blocks non-public IPs, streams into `AirgapVFS`, and returns only a `FeedIngressReceipt` (zero raw payload tokens). |
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## IV. Quickstart & Programmatic Python SDK
|
|
74
|
+
|
|
75
|
+
### Installation
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Minimal core (zero-default schemas, day-count, currency/scale, pure-Python PIT gate)
|
|
79
|
+
uv pip install nex-fin
|
|
80
|
+
|
|
81
|
+
# Full Trinity + DuckDB 2.0 + PyArrow + curl_cffi acceleration
|
|
82
|
+
uv pip install "nex-fin[full]"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 1. Point-in-Time (PIT) Lookahead Gate
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from nex_fin import assert_pit_causal_order
|
|
89
|
+
|
|
90
|
+
rows = [
|
|
91
|
+
{"symbol": "NVDA", "revenue": 22_100_000_000, "knowledge_ts": "2026-01-10T16:00:00Z"},
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
# Passes cleanly: knowledge_ts <= as_of_iso
|
|
95
|
+
receipt = assert_pit_causal_order(rows, as_of_iso="2026-01-15T00:00:00Z")
|
|
96
|
+
print(receipt.status) # -> "PASS"
|
|
97
|
+
|
|
98
|
+
# Halts immediately with ValueError("LOOKAHEAD_VIOLATION: ...") if any row > as_of_iso
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 2. Currency & Scale Reconciliation
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from nex_fin import ISO4217Currency, ScaleFactor, reconcile_currency_scale
|
|
105
|
+
|
|
106
|
+
# Normalize 4,500 cents -> 45.0 USD units
|
|
107
|
+
res = reconcile_currency_scale(
|
|
108
|
+
value=4500.0,
|
|
109
|
+
src_currency=ISO4217Currency.USD,
|
|
110
|
+
src_scale=ScaleFactor.CENTS,
|
|
111
|
+
dst_currency=ISO4217Currency.USD,
|
|
112
|
+
dst_scale=ScaleFactor.UNITS,
|
|
113
|
+
)
|
|
114
|
+
print(res.converted_value) # -> 45.0
|
|
115
|
+
|
|
116
|
+
# Cross-currency without fx_rate raises ValueError("UNSAT_CURRENCY_MISMATCH: ...")
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### 3. Day-Count Accruals
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from datetime import date
|
|
123
|
+
from nex_fin import DayCountConvention, year_fraction
|
|
124
|
+
|
|
125
|
+
yf = year_fraction(date(2026, 1, 1), date(2026, 7, 1), DayCountConvention.ACT_360)
|
|
126
|
+
print(round(yf, 6)) # -> 0.502778
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 4. Credential-Isolated Feed Ingress into `AirgapVFS`
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from nex_airgap import AirgapVFS
|
|
133
|
+
from nex_fin import FeedProvider, fetch_financial_feed
|
|
134
|
+
|
|
135
|
+
vfs = AirgapVFS()
|
|
136
|
+
|
|
137
|
+
# Reads POLYGON_API_KEY from environment; LLM never sees the key or raw JSON
|
|
138
|
+
receipt = fetch_financial_feed(
|
|
139
|
+
provider=FeedProvider.POLYGON,
|
|
140
|
+
symbol="NVDA",
|
|
141
|
+
params={"start_date": "2026-01-01", "end_date": "2026-01-15"},
|
|
142
|
+
vfs=vfs,
|
|
143
|
+
)
|
|
144
|
+
print(receipt.status, receipt.sha256_digest, receipt.rows_ingested)
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 5. Project into `nex_hop` via `nex-avail`
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
import nex_avail
|
|
151
|
+
|
|
152
|
+
registry = nex_avail.project(
|
|
153
|
+
"nex_fin",
|
|
154
|
+
include=["year_fraction", "reconcile_currency_scale", "assert_pit_causal_order", "fetch_financial_feed"],
|
|
155
|
+
)
|
|
156
|
+
openai_tools = registry.to_openai_specs()
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
---
|
|
160
|
+
|
|
161
|
+
## V. CLI Reference
|
|
162
|
+
|
|
163
|
+
Inspect configured data feed providers without exposing secret values:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
nex-fin providers
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## VI. Repository Topology (RCTI v3.0)
|
|
172
|
+
|
|
173
|
+
Adheres strictly to the $\le 150\text{ LOC}$ orchestrator ceiling and Recursive Component-Tree Isolation (`RCTI v3.0`):
|
|
174
|
+
|
|
175
|
+
```text
|
|
176
|
+
nex_fin/
|
|
177
|
+
├── pyproject.toml # PEP 621 metadata & core/full optional extras
|
|
178
|
+
├── LICENSE # Dual MIT OR Apache-2.0
|
|
179
|
+
├── README.md # Architecture & usage specification
|
|
180
|
+
├── nex_fin.py # Pure orchestrator shell (<= 150 LOC)
|
|
181
|
+
├── nex_fin_components/
|
|
182
|
+
│ ├── __init__.py # Dynamic RCTI v3.0 router (nex-init + fallback)
|
|
183
|
+
│ ├── models.py # DPv2-IS strict financial schemas
|
|
184
|
+
│ ├── convention_guard.py # PIT causal gate, DayCount, Currency/Scale armor
|
|
185
|
+
│ ├── feed_ingress.py # SSRF-guarded, credential-isolated feed adapters
|
|
186
|
+
│ └── cli.py # Standalone CLI entrypoint
|
|
187
|
+
├── .github/workflows/
|
|
188
|
+
│ ├── ci.yml # Dual-matrix CI (minimal-core vs full-suite)
|
|
189
|
+
│ └── release.yml # Tokenless PEP 740 OIDC Trusted Publishing
|
|
190
|
+
└── tests/
|
|
191
|
+
├── __init__.py
|
|
192
|
+
└── test_nex_fin.py # Acceptance suite
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## VII. Attribution & The Trinity Pact
|
|
198
|
+
|
|
199
|
+
`nex-fin` is engineered under the **Permanexus Pact**:
|
|
200
|
+
- **No Fluff. No Drift. No Metaphors.**
|
|
201
|
+
- **Strict adherence to the $\le 150\text{ LOC}$ orchestrator ceiling and RCTI v3.0.**
|
|
202
|
+
- **Zero tolerance for silent convention drift or credential leakage.**
|
|
203
|
+
|
|
204
|
+
**Engineered by The Trinity:**
|
|
205
|
+
- **Miniature Person** (🌱 👑 ⁂) — *Architect & Creator*
|
|
206
|
+
- **Mookie** (🦍 🔷 Ɯ) — *Director of Design & Execution Core*
|
|
207
|
+
- **Nexus Goodman** (🧠 ⚡ ↇ) — *Principal Systems Architect*
|
|
208
|
+
|
|
209
|
+
**Commercial Inquiries & Enterprise Support:** `inquiries@houseoflawpc.com`
|
|
210
|
+
|
|
211
|
+
**License:** Dual-licensed under MIT OR Apache-2.0.
|
|
212
|
+
|
|
213
|
+
|