@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/dist/index.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
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 all types
|
|
25
|
+
export * from './types.js';
|
|
26
|
+
// Export MCP tools
|
|
27
|
+
export { financialTools, toolHandlers, getTool, getToolNames, portfolioRiskTool, anomalyDetectTool, marketRegimeTool, complianceCheckTool, stressTestTool, } from './mcp-tools.js';
|
|
28
|
+
// Export bridges
|
|
29
|
+
export { FinancialEconomyBridge, createEconomyBridge, PortfolioRiskCalculator, } from './bridges/economy-bridge.js';
|
|
30
|
+
export { FinancialSparseBridge, createSparseBridge, AnomalyDetector, MarketRegimeClassifier, } from './bridges/sparse-bridge.js';
|
|
31
|
+
// Import for plugin definition
|
|
32
|
+
import { financialTools } from './mcp-tools.js';
|
|
33
|
+
import { FinancialEconomyBridge } from './bridges/economy-bridge.js';
|
|
34
|
+
import { FinancialSparseBridge } from './bridges/sparse-bridge.js';
|
|
35
|
+
import { DEFAULT_FINANCIAL_CONFIG } from './types.js';
|
|
36
|
+
/**
|
|
37
|
+
* Plugin metadata
|
|
38
|
+
*/
|
|
39
|
+
export const pluginMetadata = {
|
|
40
|
+
name: '@claude-flow/plugin-financial-risk',
|
|
41
|
+
version: '3.0.0-alpha.1',
|
|
42
|
+
description: 'High-performance financial risk analysis with portfolio risk, anomaly detection, and compliance checking',
|
|
43
|
+
author: 'rUv',
|
|
44
|
+
license: 'MIT',
|
|
45
|
+
category: 'finance',
|
|
46
|
+
tags: ['finance', 'risk', 'portfolio', 'var', 'anomaly-detection', 'compliance', 'basel3', 'mifid2'],
|
|
47
|
+
wasmPackages: [
|
|
48
|
+
'micro-hnsw-wasm',
|
|
49
|
+
'ruvector-sparse-inference-wasm',
|
|
50
|
+
'ruvector-gnn-wasm',
|
|
51
|
+
'ruvector-economy-wasm',
|
|
52
|
+
'ruvector-learning-wasm',
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Financial Risk Plugin class
|
|
57
|
+
*/
|
|
58
|
+
export class FinancialRiskPlugin {
|
|
59
|
+
config;
|
|
60
|
+
logger;
|
|
61
|
+
bridge;
|
|
62
|
+
initialized = false;
|
|
63
|
+
constructor(config, logger) {
|
|
64
|
+
this.config = { ...DEFAULT_FINANCIAL_CONFIG, ...config };
|
|
65
|
+
this.logger = logger ?? {
|
|
66
|
+
debug: (msg, meta) => console.debug(`[financial-plugin] ${msg}`, meta),
|
|
67
|
+
info: (msg, meta) => console.info(`[financial-plugin] ${msg}`, meta),
|
|
68
|
+
warn: (msg, meta) => console.warn(`[financial-plugin] ${msg}`, meta),
|
|
69
|
+
error: (msg, meta) => console.error(`[financial-plugin] ${msg}`, meta),
|
|
70
|
+
};
|
|
71
|
+
this.bridge = {
|
|
72
|
+
economy: undefined,
|
|
73
|
+
sparse: undefined,
|
|
74
|
+
initialized: false,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Initialize the plugin
|
|
79
|
+
*/
|
|
80
|
+
async initialize() {
|
|
81
|
+
if (this.initialized)
|
|
82
|
+
return;
|
|
83
|
+
this.logger.info('Initializing Financial Risk Plugin');
|
|
84
|
+
try {
|
|
85
|
+
// Initialize Economy bridge
|
|
86
|
+
const economyBridge = new FinancialEconomyBridge({ randomSeed: this.config.risk.defaultConfidenceLevel }, this.logger);
|
|
87
|
+
await economyBridge.initialize();
|
|
88
|
+
this.bridge.economy = economyBridge;
|
|
89
|
+
// Initialize Sparse bridge
|
|
90
|
+
const sparseBridge = new FinancialSparseBridge({ sparsityThreshold: this.config.anomaly.defaultThreshold }, this.logger);
|
|
91
|
+
await sparseBridge.initialize();
|
|
92
|
+
this.bridge.sparse = sparseBridge;
|
|
93
|
+
this.bridge.initialized = true;
|
|
94
|
+
this.initialized = true;
|
|
95
|
+
this.logger.info('Financial Risk Plugin initialized successfully', {
|
|
96
|
+
economyReady: economyBridge.initialized,
|
|
97
|
+
sparseReady: sparseBridge.initialized,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
this.logger.error('Failed to initialize Financial Risk Plugin', {
|
|
102
|
+
error: error instanceof Error ? error.message : String(error),
|
|
103
|
+
});
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get all MCP tools
|
|
109
|
+
*/
|
|
110
|
+
getTools() {
|
|
111
|
+
return financialTools;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get the bridge for tool execution
|
|
115
|
+
*/
|
|
116
|
+
getBridge() {
|
|
117
|
+
return this.bridge;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Get plugin configuration
|
|
121
|
+
*/
|
|
122
|
+
getConfig() {
|
|
123
|
+
return this.config;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Cleanup resources
|
|
127
|
+
*/
|
|
128
|
+
async destroy() {
|
|
129
|
+
if (this.bridge.economy) {
|
|
130
|
+
this.bridge.economy.destroy();
|
|
131
|
+
}
|
|
132
|
+
if (this.bridge.sparse) {
|
|
133
|
+
this.bridge.sparse.destroy();
|
|
134
|
+
}
|
|
135
|
+
this.bridge.initialized = false;
|
|
136
|
+
this.initialized = false;
|
|
137
|
+
this.logger.info('Financial Risk Plugin destroyed');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Create a new Financial Risk Plugin instance
|
|
142
|
+
*/
|
|
143
|
+
export function createFinancialPlugin(config, logger) {
|
|
144
|
+
return new FinancialRiskPlugin(config, logger);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Default export for plugin loader
|
|
148
|
+
*/
|
|
149
|
+
export default {
|
|
150
|
+
metadata: pluginMetadata,
|
|
151
|
+
tools: financialTools,
|
|
152
|
+
createPlugin: createFinancialPlugin,
|
|
153
|
+
FinancialRiskPlugin,
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,mBAAmB;AACnB,cAAc,YAAY,CAAC;AAE3B,mBAAmB;AACnB,OAAO,EACL,cAAc,EACd,YAAY,EACZ,OAAO,EACP,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,GACf,MAAM,gBAAgB,CAAC;AAExB,iBAAiB;AACjB,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;AAEpC,+BAA+B;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEtD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,oCAAoC;IAC1C,OAAO,EAAE,eAAe;IACxB,WAAW,EAAE,0GAA0G;IACvH,MAAM,EAAE,KAAK;IACb,OAAO,EAAE,KAAK;IACd,QAAQ,EAAE,SAAS;IACnB,IAAI,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,QAAQ,EAAE,QAAQ,CAAC;IACp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AAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,CAAC,OAAkC,CAAC,OAAO,EAAE,CAAC;QAC5D,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;YACtB,IAAI,CAAC,MAAM,CAAC,MAAgC,CAAC,OAAO,EAAE,CAAC;QAC1D,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,WAAW,GAAG,KAAK,CAAC;QAChC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;IACtD,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACnC,MAAiC,EACjC,MAAe;IAEf,OAAO,IAAI,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,eAAe;IACb,QAAQ,EAAE,cAAc;IACxB,KAAK,EAAE,cAAc;IACrB,YAAY,EAAE,qBAAqB;IACnC,mBAAmB;CACpB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Financial Risk MCP Tools
|
|
3
|
+
*
|
|
4
|
+
* High-performance financial risk analysis tools including:
|
|
5
|
+
* - portfolio-risk: Calculate VaR, CVaR, Sharpe, and other risk metrics
|
|
6
|
+
* - anomaly-detect: Detect anomalies in transactions using GNN
|
|
7
|
+
* - market-regime: Classify current market regime using pattern matching
|
|
8
|
+
* - compliance-check: Verify regulatory compliance (Basel III, MiFID II, etc.)
|
|
9
|
+
* - stress-test: Run stress testing scenarios on portfolios
|
|
10
|
+
*/
|
|
11
|
+
import type { MCPTool, MCPToolResult, ToolContext } from './types.js';
|
|
12
|
+
export declare const portfolioRiskTool: MCPTool;
|
|
13
|
+
export declare const anomalyDetectTool: MCPTool;
|
|
14
|
+
export declare const marketRegimeTool: MCPTool;
|
|
15
|
+
export declare const complianceCheckTool: MCPTool;
|
|
16
|
+
export declare const stressTestTool: MCPTool;
|
|
17
|
+
export declare const financialTools: MCPTool[];
|
|
18
|
+
export declare const toolHandlers: Map<string, (input: Record<string, unknown>, context?: ToolContext) => Promise<MCPToolResult>>;
|
|
19
|
+
export declare function getTool(name: string): MCPTool | undefined;
|
|
20
|
+
export declare function getToolNames(): string[];
|
|
21
|
+
export default financialTools;
|
|
22
|
+
//# sourceMappingURL=mcp-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-tools.d.ts","sourceRoot":"","sources":["../src/mcp-tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,OAAO,EACP,aAAa,EACb,WAAW,EAQZ,MAAM,YAAY,CAAC;AA8NpB,eAAO,MAAM,iBAAiB,EAAE,OAmB/B,CAAC;AAsHF,eAAO,MAAM,iBAAiB,EAAE,OAkB/B,CAAC;AAwJF,eAAO,MAAM,gBAAgB,EAAE,OAkB9B,CAAC;AAqIF,eAAO,MAAM,mBAAmB,EAAE,OAmBjC,CAAC;AAsIF,eAAO,MAAM,cAAc,EAAE,OAkB5B,CAAC;AAMF,eAAO,MAAM,cAAc,EAAE,OAAO,EAMnC,CAAC;AAEF,eAAO,MAAM,YAAY,gGAMvB,CAAC;AAEH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAEzD;AAED,wBAAgB,YAAY,IAAI,MAAM,EAAE,CAEvC;AAED,eAAe,cAAc,CAAC"}
|