Skills Agentes

Trader Portfolio Cg

Optimización de cartera media-varianza vía Gradiente Conjugado, 40-60x más rápido que la ruta Neumann heredada.

Solicitabash 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
Estrellas
69.4k

en todo el repo

Actividad
54

0–100, la ruta de este skill

Actualizado
el mes pasado

último commit aquí

Commits
1

últimos 90 días

Contexto
1.7k tok

36 tok en reposo

Paquete
1 archivo

7 KB

Instalar

Funciona con cualquier agente que lea SKILL.md

npx -y skills add ruvnet/ruflo --skill trader-portfolio-cg --agent claude-code

Se instala solo en este repositorio.

Qué hace

  • Resuelve la optimización media-varianza (Σ·x=μ) con Gradiente Conjugado en vez del método Neumann heredado.
  • Prueba primero el solver nativo vía MCP y cae automáticamente al CG local en JS si falla o no está disponible.
  • Si la entrada falla las comprobaciones de definición positiva, cae al método Neumann heredado.
  • Guarda los pesos óptimos con procedencia completa (método, solver, iteraciones, residual) en trading-risk.

Úsalo cuando

  • Necesitas optimizar la asignación de una cartera y quieres el método más rápido disponible con fallback seguro.

No lo uses cuando

    Qué lo activa

    Di cualquiera de estas frases y el agente debería cargar este skill.

    • Optimiza mi cartera con el solver de gradiente conjugado
    • Recalcula los pesos óptimos de la cartera actual

    SKILL.md

    En inglés

    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:

      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:

      # 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__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:

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

      mcp__ruflo-sublinear__solve({
        matrix: COVARIANCE,
        rhs: EXPECTED_RETURNS,
        algorithm: "cg",
        tolerance: 1e-6,
        maxIterations: 200
      })
      

      Output:

      { 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:

      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:

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

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

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

    Reproducido de ruvnet/ruflo bajo licencia MIT. Leer esta página en markdown.

    Archivos

    1 archivo en el paquete. Solo se lee SKILL.md al activarse — las referencias se cargan si el skill decide que las necesita.

    Antes de instalar

    Necesita neural-trader instalado.

    Necesita en el PATH:npm

    Detalles

    Creador
    ruvnet
    Categoría
    Finanzas
    Licencia
    MIT
    Recursos incluidos
    Solo SKILL.md
    Repositorio
    ruvnet/ruflo
    Código fuente
    Ver SKILL.md

    Etiquetas

    Más de ruvnet/ruflo

    Este repo incluye 275 skills. Si instalas uno, normalmente ya tienes los demás.

    Inspecciona y audita genomas GEPA: carga y valida un genoma, renderiza el system prompt que compila, o clasifica los modos de fallo de una transcripción de ejecución.

    Costo de contexto al activarse
    833 tok
    Tamaño del paquete
    1 archivo
    Última actualización
    hace 4 días
    Permisos
    herramientas desarrollo

    Completion de un solo turno contra el modelo deepseek-chat de DeepSeek vía /v1/chat/completions. Lee DEEPSEEK_API_KEY y degrada con status:degraded si falta o la API no responde. Para tareas sin razonamiento.

    Costo de contexto al activarse
    566 tok
    Tamaño del paquete
    1 archivo
    Última actualización
    hace 4 días
    Permisos
    automatizacion

    Completion en modo razonamiento contra deepseek-reasoner (R1) de DeepSeek. Devuelve el chain-of-thought por separado de la respuesta final. Lee DEEPSEEK_API_KEY y degrada si falta o la API no responde.

    Costo de contexto al activarse
    627 tok
    Tamaño del paquete
    1 archivo
    Última actualización
    hace 4 días
    Permisos
    automatizacion

    Construye o reconstruye el índice de ADRs y su grafo de dependencias ejecutando scripts/import.mjs, en vez de cientos de llamadas MCP.

    Costo de contexto al activarse
    866 tok
    Tamaño del paquete
    1 archivo
    Última actualización
    hace 27 días
    herramientas desarrollo

    Crea un nuevo Architecture Decision Record con numeración secuencial y registro en AgentDB.

    Costo de contexto al activarse
    680 tok
    Tamaño del paquete
    1 archivo
    Última actualización
    hace 27 días
    herramientas desarrollo

    Muestra el estado de la integración AGNTCY/SLIM/CASA: si los paquetes están instalados, qué transporte está activo y si el enforcement de CASA está habilitado.

    Costo de contexto al activarse
    443 tok
    Tamaño del paquete
    1 archivo
    Última actualización
    hace 26 días
    devops infraestructura

    Skills relacionados

    Especialista en autorización de pagos multi-agente para comercio autónomo con IA: verificación criptográfica y consenso Byzantine entre agentes.

    Costo de contexto al activarse
    1.3k tok
    Tamaño del paquete
    1 archivo
    Última actualización
    hace 6 meses
    finanzas

    Especialista en gestión de créditos y facturación. Procesa pagos, gestiona sistemas de créditos, niveles de suscripción y operaciones financieras dentro de Flow Nexus.

    Costo de contexto al activarse
    959 tok
    Tamaño del paquete
    1 archivo
    Última actualización
    hace 6 meses
    finanzas

    Agente de trading financiero que usa algoritmos sublineales para predecir movimientos de mercado y calcular ventajas temporales frente a la transmisión de datos, con fines de arbitraje y HFT.

    Costo de contexto al activarse
    2.5k tok
    Tamaño del paquete
    1 archivo
    Última actualización
    hace 6 meses
    finanzas