一键导入
trader-portfolio-cg
Mean-variance portfolio optimization via Conjugate Gradient — 40-60× faster than the legacy Neumann path (ADR-126 Phase 3, ADR-123 Wedge 8)
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Mean-variance portfolio optimization via Conjugate Gradient — 40-60× faster than the legacy Neumann path (ADR-126 Phase 3, ADR-123 Wedge 8)
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | trader-portfolio-cg |
| description | Mean-variance portfolio optimization via Conjugate Gradient — 40-60× faster than the legacy Neumann path (ADR-126 Phase 3, ADR-123 Wedge 8) |
| allowed-tools | Bash Read mcp__ruflo-sublinear__solve mcp__ruflo__memory_store mcp__ruflo__memory_retrieve mcp__ruflo__memory_search mcp__ruflo__agentdb_pattern-search |
| argument-hint | [--portfolio-id ID] [--tolerance 1e-6] |
Solve the mean-variance optimization Σ · x = μ via Conjugate Gradient instead of the legacy Neumann series.
Why CG instead of Neumann (ADR-123 Wedge 8):
npx neural-trader --portfolio optimize)The covariance matrix Σ is symmetric positive-definite by construction (it's a Gram matrix on real returns), so CG is provably optimal — it converges in at most n iterations with no preconditioning, and typically far fewer when eigenvalues cluster.
Disable flag: set RUFLO_NEURAL_TRADER_DISABLE_CG=1 to skip the CG path entirely and fall through to step 4's legacy Neumann route. Useful for A/B validation or when an upstream covariance regression breaks SPD.
Steps:
Ensure neural-trader is available:
npm ls neural-trader 2>/dev/null || npm install --ignore-scripts neural-trader
Read the current covariance matrix Σ and expected-return vector μ from neural-trader's portfolio API:
# Primary path (preferred — clean JSON):
npx neural-trader --portfolio current --json
# Fallback paths if the --json flag is unavailable on the installed version:
npx neural-trader --portfolio current # parse the text output
# OR pull from AgentDB if a prior run stored the matrix there:
mcp__ruflo__memory_search({ query: "covariance matrix current", namespace: "trading-risk", limit: 1 })
The skill expects the response to include covariance: number[][] (n × n) and expectedReturns: number[] (length n).
Solve Σ · x = μ via CG (preferred path) when RUFLO_NEURAL_TRADER_DISABLE_CG is unset and the MCP tool is available:
mcp__ruflo-sublinear__solve({
matrix: COVARIANCE,
rhs: EXPECTED_RETURNS,
algorithm: "cg",
tolerance: 1e-6,
maxIterations: 200
})
The tool's expected output shape:
{ solution: number[], iterations: number, residual: number }
The skill's adapter (plugins/ruflo-neural-trader/src/sublinear-adapter.ts) detects MCP availability and falls back transparently to the embedded CG kernel (~50 LOC) when mcp__ruflo-sublinear__solve is not registered in the running runtime. Either way the math is identical — CG, dense form, n × n SPD covariance.
Fallback (legacy Neumann) — if step 3 reports degraded: true (non-SPD input, non-square matrix, MCP error) OR if RUFLO_NEURAL_TRADER_DISABLE_CG=1:
npx neural-trader --portfolio optimize
Capture the weights output and tag the artifact metadata with method: 'neumann-fallback' and a reason field.
Store the optimal weights to trading-risk namespace with full provenance metadata:
mcp__ruflo__memory_store({
key: "portfolio-weights-PORTFOLIO_ID-TIMESTAMP",
namespace: "trading-risk",
value: JSON.stringify({
weights: SOLUTION, // number[] from step 3 or 4
method: 'cg-sublinear' | 'cg-local' | 'neumann-fallback',
solver: 'ruflo-sublinear@0.1.0', // or 'neural-trader-cli' on fallback
iterations: ITERATIONS,
residual: RESIDUAL,
latencyMs: LATENCY_MS,
capturedAt: NEW_DATE_ISO,
reason: FALLBACK_REASON || null
})
})
The trading-risk namespace is canonical (ADR-126 Phase 1; the five-namespace alignment). Long-lived — no TTL — because portfolio weights are the audit trail Phase 4 will Ed25519-sign.
Cross-check against historical patterns (optional but recommended):
mcp__ruflo__agentdb_pattern-search({
query: "portfolio weights Sharpe regime:CURRENT_REGIME",
namespace: "trading-risk"
})
If the new weights differ by more than 30% in any single asset from the historical median, flag for human review before applying. This is a guard-rail, not a hard block.
Acceptance criteria (ADR-126 Phase 3):
||cg − neumann||_∞ < 1e-4 on a fixed seed.cg-sublinear, cg-local, and neumann-fallback.Refs:
plugins/ruflo-neural-trader/src/sublinear-adapter.ts (the adapter)plugins/ruflo-neural-trader/benchmarks/portfolio-cg.bench.ts (the measured numbers)Build or rebuild the ADR index + dependency graph in AgentDB by running the in-process `agentdb index` command (one cold-start, all surfaces in one pass — no per-record npx round-trips). Handles v3-style and plugin-style ADR formats.
Create a new Architecture Decision Record with sequential numbering and AgentDB registration
Hive Mind orchestration patterns — queen-led multi-agent coordination with Byzantine/Raft/Gossip/CRDT consensus, typed collective memory, dialectic council, and session checkpoint/resume. Use for decision-bearing work; use swarm-advanced for parallel execution without consensus.
Analyze git diffs for risk scoring, reviewer recommendations, and change classification
Detect missing test coverage and generate test suggestions
Hive Mind orchestration patterns — queen-led multi-agent coordination with Byzantine/Raft/Gossip/CRDT consensus, typed collective memory, dialectic council, and session checkpoint/resume. Use for decision-bearing work; use swarm-advanced for parallel execution without consensus.