cortex-risk-sdk 1.0.0 → 1.0.1
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.
- package/README.md +107 -0
- package/package.json +6 -6
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# cortex-risk-sdk
|
|
2
|
+
|
|
3
|
+
TypeScript SDK for the [CortexAgent Risk Engine](https://www.cortex-agent.xyz) — 45 typed endpoints covering MSM regime detection, EVT, SVJ, Hawkes, rough volatility, copula VaR, and Guardian risk veto.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/cortex-risk-sdk)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install cortex-risk-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires **Node 18+** (native `fetch`).
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { RiskEngineClient } from "cortex-risk-sdk";
|
|
19
|
+
|
|
20
|
+
const risk = new RiskEngineClient({
|
|
21
|
+
baseUrl: "http://localhost:8000",
|
|
22
|
+
timeout: 15_000,
|
|
23
|
+
retries: 3,
|
|
24
|
+
validateResponses: true,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Calibrate MSM model
|
|
28
|
+
await risk.calibrate({ token: "SOL-USD", num_states: 5 });
|
|
29
|
+
|
|
30
|
+
// Check regime
|
|
31
|
+
const regime = await risk.regime("SOL-USD");
|
|
32
|
+
console.log(regime.regime_state, regime.regime_name);
|
|
33
|
+
|
|
34
|
+
// Guardian risk veto
|
|
35
|
+
const assessment = await risk.guardianAssess({
|
|
36
|
+
token: "SOL-USD",
|
|
37
|
+
trade_size_usd: 50_000,
|
|
38
|
+
direction: "long",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (assessment.approved) {
|
|
42
|
+
console.log(`Approved — size $${assessment.recommended_size}`);
|
|
43
|
+
} else {
|
|
44
|
+
console.log(`Vetoed — ${assessment.veto_reasons.join(", ")}`);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Modules (45 endpoints)
|
|
49
|
+
|
|
50
|
+
| Module | Methods | Description |
|
|
51
|
+
|--------|---------|-------------|
|
|
52
|
+
| **Core MSM** | `calibrate`, `regime`, `var`, `volatilityForecast`, `backtestSummary`, `tailProbs` | Regime detection, VaR |
|
|
53
|
+
| **Regime Analytics** | `regimeDurations`, `regimeHistory`, `regimeStatistics`, `transitionAlert` | Temporal regime analysis |
|
|
54
|
+
| **Model Comparison** | `compare`, `comparisonReport` | 9-model benchmark |
|
|
55
|
+
| **Portfolio VaR** | `portfolioCalibrate`, `portfolioVar`, `marginalVar`, `stressVar` | Multi-asset risk |
|
|
56
|
+
| **Copula VaR** | `copulaVar`, `copulaCompare`, `copulaDiagnostics`, `regimeDependentCopulaVar` | Dependence modeling |
|
|
57
|
+
| **EVT** | `evtCalibrate`, `evtVar`, `evtDiagnostics` | Tail risk (GPD) |
|
|
58
|
+
| **Hawkes** | `hawkesCalibrate`, `hawkesIntensity`, `hawkesClusters`, `hawkesVar`, `hawkesSimulate` | Crash contagion |
|
|
59
|
+
| **Multifractal** | `hurst`, `spectrum`, `regimeHurst`, `fractalDiagnostics` | Hurst exponent |
|
|
60
|
+
| **Rough Vol** | `roughCalibrate`, `roughForecast`, `roughDiagnostics`, `roughCompareMsm` | Rough Bergomi |
|
|
61
|
+
| **SVJ** | `svjCalibrate`, `svjVar`, `svjJumpRisk`, `svjDiagnostics` | Jump risk |
|
|
62
|
+
| **News** | `newsFeed`, `newsSentiment`, `newsSignal` | Sentiment signals |
|
|
63
|
+
| **Guardian** | `guardianAssess` | Unified risk veto |
|
|
64
|
+
|
|
65
|
+
## WebSocket Streaming
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { RegimeStreamClient } from "cortex-risk-sdk";
|
|
69
|
+
|
|
70
|
+
const stream = new RegimeStreamClient({
|
|
71
|
+
baseUrl: "http://localhost:8000",
|
|
72
|
+
token: "SOL-USD",
|
|
73
|
+
onRegime: (msg) => console.log(`Regime ${msg.regime_state}`),
|
|
74
|
+
onError: (err) => console.error(err),
|
|
75
|
+
});
|
|
76
|
+
stream.connect();
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Resilience
|
|
80
|
+
|
|
81
|
+
Built-in via [cockatiel](https://github.com/connor4312/cockatiel):
|
|
82
|
+
|
|
83
|
+
- **Retry** — exponential backoff (configurable `retries`)
|
|
84
|
+
- **Circuit breaker** — opens after consecutive failures, half-opens after cooldown
|
|
85
|
+
- **Timeout** — per-request timeout with `AbortSignal`
|
|
86
|
+
|
|
87
|
+
## Validation
|
|
88
|
+
|
|
89
|
+
Optional [zod](https://github.com/colinhacks/zod) runtime validation for critical responses (Guardian, VaR, Regime). Enable with `validateResponses: true`.
|
|
90
|
+
|
|
91
|
+
## Configuration
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const risk = new RiskEngineClient({
|
|
95
|
+
baseUrl: "http://localhost:8000", // Risk Engine URL
|
|
96
|
+
timeout: 10_000, // Request timeout (ms)
|
|
97
|
+
retries: 3, // Max retry attempts
|
|
98
|
+
cbThreshold: 5, // Circuit breaker threshold
|
|
99
|
+
cbResetMs: 30_000, // Circuit breaker reset (ms)
|
|
100
|
+
validateResponses: false, // Zod validation
|
|
101
|
+
});
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT — [Cortex AI](https://www.cortex-agent.xyz)
|
|
107
|
+
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortex-risk-sdk",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"author": "Cortex
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "TypeScript SDK for the CortexAgent Risk Engine — MSM-VaR, EVT, SVJ, Hawkes, Rough Volatility, Copula VaR, and Guardian risk veto for autonomous DeFi agents on Solana.",
|
|
5
|
+
"author": "Cortex AI <dev@cortex-agent.xyz> (https://www.cortex-agent.xyz)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
|
-
"url": "git+https://github.com/cortex-
|
|
9
|
+
"url": "git+https://github.com/cortex-agent/cortexagent.git"
|
|
10
10
|
},
|
|
11
|
-
"homepage": "https://
|
|
11
|
+
"homepage": "https://www.cortex-agent.xyz",
|
|
12
12
|
"bugs": {
|
|
13
|
-
"url": "https://github.com/cortex-
|
|
13
|
+
"url": "https://github.com/cortex-agent/cortexagent/issues"
|
|
14
14
|
},
|
|
15
15
|
"main": "dist/index.js",
|
|
16
16
|
"types": "dist/index.d.ts",
|