Agent skill

Trader Portfolio Cg

by ruvnet in ruvnet/ruflo

Mean-variance portfolio optimization via Conjugate Gradient — 40-60× faster than the legacy Neumann path (ADR-126 Phase 3, ADR-123 Wedge 8)

MITAuto-check: notesDevelopment

Install Trader Portfolio Cg

skills CLI
$ npx skills add ruvnet/ruflo --skill trader-portfolio-cg -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install ruvnet/ruflo trader-portfolio-cg --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/ruvnet/ruflo.git skills-src && mkdir -p .claude/skills && cp -r skills-src/plugins/ruflo-neural-trader/skills/trader-portfolio-cg .claude/skills/trader-portfolio-cg && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
trader-portfolio-cg
GitHub stars
74k
Token cost
~1.7k tokens
SKILL.md length
524 words
Files
1
Skills in repo
265
Repo updated
First seen
Licence
MIT

At a glance

Mean-variance portfolio optimization via Conjugate Gradient — 40-60× faster than the legacy Neumann path (ADR-126 Phase 3, ADR-123 Wedge 8)

  • Works in 6 steps: Ensure neural-trader is available → Read the current covariance matrix Σ and… → Solve Σ · x = μ via the SublinearAdapter… → …
  • Tasks that involve Architecture decision records
  • Calls npx and npm
  • Tasks that involve Trading and backtesting

What it does

Trader Portfolio Cg is an agent skill from ruvnet/ruflo. Mean-variance portfolio optimization via Conjugate Gradient — 40-60× faster than the legacy Neumann path (ADR-126 Phase 3, ADR-123 Wedge 8)

Its SKILL.md is about 1.7k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Development, covering Architecture decision records and Trading and backtesting. The repository describes itself as: 🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory…. The licence is MIT.

When your agent uses it

  • Tasks that involve Architecture decision records
  • Tasks that involve Trading and backtesting

Example prompts

  • “/trader-portfolio-cg”

Requirements

  • Node.js
  • Pre-approved tools (allowed-tools): Bash, Read, mcp__ruflo-sublinear__solve, mcp__plugin_ruflo-core_ruflo__memory_store, mcp__plugin_ruflo-core_ruflo__memory_retrieve, mcp__plugin_ruflo-core_ruflo__memory_search, mcp__plugin_ruflo-core_ruflo__agentdb_pattern-search

Workflow steps

6 steps, taken from the first numbered list in SKILL.md.

  1. Ensure neural-trader is available
  2. Read the current covariance matrix Σ and expected-return vector μ from neural-trader's portfolio API
  3. Solve Σ · x = μ via the SublinearAdapter (preferred path) when RUFLO_NEURAL_TRADER_DISABLE_CG is unset
  4. Fallback (legacy Neumann) — if step 3 reports degraded: true (non-SPD input, non-square matrix, MCP error) OR if…
  5. Store the optimal weights to trading-risk namespace with full provenance metadata. Take method and solver straight from the adapter's…
  6. Cross-check against historical patterns (optional but recommended)

What it can do on your machine

Read from SKILL.md and the folder at commit 6c04654. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • Bash
    • Read
    • mcp__ruflo-sublinear__solve
    • mcp__plugin_ruflo-core_ruflo__memory_store
    • mcp__plugin_ruflo-core_ruflo__memory_retrieve
    • mcp__plugin_ruflo-core_ruflo__memory_search
    • mcp__plugin_ruflo-core_ruflo__agentdb_pattern-search

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • npx
    • npm

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use npx and npm, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Trader Portfolio Cg loads about 1.7k tokens when it runs. Until then it costs about 40 tokens; SKILL.md has 524 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~40
When it runs · the whole SKILL.md, loaded when a task matches
~1.7k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check: notes

The automated check noted patterns worth knowing about, such as sudo or a known installer.

  • NotePre-approves every shell command (allowed-tools: Bash)SKILL.md
    allowed-tools: Bash, Read, mcp__ruflo-sublinear__solve, mcp__plugin_ruflo-core_ruflo__memory_store, mcp__plugin_ruf

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from ruvnet/ruflo at commit 6c04654, republished under its MIT licence (© ruvnet). 524 words, ~1,686 tokens.

Download SKILL.mdSave it as .claude/skills/trader-portfolio-cg/SKILL.md (or your agent's skills folder).
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__plugin_ruflo-core_ruflo__memory_store, mcp__plugin_ruflo-core_ruflo__memory_retrieve, mcp__plugin_ruflo-core_ruflo__memory_search, mcp__plugin_ruflo-core_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):

  • Neumann series: ~50 µs at n=256 (legacy npx neural-trader --portfolio optimize)
  • Conjugate Gradient: ~816 ns at n=256 (this skill)
  • Measured speedup: 40-60×; parity within 1e-4 on a fixed seed.

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:

  1. Ensure neural-trader is available:

    bash
    npm ls neural-trader 2>/dev/null || npm install --ignore-scripts neural-trader
  2. Read the current covariance matrix Σ and expected-return vector μ from neural-trader's portfolio API:

    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).

  3. Solve Σ · x = μ via the SublinearAdapter (preferred path) when 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 }
  4. 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:

    bash
    npx neural-trader --portfolio optimize

    Capture the weights output and tag the artifact metadata with method: 'neumann-fallback' and a reason field.

  5. Store the optimal weights to 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.

  6. Cross-check against historical patterns (optional but recommended):

    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.

Show full SKILL.md (86 more words)Show less

Acceptance criteria (ADR-126 Phase 3):

  • Latency < 1 ms on n = 256 covariance (local JS CG); native path target 40-60× faster (816 ns native vs 50 µs Neumann per sublinear-time-solver@1.7.0).
  • Parity with legacy Neumann within ||cg − neumann||_∞ < 1e-4 on a fixed seed.
  • Fallback path engages cleanly when native MCP unavailable / covariance non-SPD.
  • Artifact metadata distinguishes cg-sublinear-native, cg-local, and neumann-fallback.

Refs:

  • ADR-126 Phase 3 (this skill's authoring ADR)
  • ADR-123 §162 Row 8 (Wedge 8 speedup claim)
  • ADR-123 §262-289 (the SublinearAdapter contract)
  • plugins/ruflo-neural-trader/src/sublinear-adapter.ts (the adapter)
  • plugins/ruflo-neural-trader/benchmarks/portfolio-cg.bench.ts (the measured numbers)

© ruvnet, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in plugins/ruflo-neural-trader/skills/trader-portfolio-cg of ruvnet/ruflo.

Open the folder on GitHubat commit 6c04654

Compare with similar skills

Trader Portfolio Cg next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Trader Portfolio Cg compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Trader Portfolio Cg this skillruvnet/ruflo74k—~1.7kAutomated safety check: NotesMIT
Longbridge Market Datasickn33/agentic-awesome-skills47k1 repos~1.7kAutomated safety check: PassMIT
Rsigmatimescale/rsigma166—~1.2kAutomated safety check: PassMIT
Version Bumpmarketcalls/openalgo2.8k—~1.8kAutomated safety check: PassAGPL-3.0
Handoverk1ein-chen/Harness-Starter119—~752Automated safety check: PassMIT
Longbridge Market Datahelsome/folio2711 repos~1.6kAutomated safety check: PassMIT

Similar skills

  • Longbridge Market Data

    sickn33/agentic-awesome-skills

    Real-time quotes, K-line charts, order book, trade ticks, intraday capital flow, market sentiment temperature, trading session schedule, security lists, exchange rates, and IPO calendar for…

    47k GitHub starsUsed in 1 repo~1.7k tokens
    Business, Finance & HRAuto-check passed
  • Rsigma

    timescale/rsigma

    Use the rsigma CLI and MCP server: engine eval, engine daemon, rule lint, rule draft, rule tune, rule backtest, backend convert, mcp serve.

    166 GitHub stars~1.2k tokensUpdated today
    DevelopmentAuto-check passed
  • Version Bump

    marketcalls/openalgo

    Bump a version in the OpenAlgo repo. An agent skill from marketcalls/openalgo.

    2.8k GitHub stars~1.8k tokensUpdated yesterday
    DevelopmentAuto-check passed
  • Handover

    k1ein-chen/Harness-Starter

    将当前会话中的技术决策、运维流程或阶段性研发进展,归档为标准工程文档(ADR / SOP / Handover),并自动更新模块内的 README 归档索引。

    119 GitHub stars~752 tokensUpdated 17 days ago
    DevelopmentAuto-check passed
  • Real-time quotes, K-line charts, order book, trade ticks, intraday capital flow, market sentiment temperature, trading session schedule, security lists, exchange rates, and IPO calendar for…

    271 GitHub starsUsed in 1 repo~1.6k tokens
    Business, Finance & HRAuto-check passed
  • Metrics Definition

    Owl-Listener/designer-skills

    Define UX metrics and KPIs that connect design decisions to measurable outcomes.

    2.9k GitHub starsUsed in 1 repo~311 tokens
    DevelopmentAuto-check passed

More from ruvnet/ruflo

All 265 skills in this repo
  • Stores, searches, and retrieves successful patterns with HNSW-indexed semantic search so agents can reuse past solutions instead of relearning them.

    74k GitHub starsUsed in 1 repo~830 tokens
    Auto-check passed
  • Sets up and drives Ruflo, an npm-installed orchestration layer for multi-agent swarms, persistent memory, routing, hooks and its MCP tool catalog.

    74k GitHub starsUsed in 1 repo~975 tokens
    Auto-check passed
  • Runs claude-flow CLI security scans for input validation, path traversal, SQL injection, XSS, hardcoded secrets and known CVEs, and writes an audit report.

    74k GitHub starsUsed in 1 repo~823 tokens
    Auto-check passed
  • Applies the SPARC method (specification, pseudocode, architecture, refinement, completion) with 17 specialized modes and multi-agent orchestration, from research to deployment.

    74k GitHub starsUsed in 1 repo~829 tokens
    Auto-check passed
  • Coordinates a hierarchical swarm of specialized agents through the claude-flow CLI for work that spans several files or modules at once.

    74k GitHub starsUsed in 1 repo~779 tokens
    Auto-check passed
  • Finds models on the Hugging Face router that lack descriptions in chat-ui's prod.yaml and dev.yaml, researches each one and adds short descriptions.

    74k GitHub starsUsed in 1 repo~600 tokens
    Auto-check passed

Questions about Trader Portfolio Cg

What does Trader Portfolio Cg do?

Mean-variance portfolio optimization via Conjugate Gradient — 40-60× faster than the legacy Neumann path (ADR-126 Phase 3, ADR-123 Wedge 8). Trader Portfolio Cg is an agent skill from ruvnet/ruflo.

When should I use Trader Portfolio Cg?

Trader Portfolio Cg fits situations like: tasks that involve Architecture decision records; tasks that involve Trading and backtesting.

How do I install Trader Portfolio Cg in Claude Code?

Run `npx skills add ruvnet/ruflo --skill trader-portfolio-cg -a claude-code`. Or copy the skill folder (plugins/ruflo-neural-trader/skills/trader-portfolio-cg in ruvnet/ruflo) into .claude/skills/trader-portfolio-cg in your project. Claude Code loads it when a task matches its description.

How do I install Trader Portfolio Cg in Codex?

Run `npx skills add ruvnet/ruflo --skill trader-portfolio-cg -a codex`. Or copy the skill folder (plugins/ruflo-neural-trader/skills/trader-portfolio-cg in ruvnet/ruflo) into .agents/skills/trader-portfolio-cg in your project. Codex loads it when a task matches its description.

Can I use Trader Portfolio Cg in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add ruvnet/ruflo --skill trader-portfolio-cg -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/trader-portfolio-cg, .gemini/skills/trader-portfolio-cg, .github/skills/trader-portfolio-cg and .opencode/skills/trader-portfolio-cg in your project.

What does Trader Portfolio Cg need to run?

Going by SKILL.md and its folder, Trader Portfolio Cg needs the command-line tools its instructions call (npx and npm). Our summary lists: Node.js. Its frontmatter pre-approves these tools: Bash, Read, mcp__ruflo-sublinear__solve, mcp__plugin_ruflo-core_ruflo__memory_store, mcp__plugin_ruflo-core_ruflo__memory_retrieve, mcp__plugin_ruflo-core_ruflo__memory_search, mcp__plugin_ruflo-core_ruflo__agentdb_pattern-search.

Does Trader Portfolio Cg access the network?

SKILL.md contains no URLs. Its commands use npx and npm, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Trader Portfolio Cg safe to install?

Our automated static check of SKILL.md found notes only (pre-approves every shell command (allowed-tools: bash)), nothing it rates as a warning. It is not a guarantee. Review the folder before installing.

What licence does Trader Portfolio Cg use?

Trader Portfolio Cg is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Trader Portfolio Cg use?

About 1.7k tokens (SKILL.md is roughly 6.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Trader Portfolio Cg?

Skills that share tags, products or a category with Trader Portfolio Cg: Longbridge Market Data (sickn33/agentic-awesome-skills, 47k stars), Rsigma (timescale/rsigma, 166 stars), Version Bump (marketcalls/openalgo, 2.8k stars) and Handover (k1ein-chen/Harness-Starter, 119 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Trader Portfolio Cg?

ruvnet (a GitHub user) maintains it in ruvnet/ruflo, which has 74,222 GitHub stars. The repository holds 265 skills in this directory. The repository was last updated on October 10, 2026.

Source: ruvnet/ruflo on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.