@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
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sparse Bridge - Financial Risk Plugin
|
|
3
|
+
*
|
|
4
|
+
* Provides sparse inference capabilities for efficient processing
|
|
5
|
+
* of high-dimensional financial data. Integrates with
|
|
6
|
+
* ruvector-sparse-inference-wasm for anomaly detection and
|
|
7
|
+
* market regime classification.
|
|
8
|
+
*
|
|
9
|
+
* Features:
|
|
10
|
+
* - Efficient sparse feature processing
|
|
11
|
+
* - Transaction anomaly detection
|
|
12
|
+
* - Market regime classification
|
|
13
|
+
* - Real-time fraud detection
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Default logger
|
|
17
|
+
*/
|
|
18
|
+
const defaultLogger = {
|
|
19
|
+
debug: (msg, meta) => console.debug(`[sparse-bridge] ${msg}`, meta),
|
|
20
|
+
info: (msg, meta) => console.info(`[sparse-bridge] ${msg}`, meta),
|
|
21
|
+
warn: (msg, meta) => console.warn(`[sparse-bridge] ${msg}`, meta),
|
|
22
|
+
error: (msg, meta) => console.error(`[sparse-bridge] ${msg}`, meta),
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Anomaly detection using Isolation Forest-like approach
|
|
26
|
+
*/
|
|
27
|
+
export class AnomalyDetector {
|
|
28
|
+
constructor(_numTrees = 100, _sampleSize = 256, _maxDepth = 8) {
|
|
29
|
+
// Parameters reserved for future Isolation Forest implementation
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Calculate anomaly scores for transactions
|
|
33
|
+
*/
|
|
34
|
+
calculateAnomalyScores(transactions) {
|
|
35
|
+
const scores = new Map();
|
|
36
|
+
const features = this.extractFeatures(transactions);
|
|
37
|
+
for (let i = 0; i < transactions.length; i++) {
|
|
38
|
+
const txn = transactions[i];
|
|
39
|
+
const featureVector = features[i];
|
|
40
|
+
const score = this.isolationScore(featureVector, features);
|
|
41
|
+
scores.set(txn.id, score);
|
|
42
|
+
}
|
|
43
|
+
return scores;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Detect anomalies above threshold
|
|
47
|
+
*/
|
|
48
|
+
detectAnomalies(transactions, threshold = 0.8) {
|
|
49
|
+
const scores = this.calculateAnomalyScores(transactions);
|
|
50
|
+
const anomalies = [];
|
|
51
|
+
for (const txn of transactions) {
|
|
52
|
+
const score = scores.get(txn.id) ?? 0;
|
|
53
|
+
if (score >= threshold) {
|
|
54
|
+
anomalies.push({
|
|
55
|
+
transactionId: txn.id,
|
|
56
|
+
score,
|
|
57
|
+
severity: this.scoresToSeverity(score),
|
|
58
|
+
type: this.classifyAnomalyType(txn, score),
|
|
59
|
+
description: this.generateDescription(txn, score),
|
|
60
|
+
indicators: this.identifyIndicators(txn),
|
|
61
|
+
recommendedAction: this.recommendAction(score),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Sort by score descending
|
|
66
|
+
anomalies.sort((a, b) => b.score - a.score);
|
|
67
|
+
return anomalies;
|
|
68
|
+
}
|
|
69
|
+
extractFeatures(transactions) {
|
|
70
|
+
return transactions.map(txn => {
|
|
71
|
+
const hour = new Date(txn.timestamp).getHours();
|
|
72
|
+
const dayOfWeek = new Date(txn.timestamp).getDay();
|
|
73
|
+
return [
|
|
74
|
+
Math.log(Math.abs(txn.amount) + 1), // Log-scaled amount
|
|
75
|
+
txn.amount < 0 ? 1 : 0, // Debit indicator
|
|
76
|
+
txn.parties.length, // Number of parties
|
|
77
|
+
hour / 24, // Normalized hour
|
|
78
|
+
dayOfWeek / 7, // Normalized day of week
|
|
79
|
+
txn.amount > 10000 ? 1 : 0, // Large transaction flag
|
|
80
|
+
txn.amount > 100000 ? 1 : 0, // Very large transaction flag
|
|
81
|
+
];
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
isolationScore(point, allPoints) {
|
|
85
|
+
// Simplified isolation score based on distance from median
|
|
86
|
+
const numFeatures = point.length;
|
|
87
|
+
let totalDeviation = 0;
|
|
88
|
+
for (let f = 0; f < numFeatures; f++) {
|
|
89
|
+
const values = allPoints.map(p => p[f]).sort((a, b) => a - b);
|
|
90
|
+
const median = values[Math.floor(values.length / 2)];
|
|
91
|
+
const mad = this.medianAbsoluteDeviation(values, median);
|
|
92
|
+
if (mad > 0) {
|
|
93
|
+
totalDeviation += Math.abs(point[f] - median) / mad;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Normalize score to [0, 1]
|
|
97
|
+
const normalizedScore = 1 - Math.exp(-totalDeviation / (numFeatures * 3));
|
|
98
|
+
return Math.min(Math.max(normalizedScore, 0), 1);
|
|
99
|
+
}
|
|
100
|
+
medianAbsoluteDeviation(values, median) {
|
|
101
|
+
const deviations = values.map(v => Math.abs(v - median));
|
|
102
|
+
deviations.sort((a, b) => a - b);
|
|
103
|
+
return deviations[Math.floor(deviations.length / 2)] ?? 1;
|
|
104
|
+
}
|
|
105
|
+
scoresToSeverity(score) {
|
|
106
|
+
if (score >= 0.95)
|
|
107
|
+
return 'critical';
|
|
108
|
+
if (score >= 0.85)
|
|
109
|
+
return 'high';
|
|
110
|
+
if (score >= 0.7)
|
|
111
|
+
return 'medium';
|
|
112
|
+
return 'low';
|
|
113
|
+
}
|
|
114
|
+
classifyAnomalyType(txn, score) {
|
|
115
|
+
if (Math.abs(txn.amount) > 100000)
|
|
116
|
+
return 'large_transaction';
|
|
117
|
+
if (txn.parties.length > 5)
|
|
118
|
+
return 'multi_party';
|
|
119
|
+
if (score > 0.9)
|
|
120
|
+
return 'pattern_deviation';
|
|
121
|
+
return 'unusual_activity';
|
|
122
|
+
}
|
|
123
|
+
generateDescription(txn, score) {
|
|
124
|
+
const amount = Math.abs(txn.amount).toLocaleString('en-US', { style: 'currency', currency: 'USD' });
|
|
125
|
+
return `Transaction ${txn.id} with amount ${amount} has anomaly score ${(score * 100).toFixed(1)}%`;
|
|
126
|
+
}
|
|
127
|
+
identifyIndicators(txn) {
|
|
128
|
+
const indicators = [];
|
|
129
|
+
if (Math.abs(txn.amount) > 10000)
|
|
130
|
+
indicators.push('large_amount');
|
|
131
|
+
if (txn.parties.length > 3)
|
|
132
|
+
indicators.push('multiple_parties');
|
|
133
|
+
const hour = new Date(txn.timestamp).getHours();
|
|
134
|
+
if (hour < 6 || hour > 22)
|
|
135
|
+
indicators.push('unusual_time');
|
|
136
|
+
const dayOfWeek = new Date(txn.timestamp).getDay();
|
|
137
|
+
if (dayOfWeek === 0 || dayOfWeek === 6)
|
|
138
|
+
indicators.push('weekend_transaction');
|
|
139
|
+
return indicators;
|
|
140
|
+
}
|
|
141
|
+
recommendAction(score) {
|
|
142
|
+
if (score >= 0.95)
|
|
143
|
+
return 'Immediate escalation to compliance team required';
|
|
144
|
+
if (score >= 0.85)
|
|
145
|
+
return 'Flag for manual review within 24 hours';
|
|
146
|
+
if (score >= 0.7)
|
|
147
|
+
return 'Add to monitoring watchlist';
|
|
148
|
+
return 'Continue standard monitoring';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Market regime classifier
|
|
153
|
+
*/
|
|
154
|
+
export class MarketRegimeClassifier {
|
|
155
|
+
windowSize;
|
|
156
|
+
constructor(windowSize = 20) {
|
|
157
|
+
this.windowSize = windowSize;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Classify current market regime
|
|
161
|
+
*/
|
|
162
|
+
classify(prices, _volumes) {
|
|
163
|
+
if (prices.length < this.windowSize) {
|
|
164
|
+
return { regime: 'sideways', confidence: 0.5 };
|
|
165
|
+
}
|
|
166
|
+
const returns = this.calculateReturns(prices);
|
|
167
|
+
const volatility = this.calculateVolatility(returns);
|
|
168
|
+
const trend = this.calculateTrend(prices);
|
|
169
|
+
const momentum = this.calculateMomentum(returns);
|
|
170
|
+
// Regime classification logic
|
|
171
|
+
const regime = this.determineRegime(trend, volatility, momentum);
|
|
172
|
+
const confidence = this.calculateConfidence(trend, volatility, momentum);
|
|
173
|
+
return { regime, confidence };
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Get regime probabilities
|
|
177
|
+
*/
|
|
178
|
+
getRegimeProbabilities(prices) {
|
|
179
|
+
const { regime, confidence } = this.classify(prices);
|
|
180
|
+
// Distribute probability based on confidence
|
|
181
|
+
const probs = {
|
|
182
|
+
bull: 0.1,
|
|
183
|
+
bear: 0.1,
|
|
184
|
+
sideways: 0.3,
|
|
185
|
+
high_vol: 0.2,
|
|
186
|
+
crisis: 0.1,
|
|
187
|
+
recovery: 0.2,
|
|
188
|
+
};
|
|
189
|
+
// Increase probability for detected regime
|
|
190
|
+
const totalOther = 1 - confidence;
|
|
191
|
+
for (const r of Object.keys(probs)) {
|
|
192
|
+
if (r === regime) {
|
|
193
|
+
probs[r] = confidence;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
probs[r] = (totalOther * probs[r]) / (1 - probs[regime]);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return probs;
|
|
200
|
+
}
|
|
201
|
+
calculateReturns(prices) {
|
|
202
|
+
const returns = [];
|
|
203
|
+
for (let i = 1; i < prices.length; i++) {
|
|
204
|
+
returns.push((prices[i] - prices[i - 1]) / prices[i - 1]);
|
|
205
|
+
}
|
|
206
|
+
return returns;
|
|
207
|
+
}
|
|
208
|
+
calculateVolatility(returns) {
|
|
209
|
+
if (returns.length < 2)
|
|
210
|
+
return 0;
|
|
211
|
+
const mean = returns.reduce((a, b) => a + b, 0) / returns.length;
|
|
212
|
+
const variance = returns.reduce((sum, r) => sum + Math.pow(r - mean, 2), 0) / (returns.length - 1);
|
|
213
|
+
return Math.sqrt(variance) * Math.sqrt(252); // Annualized
|
|
214
|
+
}
|
|
215
|
+
calculateTrend(prices) {
|
|
216
|
+
if (prices.length < 2)
|
|
217
|
+
return 0;
|
|
218
|
+
// Simple linear regression slope
|
|
219
|
+
const n = prices.length;
|
|
220
|
+
let sumX = 0, sumY = 0, sumXY = 0, sumX2 = 0;
|
|
221
|
+
for (let i = 0; i < n; i++) {
|
|
222
|
+
sumX += i;
|
|
223
|
+
sumY += prices[i];
|
|
224
|
+
sumXY += i * prices[i];
|
|
225
|
+
sumX2 += i * i;
|
|
226
|
+
}
|
|
227
|
+
const slope = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);
|
|
228
|
+
const avgPrice = sumY / n;
|
|
229
|
+
return slope / avgPrice * 252; // Annualized trend
|
|
230
|
+
}
|
|
231
|
+
calculateMomentum(returns) {
|
|
232
|
+
if (returns.length < this.windowSize)
|
|
233
|
+
return 0;
|
|
234
|
+
// Recent momentum vs historical
|
|
235
|
+
const recent = returns.slice(-Math.floor(this.windowSize / 2));
|
|
236
|
+
const historical = returns.slice(-this.windowSize, -Math.floor(this.windowSize / 2));
|
|
237
|
+
const recentMean = recent.reduce((a, b) => a + b, 0) / recent.length;
|
|
238
|
+
const historicalMean = historical.reduce((a, b) => a + b, 0) / historical.length;
|
|
239
|
+
return recentMean - historicalMean;
|
|
240
|
+
}
|
|
241
|
+
determineRegime(trend, volatility, momentum) {
|
|
242
|
+
// High volatility regimes
|
|
243
|
+
if (volatility > 0.4) {
|
|
244
|
+
if (trend < -0.3)
|
|
245
|
+
return 'crisis';
|
|
246
|
+
return 'high_vol';
|
|
247
|
+
}
|
|
248
|
+
// Trend-based regimes
|
|
249
|
+
if (trend > 0.15) {
|
|
250
|
+
return momentum > 0 ? 'bull' : 'recovery';
|
|
251
|
+
}
|
|
252
|
+
if (trend < -0.15) {
|
|
253
|
+
return 'bear';
|
|
254
|
+
}
|
|
255
|
+
return 'sideways';
|
|
256
|
+
}
|
|
257
|
+
calculateConfidence(trend, volatility, momentum) {
|
|
258
|
+
// Higher confidence for extreme values
|
|
259
|
+
const trendStrength = Math.min(Math.abs(trend) / 0.3, 1);
|
|
260
|
+
const volStrength = Math.min(volatility / 0.4, 1);
|
|
261
|
+
const momStrength = Math.min(Math.abs(momentum) / 0.01, 1);
|
|
262
|
+
return 0.4 + 0.6 * Math.max(trendStrength, volStrength, momStrength);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Financial Sparse Bridge implementation
|
|
267
|
+
*/
|
|
268
|
+
export class FinancialSparseBridge {
|
|
269
|
+
wasmModule = null;
|
|
270
|
+
modelPtr = 0;
|
|
271
|
+
config;
|
|
272
|
+
logger;
|
|
273
|
+
anomalyDetector;
|
|
274
|
+
regimeClassifier;
|
|
275
|
+
initialized = false;
|
|
276
|
+
constructor(config, logger) {
|
|
277
|
+
this.config = {
|
|
278
|
+
sparsityThreshold: config?.sparsityThreshold ?? 0.9,
|
|
279
|
+
maxFeatures: config?.maxFeatures ?? 1000,
|
|
280
|
+
compressionLevel: config?.compressionLevel ?? 3,
|
|
281
|
+
};
|
|
282
|
+
this.logger = logger ?? defaultLogger;
|
|
283
|
+
this.anomalyDetector = new AnomalyDetector();
|
|
284
|
+
this.regimeClassifier = new MarketRegimeClassifier();
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Initialize the sparse bridge
|
|
288
|
+
*/
|
|
289
|
+
async initialize(config) {
|
|
290
|
+
if (config) {
|
|
291
|
+
this.config = { ...this.config, ...config };
|
|
292
|
+
}
|
|
293
|
+
try {
|
|
294
|
+
const wasmPath = await this.resolveWasmPath();
|
|
295
|
+
if (wasmPath) {
|
|
296
|
+
this.wasmModule = await this.loadWasmModule(wasmPath);
|
|
297
|
+
this.modelPtr = this.wasmModule.create_sparse_model(this.config.maxFeatures ?? 1000, 256, // Hidden dimension
|
|
298
|
+
this.config.sparsityThreshold ?? 0.9);
|
|
299
|
+
this.logger.info('Sparse WASM module initialized', {
|
|
300
|
+
maxFeatures: this.config.maxFeatures,
|
|
301
|
+
sparsityThreshold: this.config.sparsityThreshold,
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
this.logger.warn('WASM module not available, using JavaScript fallback');
|
|
306
|
+
}
|
|
307
|
+
this.initialized = true;
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
this.logger.warn('Failed to initialize WASM, using fallback', {
|
|
311
|
+
error: error instanceof Error ? error.message : String(error),
|
|
312
|
+
});
|
|
313
|
+
this.initialized = true;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Perform sparse inference on features
|
|
318
|
+
*/
|
|
319
|
+
async sparseInference(features, indices) {
|
|
320
|
+
if (!this.initialized) {
|
|
321
|
+
throw new Error('Sparse bridge not initialized');
|
|
322
|
+
}
|
|
323
|
+
if (this.wasmModule && this.modelPtr) {
|
|
324
|
+
return this.wasmModule.sparse_forward(this.modelPtr, features, indices);
|
|
325
|
+
}
|
|
326
|
+
// Fallback: Simple linear projection
|
|
327
|
+
const output = new Float32Array(128);
|
|
328
|
+
for (let i = 0; i < indices.length && i < output.length; i++) {
|
|
329
|
+
const idx = indices[i];
|
|
330
|
+
if (idx < features.length) {
|
|
331
|
+
output[i] = features[idx] * 0.1; // Simple scaling
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return output;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Detect anomalies in transactions
|
|
338
|
+
*/
|
|
339
|
+
async detectAnomalies(transactions, threshold) {
|
|
340
|
+
if (!this.initialized) {
|
|
341
|
+
throw new Error('Sparse bridge not initialized');
|
|
342
|
+
}
|
|
343
|
+
if (this.wasmModule && this.modelPtr) {
|
|
344
|
+
const numSamples = transactions.length;
|
|
345
|
+
const featureDim = transactions[0]?.length ?? 0;
|
|
346
|
+
if (numSamples === 0 || featureDim === 0) {
|
|
347
|
+
return new Uint32Array(0);
|
|
348
|
+
}
|
|
349
|
+
// Flatten transactions
|
|
350
|
+
const flatData = new Float32Array(numSamples * featureDim);
|
|
351
|
+
for (let i = 0; i < numSamples; i++) {
|
|
352
|
+
flatData.set(transactions[i], i * featureDim);
|
|
353
|
+
}
|
|
354
|
+
return this.wasmModule.detect_anomalies(this.modelPtr, flatData, numSamples, featureDim, threshold);
|
|
355
|
+
}
|
|
356
|
+
// Fallback: Use JavaScript anomaly detector
|
|
357
|
+
// Convert Float32Array[] to FinancialTransaction[] for the detector
|
|
358
|
+
// This is a simplified fallback - in production, pass actual transactions
|
|
359
|
+
const anomalyIndices = [];
|
|
360
|
+
for (let i = 0; i < transactions.length; i++) {
|
|
361
|
+
const txn = transactions[i];
|
|
362
|
+
// Simple anomaly heuristic based on feature magnitudes
|
|
363
|
+
const magnitude = Math.sqrt(txn.reduce((sum, v) => sum + v * v, 0));
|
|
364
|
+
if (magnitude > threshold * 10) {
|
|
365
|
+
anomalyIndices.push(i);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return new Uint32Array(anomalyIndices);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Classify market regime from market data
|
|
372
|
+
*/
|
|
373
|
+
async classifyRegime(marketData) {
|
|
374
|
+
if (!this.initialized) {
|
|
375
|
+
throw new Error('Sparse bridge not initialized');
|
|
376
|
+
}
|
|
377
|
+
if (this.wasmModule && this.modelPtr) {
|
|
378
|
+
const regimeCode = this.wasmModule.classify_regime(this.modelPtr, marketData, 20 // Window size
|
|
379
|
+
);
|
|
380
|
+
return {
|
|
381
|
+
regime: regimeCode,
|
|
382
|
+
confidence: 0.8, // WASM returns confidence separately in full implementation
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
// Fallback: Use JavaScript classifier
|
|
386
|
+
const prices = Array.from(marketData);
|
|
387
|
+
const result = this.regimeClassifier.classify(prices);
|
|
388
|
+
return {
|
|
389
|
+
regime: this.regimeToCode(result.regime),
|
|
390
|
+
confidence: result.confidence,
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Detect anomalies in financial transactions
|
|
395
|
+
*/
|
|
396
|
+
async detectTransactionAnomalies(transactions, threshold = 0.8) {
|
|
397
|
+
return this.anomalyDetector.detectAnomalies(transactions, threshold);
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Classify market regime from price data
|
|
401
|
+
*/
|
|
402
|
+
async classifyMarketRegime(prices, volumes) {
|
|
403
|
+
const { regime, confidence } = this.regimeClassifier.classify(prices, volumes);
|
|
404
|
+
const probabilities = this.regimeClassifier.getRegimeProbabilities(prices);
|
|
405
|
+
return { regime, confidence, probabilities };
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Cleanup resources
|
|
409
|
+
*/
|
|
410
|
+
destroy() {
|
|
411
|
+
if (this.wasmModule && this.modelPtr) {
|
|
412
|
+
this.wasmModule.free_model(this.modelPtr);
|
|
413
|
+
}
|
|
414
|
+
this.initialized = false;
|
|
415
|
+
}
|
|
416
|
+
// Private methods
|
|
417
|
+
async resolveWasmPath() {
|
|
418
|
+
try {
|
|
419
|
+
const module = await import(/* webpackIgnore: true */ 'ruvector-sparse-inference-wasm');
|
|
420
|
+
return module.default ?? null;
|
|
421
|
+
}
|
|
422
|
+
catch {
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
async loadWasmModule(wasmPath) {
|
|
427
|
+
const module = await import(wasmPath);
|
|
428
|
+
await module.default();
|
|
429
|
+
return module;
|
|
430
|
+
}
|
|
431
|
+
regimeToCode(regime) {
|
|
432
|
+
const codes = {
|
|
433
|
+
bull: 0,
|
|
434
|
+
bear: 1,
|
|
435
|
+
sideways: 2,
|
|
436
|
+
high_vol: 3,
|
|
437
|
+
crisis: 4,
|
|
438
|
+
recovery: 5,
|
|
439
|
+
};
|
|
440
|
+
return codes[regime] ?? 2;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Create a new sparse bridge instance
|
|
445
|
+
*/
|
|
446
|
+
export function createSparseBridge(config, logger) {
|
|
447
|
+
return new FinancialSparseBridge(config, logger);
|
|
448
|
+
}
|
|
449
|
+
export default FinancialSparseBridge;
|
|
450
|
+
//# sourceMappingURL=sparse-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sparse-bridge.js","sourceRoot":"","sources":["../../src/bridges/sparse-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAYH;;GAEG;AACH,MAAM,aAAa,GAAW;IAC5B,KAAK,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,mBAAmB,GAAG,EAAE,EAAE,IAAI,CAAC;IACrG,IAAI,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,GAAG,EAAE,EAAE,IAAI,CAAC;IACnG,IAAI,EAAE,CAAC,GAAW,EAAE,IAA8B,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,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,MAAM,CAAC,OAAO,EAAE,CAAC;QACvB,OAAO,MAA0B,CAAC;IACpC,CAAC;IAEO,YAAY,CAAC,MAAwB;QAC3C,MAAM,KAAK,GAAqC;YAC9C,IAAI,EAAE,CAAC;YACP,IAAI,EAAE,CAAC;YACP,QAAQ,EAAE,CAAC;YACX,QAAQ,EAAE,CAAC;YACX,MAAM,EAAE,CAAC;YACT,QAAQ,EAAE,CAAC;SACZ,CAAC;QACF,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAA8B,EAAE,MAAe;IAChF,OAAO,IAAI,qBAAqB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACnD,CAAC;AAED,eAAe,qBAAqB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Financial Risk Analysis Plugin
|
|
3
|
+
*
|
|
4
|
+
* A high-performance financial risk analysis plugin combining
|
|
5
|
+
* sparse inference for efficient market signal processing with
|
|
6
|
+
* graph neural networks for transaction network analysis.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Portfolio risk analysis (VaR, CVaR, Sharpe, Sortino)
|
|
10
|
+
* - Transaction anomaly detection using GNN
|
|
11
|
+
* - Market regime classification
|
|
12
|
+
* - Regulatory compliance checking (Basel III, MiFID II, AML)
|
|
13
|
+
* - Stress testing with historical and hypothetical scenarios
|
|
14
|
+
*
|
|
15
|
+
* Compliance:
|
|
16
|
+
* - SOX and MiFID II compliant audit logging
|
|
17
|
+
* - Deterministic execution for reproducibility
|
|
18
|
+
* - Role-based access control
|
|
19
|
+
* - Rate limiting for fair resource allocation
|
|
20
|
+
*
|
|
21
|
+
* @packageDocumentation
|
|
22
|
+
* @module @claude-flow/plugin-financial-risk
|
|
23
|
+
*/
|
|
24
|
+
export * from './types.js';
|
|
25
|
+
export { financialTools, toolHandlers, getTool, getToolNames, portfolioRiskTool, anomalyDetectTool, marketRegimeTool, complianceCheckTool, stressTestTool, } from './mcp-tools.js';
|
|
26
|
+
export { FinancialEconomyBridge, createEconomyBridge, PortfolioRiskCalculator, } from './bridges/economy-bridge.js';
|
|
27
|
+
export { FinancialSparseBridge, createSparseBridge, AnomalyDetector, MarketRegimeClassifier, } from './bridges/sparse-bridge.js';
|
|
28
|
+
import type { FinancialConfig, FinancialBridge, Logger } from './types.js';
|
|
29
|
+
/**
|
|
30
|
+
* Plugin metadata
|
|
31
|
+
*/
|
|
32
|
+
export declare const pluginMetadata: {
|
|
33
|
+
name: string;
|
|
34
|
+
version: string;
|
|
35
|
+
description: string;
|
|
36
|
+
author: string;
|
|
37
|
+
license: string;
|
|
38
|
+
category: string;
|
|
39
|
+
tags: string[];
|
|
40
|
+
wasmPackages: string[];
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Financial Risk Plugin class
|
|
44
|
+
*/
|
|
45
|
+
export declare class FinancialRiskPlugin {
|
|
46
|
+
private config;
|
|
47
|
+
private logger;
|
|
48
|
+
private bridge;
|
|
49
|
+
private initialized;
|
|
50
|
+
constructor(config?: Partial<FinancialConfig>, logger?: Logger);
|
|
51
|
+
/**
|
|
52
|
+
* Initialize the plugin
|
|
53
|
+
*/
|
|
54
|
+
initialize(): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Get all MCP tools
|
|
57
|
+
*/
|
|
58
|
+
getTools(): import("./types.js").MCPTool[];
|
|
59
|
+
/**
|
|
60
|
+
* Get the bridge for tool execution
|
|
61
|
+
*/
|
|
62
|
+
getBridge(): FinancialBridge;
|
|
63
|
+
/**
|
|
64
|
+
* Get plugin configuration
|
|
65
|
+
*/
|
|
66
|
+
getConfig(): FinancialConfig;
|
|
67
|
+
/**
|
|
68
|
+
* Cleanup resources
|
|
69
|
+
*/
|
|
70
|
+
destroy(): Promise<void>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create a new Financial Risk Plugin instance
|
|
74
|
+
*/
|
|
75
|
+
export declare function createFinancialPlugin(config?: Partial<FinancialConfig>, logger?: Logger): FinancialRiskPlugin;
|
|
76
|
+
/**
|
|
77
|
+
* Default export for plugin loader
|
|
78
|
+
*/
|
|
79
|
+
declare const _default: {
|
|
80
|
+
metadata: {
|
|
81
|
+
name: string;
|
|
82
|
+
version: string;
|
|
83
|
+
description: string;
|
|
84
|
+
author: string;
|
|
85
|
+
license: string;
|
|
86
|
+
category: string;
|
|
87
|
+
tags: string[];
|
|
88
|
+
wasmPackages: string[];
|
|
89
|
+
};
|
|
90
|
+
tools: import("./types.js").MCPTool[];
|
|
91
|
+
createPlugin: typeof createFinancialPlugin;
|
|
92
|
+
FinancialRiskPlugin: typeof FinancialRiskPlugin;
|
|
93
|
+
};
|
|
94
|
+
export default _default;
|
|
95
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,cAAc,YAAY,CAAC;AAG3B,OAAO,EACL,cAAc,EACd,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,GACf,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,sBAAsB,GACvB,MAAM,4BAA4B,CAAC;AAMpC,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAG3E;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;CAe1B,CAAC;AAEF;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,O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