trader-portfolio-cg

Solves mean-variance portfolio optimization via Conjugate Gradient on covariance matrices.

70.1k|8.4k|Updated Jun 2, 2025
One-click install
npx skills add https://github.com/ruvnet/claude-flow --skill trader-portfolio-cg
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: trader-portfolio-cg
Source: https://github.com/ruvnet/claude-flow/tree/main/plugins/ruflo-neural-trader/skills/trader-portfolio-cg
Command: npx skills add https://github.com/ruvnet/claude-flow --skill trader-portfolio-cg

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires neural-trader.

What problem does it solve?

Mean-variance portfolio optimization requires solving the linear system Σ·x = μ, and the legacy Neumann series approach takes roughly 50 µs at n=256. This Skill replaces that path with Conjugate Gradient, which exploits the symmetric positive-definite structure of covariance matrices to converge in far fewer iterations, achieving a measured 40-60× speedup while maintaining parity within 1e-4 of the legacy result.

Core Features & Use Cases

  • Conjugate Gradient Solver: Solves Σ·x = μ through a SublinearAdapter that dispatches to a native MCP solver when available and falls back to an embedded local JS CG implementation otherwise.
  • Graceful Degradation: Automatically falls back to the legacy Neumann CLI path when input fails SPD checks, the matrix is non-square, or the disable flag RUFLO_NEURAL_TRADER_DISABLE_CG=1 is set.
  • Auditable Provenance: Stores optimal weights in the trading-risk memory namespace with method, solver, iterations, residual, and latency metadata so operators can verify which backend produced each artifact.
  • Use Case: A quantitative trading operator needs to rebalance a 256-asset portfolio under a latency budget. The skill reads the current covariance matrix and expected returns from neural-trader, solves for optimal weights in under 1 ms, cross-checks against historical patterns, and flags deviations over 30% for human review.

Quick Start

Ask the agent to optimize the current portfolio using Conjugate Gradient with a tolerance of 1e-6 and store the resulting weights with full provenance metadata.

Frequently Asked Questions about trader-portfolio-cg

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I solve mean-variance portfolio optimization with Conjugate Gradient?

Read the covariance matrix and expected returns from neural-trader's portfolio API, then call the SublinearAdapter solveCG method with a tolerance like 1e-6. The adapter returns optimal weights, iteration count, residual, and which backend produced the result.

Conjugate Gradient vs Neumann series for portfolio optimization?

Conjugate Gradient runs in about 816 ns at n=256 versus roughly 50 µs for the Neumann series, a measured 40-60× speedup. Because covariance matrices are symmetric positive-definite, CG converges in at most n iterations and matches Neumann output within 1e-4.

What happens if the covariance matrix is not positive definite?

The adapter marks the result as degraded when input fails SPD checks or is non-square, and the skill falls back to the legacy Neumann CLI path. The fallback artifact is tagged with method neumann-fallback and a reason field for auditing.

Can I disable the Conjugate Gradient path for A/B testing?

Yes, set the environment variable RUFLO_NEURAL_TRADER_DISABLE_CG=1 to skip the CG path entirely and route through the legacy Neumann optimizer. This is useful for A/B validation or when an upstream covariance regression breaks SPD.

Why does the solver fall back to local JS instead of the native MCP tool?

Fallback occurs when the native mcp__ruflo-sublinear__solve tool is not reachable on globalThis and no override is set. The adapter transparently uses an embedded JS CG implementation and records method cg-local so the regression remains auditable.