trader-portfolio-cg
できること
このスキルは、共役勾配法と呼ばれるより速い数学的方法を使って、ポートフォリオの配分の重みを計算します。自分のデータを使って、資産にどう投資を分散させるかを分析する人向けです。
使う場面
- ✓共分散行列から、ポートフォリオの重みを計算したいとき。
- ✓データに対して、古い方法では遅すぎるとき。
- ✓より速い方法と古い方法を比べたいとき。
スキルのリンク
https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-neural-trader/skills/trader-portfolio-cg/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“私の5つの保有銘柄について、より速い方法で平均分散の重みを計算してください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
スキルは、共役勾配法でポートフォリオの方程式を解き、使われた方法を記録します。ネイティブの経路が失敗した場合は、ローカルの計算に切り替えます。設定によって、比較のためにより速い経路を無効にすることもできます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
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:
Ensure neural-trader is available:
npm ls neural-trader 2>/dev/null || npm install --ignore-scripts neural-traderRead the current covariance matrix Σ and expected-return vector μ from neural-trader's portfolio API:
# neural-trader 2.8.11 does NOT return Σ or μ: `--portfolio current` runs the equal-weight demo # (symbols, weights, a risk figure and a note that the returns matrix is not wired). # Take Σ and μ from the user (a returns matrix they provide), or from AgentDB if a prior run stored them: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) andexpectedReturns: number[](length n).Solve Σ · x = μ via the SublinearAdapter (preferred path) when
RUFLO_NEURAL_TRADER_DISABLE_CGis 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__solveonglobalThis(and honoursRUFLO_SUBLINEAR_NATIVE=1as 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 readsresult.methodto 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 }Fallback (legacy Neumann) — if step 3 reports
degraded: true(non-SPD input, non-square matrix, MCP error) OR ifRUFLO_NEURAL_TRADER_DISABLE_CG=1:npx neural-trader --portfolio optimizeCapture the weights output and tag the artifact metadata with
method: 'neumann-fallback'and areasonfield.Store the optimal weights to
trading-risknamespace with full provenance metadata. Takemethodandsolverstraight 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,
よくある質問
これは何を買うべきか教えてくれますか?
いいえ。あなたが提供したデータから重みを計算するだけです。何を行動に移すかは、あなたが決めます。
より速い方法を無効にするにはどうすればよいですか?
設定で無効にでき、その場合は比較のために古い方法に戻ります。
共分散のデータが不正な場合はどうなりますか?
この方法は有効な対称行列を前提とするため、不正な入力データでは結果が壊れることがあります。
詳細
作者による元の説明
Mean-variance portfolio optimization via Conjugate Gradient — 40-60× faster than the legacy Neumann path (ADR-126 Phase 3, ADR-123 Wedge 8)
repo: ruvnet/ruflo
人気
- GitHubのスター
- 81k
- ランキング
- #1670
- ライセンス
- MIT
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
agent-adaptive-coordinator
81k作業量の変化に合わせて、エージェントのグループを分割し、再配分する手助けをします。作業に合った配置を選びます。
agent-agent
81k大きな目標を順番に並んだ行動計画にし、状況が変わったときに計画を立て直す方法をエージェントに教えます。
agent-agentic-payments
81kAIの買い物のために、支出の上限、期間、販売店のルール、署名付きの承認を含む支出の委任を管理する手助けをします。
agent-analyze-code-quality
81kコードの品質を確認し、コードの臭い、技術的負債、リファクタリングの案を見つける手助けをします。ファイルは変更しません。
似ているスキル
gitcrawl
394k保存されたGitHubのイシューとプルリクエストのアーカイブを検索し、重複をまとめ、GitHub上の現在の状態を確認するようエージェントを支援します。
slacrawl
394kローカルのSlackアーカイブ内のメッセージを検索して件数を数え、アーカイブの新しさを確認し、必要に応じて更新するようエージェントを支援します。
goplaces
394kGoogle Placesを使って、場所を検索し、詳細や口コミを取得し、場所の名前を解決するようエージェントを支援します。スクリプト用にJSON出力もできます。