Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Mean-variance portfolio optimization via Conjugate Gradient — 40-60× faster than the legacy Neumann path (ADR-126 Phase 3, ADR-123 Wedge 8)
.claude/skills/ruvnet-trader-portfolio-cg/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-07 | ✗→✓ | ▲ Improved | 14% | 0% |
| case-08 | ✗→✓ | ▲ Improved | 21% | 0% |
| case-10 | ✗→✓ | ▲ Improved | 134% | 0% |
| case-11 | ✗→✓ | ▲ Improved | 72% | 0% |
| case-12 | ✗→✓ | ▲ Improved | 73% | 0% |
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.
Native dispatch flag: set RUFLO_SUBLINEAR_NATIVE=1 to force the adapter to attempt the native mcp__ruflo-sublinear__solve path even when globalThis doesn't expose the tool (e.g. when the harness mounts it via a different transport). On any native-dispatch failure the adapter cleanly falls back to the local JS CG and records method: 'cg-local' in the artifact metadata — so the regression is auditable.
Steps:
bash npm ls neural-trader 2>/dev/null || npm install --ignore-scripts neural-trader
bash # 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: text mcp__plugin_ruflo-core_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).
RUFLO_NEURAL_TRADER_DISABLE_CG is unset:js import { sublinearAdapter } from '../../src/sublinear-adapter.mjs'; const result = await sublinearAdapter.solveCG(COVARIANCE, EXPECTED_RETURNS, { tolerance: 1e-6, maxIterations: 200, }); // result.solution — optimal weights (number[]) // result.iterations — CG iterations executed // result.residual — final ||A·x − b||₂ // result.latencyMs — wall-clock latency // result.method — 'cg-sublinear-native' | 'cg-local' <-- READ THIS // result.solver — 'sublinear-time-solver@1.7.0' | 'local-js-cg' // result.degraded — true if input failed SPD checks (fall back to step 4) The adapter does the dispatch itself: it probes for mcp__ruflo-sublinear__solve on globalThis (and honours RUFLO_SUBLINEAR_NATIVE=1 as a manual override), routes through the native kernel when reachable, and falls back transparently to the embedded ~50-LOC JS CG when not. The math is identical either way — CG, dense form, n × n SPD covariance. The operator reads result.method to know which backend produced the artifact.
The native MCP tool's wire shape (for direct callers who want to bypass the adapter): text mcp__ruflo-sublinear__solve({ matrix: COVARIANCE, rhs: EXPECTED_RETURNS, algorithm: "cg", tolerance: 1e-6, maxIterations: 200 }) Output: ts { solution: number[], iterations: number, residual: number }
degraded: true (non-SPD input, non-square matrix, MCP error) OR if RUFLO_NEURAL_TRADER_DISABLE_CG=1:bash npx neural-trader --portfolio optimize Capture the weights output and tag the artifact metadata with method: 'neumann-fallback' and a reason field.
trading-risk namespace with full provenance metadata. Take method and solver straight from the adapter's result so the operator can verify which backend ran:text mcp__plugin_ruflo-core_ruflo__memory_store({ key: "portfolio-weights-PORTFOLIO_ID-TIMESTAMP", namespace: "trading-risk", value: JSON.stringify({ weights: result.solution, // number[] from step 3 (or weights from step 4 fallback) method: result.method, // 'cg-sublinear-native' | 'cg-local' | 'neumann-fallback' solver: result.solver, // 'sublinear-time-solver@1.7.0' | 'local-js-cg' | 'neural-trader-cli' iterations: result.iterations, residual: result.residual, latencyMs: result.latencyMs, 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.
text mcp__plugin_ruflo-core_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-native, 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)| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-04 | pass→pass | 15,365 | 10,466 | -32% | 1 | 1 | 0% | 3,108 | 4,044 | +30% | 0 | 0 | — |
case-01 | fail→fail | 12,944 | 4,914 | -62% | 1 | 1 | 0% | 2,733 | 2,123 | -22% | 0 | 0 | — |
case-02 | fail→fail | 12,394 | 6,784 | -45% | 1 | 1 | 0% | 2,559 | 2,177 | -15% | 0 | 0 | — |
case-03 | fail→fail | 21,956 | 7,126 | -68% | 1 | 1 | 0% | 4,505 | 2,512 | -44% | 0 | 0 | — |
case-05 | pass→pass | 16,148 | 16,940 | +5% | 1 | 1 | 0% | 3,411 | 5,307 | +56% | 0 | 0 | — |
case-06 | pass→pass | 15,666 | 21,588 | +38% | 1 | 1 | 0% | 2,878 | 5,605 | +95% | 0 | 0 | — |
case-07 | fail→pass | 23,424 | 2,152 | -91% | 1 | 1 | 0% | 1,937 | 2,208 | +14% | 0 | 0 | — |
case-08 | fail→pass | 10,669 | 2,400 | -78% | 1 | 1 | 0% | 1,858 | 2,249 | +21% | 0 | 0 | — |
case-09 | fail→fail | 6,512 | 3,078 | -53% | 1 | 1 | 0% | 1,199 | 2,406 | +101% | 0 | 0 | — |
case-10 | fail→pass | 13,019 | 1,594 | -88% | 1 | 1 | 0% | 907 | 2,126 | +134% | 0 | 0 | — |
case-11 | fail→pass | 18,066 | 1,968 | -89% | 1 | 1 | 0% | 1,294 | 2,230 | +72% | 0 | 0 | — |
case-12 | fail→pass | 21,832 | 2,022 | -91% | 1 | 1 | 0% | 1,278 | 2,214 | +73% | 0 | 0 | — |
case-13 | fail→pass | 23,317 | 2,183 | -91% | 1 | 1 | 0% | 1,625 | 2,225 | +37% | 0 | 0 | — |
case-14 | fail→pass | 10,630 | 1,685 | -84% | 1 | 1 | 0% | 1,707 | 2,114 | +24% | 0 | 0 | — |
case-15 | fail→pass | 10,485 | 1,626 | -84% | 1 | 1 | 0% | 1,666 | 2,071 | +24% | 0 | 0 | — |
case-16 | fail→pass | 8,969 | 2,357 | -74% | 1 | 1 | 0% | 1,553 | 2,311 | +49% | 0 | 0 | — |
case-17 | fail→pass | 7,524 | 2,603 | -65% | 1 | 1 | 0% | 1,395 | 2,382 | +71% | 0 | 0 | — |
case-18 | fail→pass | 12,655 | 2,653 | -79% | 1 | 1 | 0% | 735 | 2,207 | +200% | 0 | 0 | — |
case-19 | fail→pass | 17,141 | 1,666 | -90% | 1 | 1 | 0% | 973 | 2,109 | +117% | 0 | 0 | — |
case-20 | fail→pass | 66,251 | 1,585 | -98% | 1 | 1 | 0% | 901 | 2,120 | +135% | 0 | 0 | — |
case-21 | fail→pass | 4,419 | 1,470 | -67% | 1 | 1 | 0% | 869 | 2,111 | +143% | 0 | 0 | — |
case-22 | fail→pass | 17,048 | 1,923 | -89% | 1 | 1 | 0% | 1,498 | 2,230 | +49% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 10 counted toward the lift figure. The other 12 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +68 percentage points is the difference between those two pass rates over the 10 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.