@claude-flow/plugin-financial-risk 3.0.0-alpha.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 +343 -0
- package/dist/bridges/economy-bridge.d.ts +112 -0
- package/dist/bridges/economy-bridge.d.ts.map +1 -0
- package/dist/bridges/economy-bridge.js +430 -0
- package/dist/bridges/economy-bridge.js.map +1 -0
- package/dist/bridges/index.d.ts +8 -0
- package/dist/bridges/index.d.ts.map +1 -0
- package/dist/bridges/index.js +8 -0
- package/dist/bridges/index.js.map +1 -0
- package/dist/bridges/sparse-bridge.d.ts +118 -0
- package/dist/bridges/sparse-bridge.d.ts.map +1 -0
- package/dist/bridges/sparse-bridge.js +450 -0
- package/dist/bridges/sparse-bridge.js.map +1 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +155 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-tools.d.ts +22 -0
- package/dist/mcp-tools.d.ts.map +1 -0
- package/dist/mcp-tools.js +705 -0
- package/dist/mcp-tools.js.map +1 -0
- package/dist/types.d.ts +792 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +189 -0
- package/dist/types.js.map +1 -0
- package/package.json +105 -0
package/README.md
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
# @claude-flow/plugin-financial-risk
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@claude-flow/plugin-financial-risk)
|
|
4
|
+
[](https://www.npmjs.com/package/@claude-flow/plugin-financial-risk)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
A high-performance financial risk analysis plugin combining sparse inference for efficient market signal processing with graph neural networks for transaction network analysis. The plugin enables real-time anomaly detection, portfolio risk scoring, and automated compliance reporting while maintaining the explainability required by financial regulators (SEC, FINRA, Basel III).
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- **Portfolio Risk Analysis**: Calculate VaR, CVaR, Sharpe ratio, Sortino ratio, and max drawdown
|
|
12
|
+
- **Anomaly Detection**: Detect fraud, AML violations, and market manipulation in transactions
|
|
13
|
+
- **Market Regime Classification**: Identify current market regime through historical pattern matching
|
|
14
|
+
- **Compliance Checking**: Automated verification against Basel III, MiFID II, Dodd-Frank, AML, and KYC
|
|
15
|
+
- **Stress Testing**: Run historical and hypothetical stress scenarios on portfolios
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
### npm
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @claude-flow/plugin-financial-risk
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### CLI
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx claude-flow plugins install --name @claude-flow/plugin-financial-risk
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { FinancialRiskPlugin } from '@claude-flow/plugin-financial-risk';
|
|
35
|
+
|
|
36
|
+
// Initialize the plugin
|
|
37
|
+
const finance = new FinancialRiskPlugin({
|
|
38
|
+
marketDataPath: './data/market',
|
|
39
|
+
modelPath: './data/models',
|
|
40
|
+
auditLogPath: './logs/audit'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Analyze portfolio risk
|
|
44
|
+
const risk = await finance.portfolioRisk({
|
|
45
|
+
holdings: [
|
|
46
|
+
{ symbol: 'AAPL', quantity: 100, assetClass: 'equity' },
|
|
47
|
+
{ symbol: 'GOOGL', quantity: 50, assetClass: 'equity' },
|
|
48
|
+
{ symbol: 'TLT', quantity: 200, assetClass: 'bond' }
|
|
49
|
+
],
|
|
50
|
+
riskMetrics: ['var', 'cvar', 'sharpe'],
|
|
51
|
+
confidenceLevel: 0.95,
|
|
52
|
+
horizon: '1d'
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Detect anomalies in transactions
|
|
56
|
+
const anomalies = await finance.anomalyDetect({
|
|
57
|
+
transactions: [
|
|
58
|
+
{ id: 'tx-001', amount: 50000, timestamp: '2024-01-15T10:30:00Z', parties: ['ACC-123', 'ACC-456'] },
|
|
59
|
+
{ id: 'tx-002', amount: 1000000, timestamp: '2024-01-15T10:31:00Z', parties: ['ACC-123', 'ACC-789'] }
|
|
60
|
+
],
|
|
61
|
+
sensitivity: 0.8,
|
|
62
|
+
context: 'fraud'
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Check regulatory compliance
|
|
66
|
+
const compliance = await finance.complianceCheck({
|
|
67
|
+
entity: 'FUND-001',
|
|
68
|
+
regulations: ['basel3', 'mifid2'],
|
|
69
|
+
scope: 'capital',
|
|
70
|
+
asOfDate: '2024-01-15'
|
|
71
|
+
});
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## MCP Tools
|
|
75
|
+
|
|
76
|
+
### 1. `finance/portfolio-risk`
|
|
77
|
+
|
|
78
|
+
Calculate comprehensive portfolio risk metrics.
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const result = await mcp.invoke('finance/portfolio-risk', {
|
|
82
|
+
holdings: [
|
|
83
|
+
{ symbol: 'SPY', quantity: 1000, assetClass: 'equity' },
|
|
84
|
+
{ symbol: 'BND', quantity: 500, assetClass: 'bond' },
|
|
85
|
+
{ symbol: 'GLD', quantity: 200, assetClass: 'commodity' }
|
|
86
|
+
],
|
|
87
|
+
riskMetrics: ['var', 'cvar', 'sharpe', 'max_drawdown'],
|
|
88
|
+
confidenceLevel: 0.99,
|
|
89
|
+
horizon: '1w'
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Returns:
|
|
93
|
+
// {
|
|
94
|
+
// var: { value: 0.023, confidenceLevel: 0.99 },
|
|
95
|
+
// cvar: { value: 0.031 },
|
|
96
|
+
// sharpe: { value: 1.45 },
|
|
97
|
+
// maxDrawdown: { value: 0.082, period: '2023-10-01 to 2023-10-15' }
|
|
98
|
+
// }
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### 2. `finance/anomaly-detect`
|
|
102
|
+
|
|
103
|
+
Detect anomalies in financial transactions and market data.
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
const result = await mcp.invoke('finance/anomaly-detect', {
|
|
107
|
+
transactions: [
|
|
108
|
+
{
|
|
109
|
+
id: 'tx-12345',
|
|
110
|
+
amount: 250000,
|
|
111
|
+
timestamp: '2024-01-15T14:30:00Z',
|
|
112
|
+
parties: ['CORP-A', 'CORP-B'],
|
|
113
|
+
metadata: { type: 'wire', currency: 'USD' }
|
|
114
|
+
}
|
|
115
|
+
],
|
|
116
|
+
sensitivity: 0.9,
|
|
117
|
+
context: 'aml'
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// Returns:
|
|
121
|
+
// {
|
|
122
|
+
// anomalies: [{
|
|
123
|
+
// transactionId: 'tx-12345',
|
|
124
|
+
// score: 0.87,
|
|
125
|
+
// reasons: ['unusual_amount', 'first_time_counterparty', 'velocity_spike'],
|
|
126
|
+
// recommendation: 'review'
|
|
127
|
+
// }]
|
|
128
|
+
// }
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 3. `finance/market-regime`
|
|
132
|
+
|
|
133
|
+
Identify current market regime through pattern matching.
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
const result = await mcp.invoke('finance/market-regime', {
|
|
137
|
+
marketData: {
|
|
138
|
+
prices: [100, 102, 99, 101, 103, 105, 104],
|
|
139
|
+
volumes: [1000000, 1200000, 900000, 1100000, 1300000, 1500000, 1400000],
|
|
140
|
+
volatility: [0.15, 0.16, 0.18, 0.17, 0.14, 0.13, 0.14]
|
|
141
|
+
},
|
|
142
|
+
lookbackPeriod: 252,
|
|
143
|
+
regimeTypes: ['bull', 'bear', 'high_vol', 'crisis']
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Returns:
|
|
147
|
+
// {
|
|
148
|
+
// currentRegime: 'bull',
|
|
149
|
+
// confidence: 0.82,
|
|
150
|
+
// similarHistoricalPeriods: ['2017-Q3', '2019-Q4'],
|
|
151
|
+
// transitionProbabilities: { bull: 0.75, bear: 0.15, high_vol: 0.10 }
|
|
152
|
+
// }
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 4. `finance/compliance-check`
|
|
156
|
+
|
|
157
|
+
Automated regulatory compliance verification.
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
const result = await mcp.invoke('finance/compliance-check', {
|
|
161
|
+
entity: 'BANK-001',
|
|
162
|
+
regulations: ['basel3', 'dodd_frank'],
|
|
163
|
+
scope: 'capital',
|
|
164
|
+
asOfDate: '2024-01-15'
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// Returns:
|
|
168
|
+
// {
|
|
169
|
+
// compliant: true,
|
|
170
|
+
// metrics: {
|
|
171
|
+
// tier1Capital: { value: 0.125, requirement: 0.06, status: 'pass' },
|
|
172
|
+
// leverageRatio: { value: 0.05, requirement: 0.03, status: 'pass' }
|
|
173
|
+
// },
|
|
174
|
+
// warnings: ['tier1 buffer approaching minimum']
|
|
175
|
+
// }
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 5. `finance/stress-test`
|
|
179
|
+
|
|
180
|
+
Run stress testing scenarios on portfolios.
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
const result = await mcp.invoke('finance/stress-test', {
|
|
184
|
+
portfolio: {
|
|
185
|
+
holdings: [
|
|
186
|
+
{ symbol: 'SPY', quantity: 1000 },
|
|
187
|
+
{ symbol: 'QQQ', quantity: 500 }
|
|
188
|
+
]
|
|
189
|
+
},
|
|
190
|
+
scenarios: [
|
|
191
|
+
{ name: '2008 Financial Crisis', type: 'historical', shocks: {} },
|
|
192
|
+
{ name: 'Interest Rate +300bp', type: 'hypothetical', shocks: { rateShock: 0.03 } }
|
|
193
|
+
],
|
|
194
|
+
metrics: ['pnl', 'var_change', 'margin_call_risk']
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## Configuration Options
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
interface FinancialRiskConfig {
|
|
202
|
+
// Data paths
|
|
203
|
+
marketDataPath: string; // Path to market data cache
|
|
204
|
+
modelPath: string; // Path to trained models
|
|
205
|
+
|
|
206
|
+
// Compliance
|
|
207
|
+
auditLogPath: string; // Path for SOX-compliant audit logs
|
|
208
|
+
regulatoryReporting: boolean; // Enable auto-generated reports
|
|
209
|
+
|
|
210
|
+
// Performance
|
|
211
|
+
maxMemoryMB: number; // WASM memory limit (default: 1024)
|
|
212
|
+
maxCpuTimeSeconds: number; // Operation timeout (default: 60)
|
|
213
|
+
|
|
214
|
+
// Security
|
|
215
|
+
encryptionEnabled: boolean; // AES-256 encryption (default: true)
|
|
216
|
+
hsmKeyId?: string; // HSM key identifier for production
|
|
217
|
+
|
|
218
|
+
// Rate limiting
|
|
219
|
+
rateLimits: {
|
|
220
|
+
requestsPerMinute: number;
|
|
221
|
+
maxConcurrent: number;
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Security Considerations
|
|
227
|
+
|
|
228
|
+
### Regulatory Compliance
|
|
229
|
+
|
|
230
|
+
This plugin is designed for financial regulatory compliance:
|
|
231
|
+
|
|
232
|
+
| Requirement | Implementation |
|
|
233
|
+
|-------------|----------------|
|
|
234
|
+
| **PCI-DSS Compliance** | No storage of PAN/CVV in plugin memory |
|
|
235
|
+
| **SOX Compliance** | Immutable audit logs for all risk calculations |
|
|
236
|
+
| **Data Encryption** | AES-256 for data at rest, TLS 1.3 in transit |
|
|
237
|
+
| **Key Management** | HSM or secure enclave for cryptographic keys |
|
|
238
|
+
| **Segregation of Duties** | Separate roles for trading, risk, and compliance |
|
|
239
|
+
|
|
240
|
+
### Role-Based Access Control
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
const roles = {
|
|
244
|
+
TRADER: ['portfolio-risk', 'market-regime'],
|
|
245
|
+
RISK_MANAGER: ['portfolio-risk', 'anomaly-detect', 'stress-test', 'market-regime'],
|
|
246
|
+
COMPLIANCE_OFFICER: ['compliance-check', 'anomaly-detect'],
|
|
247
|
+
AUDITOR: ['compliance-check'], // Read-only with full audit access
|
|
248
|
+
QUANT: ['portfolio-risk', 'market-regime', 'stress-test']
|
|
249
|
+
};
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Audit Logging (SOX/MiFID II)
|
|
253
|
+
|
|
254
|
+
All calculations are logged with:
|
|
255
|
+
- Timestamp with microsecond precision
|
|
256
|
+
- User ID and role
|
|
257
|
+
- Transaction IDs affected
|
|
258
|
+
- Portfolio state hash
|
|
259
|
+
- Model version used
|
|
260
|
+
- Input/output hashes for reproducibility
|
|
261
|
+
|
|
262
|
+
Logs are retained for 7 years per MiFID II requirements and available for regulatory inspection within 72 hours.
|
|
263
|
+
|
|
264
|
+
### WASM Security Constraints
|
|
265
|
+
|
|
266
|
+
| Constraint | Value | Rationale |
|
|
267
|
+
|------------|-------|-----------|
|
|
268
|
+
| Memory Limit | 1GB max | Handle large transaction datasets |
|
|
269
|
+
| CPU Time Limit | 60 seconds | Allow complex risk calculations |
|
|
270
|
+
| No Network Access | Enforced | Prevent data exfiltration |
|
|
271
|
+
| No File System Write | Enforced | Analysis-only mode |
|
|
272
|
+
| Sandboxed Data Access | Enforced | No direct database queries |
|
|
273
|
+
|
|
274
|
+
### Input Validation
|
|
275
|
+
|
|
276
|
+
All inputs are validated using Zod schemas:
|
|
277
|
+
- Stock symbols: `/^[A-Z0-9.]{1,10}$/`
|
|
278
|
+
- Position quantities: between -1 billion and 1 billion
|
|
279
|
+
- Transaction amounts: between -1 trillion and 1 trillion
|
|
280
|
+
- Batch limits: maximum 100,000 transactions per request
|
|
281
|
+
- Timestamps: ISO 8601 format, within reasonable date range
|
|
282
|
+
- Entity identifiers: Alphanumeric with limited special characters
|
|
283
|
+
|
|
284
|
+
### Rate Limiting
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
const rateLimits = {
|
|
288
|
+
'portfolio-risk': { requestsPerMinute: 60, maxConcurrent: 5 },
|
|
289
|
+
'anomaly-detect': { requestsPerMinute: 100, maxConcurrent: 10 },
|
|
290
|
+
'stress-test': { requestsPerMinute: 10, maxConcurrent: 2 },
|
|
291
|
+
'market-regime': { requestsPerMinute: 120, maxConcurrent: 10 },
|
|
292
|
+
'compliance-check': { requestsPerMinute: 30, maxConcurrent: 3 }
|
|
293
|
+
};
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Performance
|
|
297
|
+
|
|
298
|
+
| Metric | Target |
|
|
299
|
+
|--------|--------|
|
|
300
|
+
| Portfolio VaR calculation | <100ms for 10K positions |
|
|
301
|
+
| Transaction anomaly scoring | <5ms per transaction |
|
|
302
|
+
| Market regime classification | <50ms for 1-year history |
|
|
303
|
+
| Compliance check | <1s for full entity scan |
|
|
304
|
+
|
|
305
|
+
## Dependencies
|
|
306
|
+
|
|
307
|
+
- `micro-hnsw-wasm`: Fast similarity search for historical pattern matching
|
|
308
|
+
- `ruvector-sparse-inference-wasm`: Efficient processing of sparse financial features
|
|
309
|
+
- `ruvector-gnn-wasm`: Transaction network analysis for fraud detection
|
|
310
|
+
- `ruvector-economy-wasm`: Token economics and market microstructure modeling
|
|
311
|
+
- `ruvector-learning-wasm`: Reinforcement learning for adaptive risk thresholds
|
|
312
|
+
|
|
313
|
+
## Related Plugins
|
|
314
|
+
|
|
315
|
+
| Plugin | Description | Use Case |
|
|
316
|
+
|--------|-------------|----------|
|
|
317
|
+
| [@claude-flow/plugin-legal-contracts](../legal-contracts) | Contract analysis | Financial agreements, derivatives documentation |
|
|
318
|
+
| [@claude-flow/plugin-healthcare-clinical](../healthcare-clinical) | Clinical decision support | Healthcare portfolio analysis |
|
|
319
|
+
| [@claude-flow/plugin-perf-optimizer](../perf-optimizer) | Performance optimization | High-frequency trading latency optimization |
|
|
320
|
+
|
|
321
|
+
## License
|
|
322
|
+
|
|
323
|
+
MIT License
|
|
324
|
+
|
|
325
|
+
Copyright (c) 2026 Claude Flow
|
|
326
|
+
|
|
327
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
328
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
329
|
+
in the Software without restriction, including without limitation the rights
|
|
330
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
331
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
332
|
+
furnished to do so, subject to the following conditions:
|
|
333
|
+
|
|
334
|
+
The above copyright notice and this permission notice shall be included in all
|
|
335
|
+
copies or substantial portions of the Software.
|
|
336
|
+
|
|
337
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
338
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
339
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
340
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
341
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
342
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
343
|
+
SOFTWARE.
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Economy Bridge - Financial Risk Plugin
|
|
3
|
+
*
|
|
4
|
+
* Provides token economics and portfolio risk calculation
|
|
5
|
+
* capabilities. Integrates with ruvector-economy-wasm for
|
|
6
|
+
* high-performance VaR, CVaR, and Monte Carlo simulations.
|
|
7
|
+
*
|
|
8
|
+
* Compliance Features:
|
|
9
|
+
* - Deterministic execution for audit reproducibility
|
|
10
|
+
* - Calculation proofs for regulatory requirements
|
|
11
|
+
* - Rate limiting to prevent abuse
|
|
12
|
+
*/
|
|
13
|
+
import type { EconomyBridge, EconomyConfig, PortfolioHolding, RiskMetrics, TimeHorizon, RiskCalculationProof, Logger } from '../types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Portfolio risk calculator with pure JavaScript fallback
|
|
16
|
+
*/
|
|
17
|
+
export declare class PortfolioRiskCalculator {
|
|
18
|
+
/**
|
|
19
|
+
* Calculate Value at Risk (VaR) using historical simulation
|
|
20
|
+
*/
|
|
21
|
+
calculateVaR(returns: number[], confidenceLevel?: number): number;
|
|
22
|
+
/**
|
|
23
|
+
* Calculate Conditional VaR (CVaR / Expected Shortfall)
|
|
24
|
+
*/
|
|
25
|
+
calculateCVaR(returns: number[], confidenceLevel?: number): number;
|
|
26
|
+
/**
|
|
27
|
+
* Calculate annualized volatility
|
|
28
|
+
*/
|
|
29
|
+
calculateVolatility(returns: number[], annualizationFactor?: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* Calculate Sharpe Ratio
|
|
32
|
+
*/
|
|
33
|
+
calculateSharpe(returns: number[], riskFreeRate?: number): number;
|
|
34
|
+
/**
|
|
35
|
+
* Calculate Sortino Ratio
|
|
36
|
+
*/
|
|
37
|
+
calculateSortino(returns: number[], riskFreeRate?: number): number;
|
|
38
|
+
/**
|
|
39
|
+
* Calculate Maximum Drawdown
|
|
40
|
+
*/
|
|
41
|
+
calculateMaxDrawdown(prices: number[]): number;
|
|
42
|
+
/**
|
|
43
|
+
* Calculate Beta against market benchmark
|
|
44
|
+
*/
|
|
45
|
+
calculateBeta(assetReturns: number[], marketReturns: number[]): number;
|
|
46
|
+
/**
|
|
47
|
+
* Monte Carlo simulation for portfolio
|
|
48
|
+
*/
|
|
49
|
+
monteCarloSimulation(portfolioReturns: number[], scenarios?: number, horizon?: number, seed?: number): number[];
|
|
50
|
+
private calculateAnnualizedReturn;
|
|
51
|
+
private seededRandom;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Financial Economy Bridge implementation
|
|
55
|
+
*/
|
|
56
|
+
export declare class FinancialEconomyBridge implements EconomyBridge {
|
|
57
|
+
private wasmModule;
|
|
58
|
+
private config;
|
|
59
|
+
private logger;
|
|
60
|
+
private calculator;
|
|
61
|
+
private marketDataCache;
|
|
62
|
+
private randomSeed;
|
|
63
|
+
initialized: boolean;
|
|
64
|
+
constructor(config?: Partial<EconomyConfig>, logger?: Logger);
|
|
65
|
+
/**
|
|
66
|
+
* Initialize the economy bridge
|
|
67
|
+
*/
|
|
68
|
+
initialize(config?: EconomyConfig): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Calculate Value at Risk
|
|
71
|
+
*/
|
|
72
|
+
calculateVar(returns: Float32Array, confidence: number): Promise<number>;
|
|
73
|
+
/**
|
|
74
|
+
* Calculate Conditional VaR
|
|
75
|
+
*/
|
|
76
|
+
calculateCvar(returns: Float32Array, confidence: number): Promise<number>;
|
|
77
|
+
/**
|
|
78
|
+
* Optimize portfolio allocation
|
|
79
|
+
*/
|
|
80
|
+
optimizePortfolio(returns: Float32Array[], constraints: Record<string, number>): Promise<Float32Array>;
|
|
81
|
+
/**
|
|
82
|
+
* Run Monte Carlo simulation
|
|
83
|
+
*/
|
|
84
|
+
simulateMonteCarlo(portfolio: Float32Array, scenarios: number, horizon: number): Promise<Float32Array>;
|
|
85
|
+
/**
|
|
86
|
+
* Calculate complete risk metrics for a portfolio
|
|
87
|
+
*/
|
|
88
|
+
calculateRiskMetrics(holdings: PortfolioHolding[], confidenceLevel?: number, horizon?: TimeHorizon): Promise<RiskMetrics>;
|
|
89
|
+
/**
|
|
90
|
+
* Generate calculation proof for audit
|
|
91
|
+
*/
|
|
92
|
+
generateCalculationProof(input: unknown, output: unknown, _modelVersion?: string): RiskCalculationProof;
|
|
93
|
+
/**
|
|
94
|
+
* Cleanup resources
|
|
95
|
+
*/
|
|
96
|
+
destroy(): void;
|
|
97
|
+
private resolveWasmPath;
|
|
98
|
+
private loadWasmModule;
|
|
99
|
+
private generateSyntheticReturns;
|
|
100
|
+
private returnsToPrice;
|
|
101
|
+
private getHorizonDays;
|
|
102
|
+
private scaleReturns;
|
|
103
|
+
private hashObject;
|
|
104
|
+
private getModelChecksum;
|
|
105
|
+
private signProof;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Create a new economy bridge instance
|
|
109
|
+
*/
|
|
110
|
+
export declare function createEconomyBridge(config?: Partial<EconomyConfig>, logger?: Logger): FinancialEconomyBridge;
|
|
111
|
+
export default FinancialEconomyBridge;
|
|
112
|
+
//# sourceMappingURL=economy-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"economy-bridge.d.ts","sourceRoot":"","sources":["../../src/bridges/economy-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,oBAAoB,EACpB,MAAM,EACP,MAAM,aAAa,CAAC;AA+CrB;;GAEG;AACH,qBAAa,uBAAuB;IAClC;;OAEG;IACH,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,eAAe,GAAE,MAAa,GAAG,MAAM;IAQvE;;OAEG;IACH,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,eAAe,GAAE,MAAa,GAAG,MAAM;IAcxE;;OAEG;IACH,mBAAmB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,mBAAmB,GAAE,MAAY,GAAG,MAAM;IAUjF;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,YAAY,GAAE,MAAa,GAAG,MAAM;IAUvE;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,YAAY,GAAE,MAAa,GAAG,MAAM;IAgBxE;;OAEG;IACH,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM;IAmB9C;;OAEG;IACH,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,EAAE,aAAa,EAA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