
Trading Signal Attribution
FreeUnderstand feature contributions to trading signals.
Free · Opens the source repo
What Trading Signal Attribution does
The Trading Signal Attribution skill provides a robust method for explaining predictions made by trading models, specifically those based on LSTM or Transformer architectures. By utilizing single-entry PageRank, this skill ranks the top features that influenced a given trading signal, ensuring compliance with regulatory requirements for interpretability in algorithmic trading systems. This is particularly crucial in light of the EU AI Act and SEC Reg-AI guidelines, which mandate that any model affecting retail capital must provide clear and interpretable outputs.
To use this skill, the user first retrieves the relevant trading signal from the trading-signals namespace. The skill then extracts contribution scores for each feature from the model's predictions. If the latest version of the neural-trader tool is not available, the skill has a fallback mechanism that uses a heuristic based on z-scores to estimate feature importance. This ensures that users still receive valuable insights even if they are working with older tool versions.
Once feature contributions are established, the skill constructs a feature-contribution graph that represents the relationships between features and the signal output. This graph is then processed using PageRank, which ranks the features based on their contributions to the prediction. The results are compiled into a markdown table format, which is not only user-friendly but also stored as a SignedAttributionArtifact in the trading-analysis namespace for future reference and regulatory compliance. This artifact includes essential metadata about the analysis, such as the number of PageRank iterations and the seed used for reproducibility.
Overall, this skill is designed for developers and data scientists working in the financial sector who need to ensure that their trading models are interpretable and compliant with regulations. It provides a clear, systematic approach to understanding the factors that drive trading decisions, which is essential for both model validation and regulatory reporting.
When to use it
Use this skill when you need to explain the predictions of trading signals and ensure they meet regulatory interpretability requirements.
When not to use it
This skill may not be suitable if you are not working with LSTM or Transformer-based models or if you do not require regulatory compliance for your trading systems.
What you can build with it
Regulatory Reporting
Use the skill to generate interpretable outputs for regulatory filings, ensuring compliance with AI regulations.
Model Validation
Leverage feature attribution to validate trading models and understand the drivers behind predictions.
Performance Analysis
Analyze trading signals to identify which features are most influential, aiding in model refinement and strategy development.
How to install Trading Signal Attribution
View source1. Install with the skills CLI
npx skills add ruvnet/ruflo/trader-explain --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by ruvnetExplain a trading signal by building a feature-contribution graph and running single-entry forward-push PageRank from the signal output node. Top-K ranked features are returned as a markdown table AND persisted to trading-analysis as a SignedAttributionArtifact (ADR-126 Phase 6).
Why this skill matters:
- EU AI Act + SEC Reg-AI guidance require interpretable model output for any algorithmic trading system that touches retail capital. This is the regulator-grade attribution path the rest of the substrate has been waiting for.
- The same call site picks up the full native-WASM PageRank from
mcp__ruflo-sublinear__page-rank-entryonce that tool is registered in the runtime — until then, the local power-iteration kernel ships insigned-attribution.mjsand produces the same ordering (seeded mulberry32).
Steps:
-
Retrieve the signal from the canonical
trading-signalsnamespace (ADR-126 Phase 1 + Phase 2 lifecycle):mcp__plugin_ruflo-core_ruflo__memory_retrieve({ key: "SIGNAL_ID", namespace: "trading-signals" })The signal entry includes
modelId,prediction, and the feature vector at the time of inference. -
Extract per-feature contribution scores from the model:
npx neural-trader --predict --signal "$SIGNAL_ID" --explain --jsonThe expected output shape:
{ features: Array<{ name: string; contribution: number }>; // for Transformers, also includes per-head attention co-occurrence: attention?: Array<{ head: string; cooccur: Array<[number, number, number]> }>; }Fallback path — if
--explainis not shipped on the installedneural-traderbuild (older versions; the flag was scoped for a follow-up upstream PR), the skill degrades to a deterministic feature-importance heuristic over the signal's input vector:contribution_i = |input_i - μ_i| / σ_i(z-score magnitude). This is a known proxy — not as faithful as attention/SHAP — and the resulting artifact is taggedattribution_method: "input-zscore-fallback"so downstream consumers can filter it out for regulator filings. Document the fallback path in the resulting markdown summary so the agent surfaces it to the user. -
Build the feature-contribution graph:
- Nodes: one node per feature + one source node
__signal_output__for the prediction. - Edges: outgoing edges from
__signal_output__to each feature node, weighted bycontribution_i. When attention co-occurrence data is available, also add edges between feature nodes weighted bycooccur— this is what makes the PageRank single-entry rather than degenerating to plain top-K. - Source:
__signal_output__(index 0 by convention so the smoke can assert reproducibility).
- Nodes: one node per feature + one source node
-
Run single-entry PageRank — preferred path when
mcp__ruflo-sublinear__page-rank-entryis registered:mcp__ruflo-sublinear__page-rank-entry({ nodes: GRAPH_NODES, edges: GRAPH_EDGES, sourceIndex: 0, damping: 0.85, maxIterations: 100, tolerance: 1e-8, seed: 42 })The local fallback (
localSingleEntryPageRankinplugins/ruflo-neural-trader/src/signed-attribution.mjs) runs ~30 LOC of seeded power-iteration when the MCP tool is not available — same math, same result up to floating-point tolerance, same ordering for the same seed (the Phase 6 smoke asserts this). -
Build the top-K
AttributionFeature[]viatopKFeatures(graph, scores, k=10, excludeIndex=0)— excludes the source node from the ranked output. Ties broken by node index (lower index wins) so the ranking is deterministic. -
Sign the artifact (reuses the Phase 4 signing primitives — same Ed25519 + canonicalization):
- Build the
SignedAttributionArtifactbody:{ signalId: SIGNAL_ID, modelId: SIGNAL.modelId, features: TOP_K_FEATURES, // from step 5 graphMetadata: { nodeCount: GRAPH.nodes.length, edgeCount: COUNT_EDGES, pageRankIterations: PR_RESULT.iterations, seed: SEED // load-bearing for reproducibility }, generatedAt: NEW_DATE_ISO } - Resolve the witness signing key — same lookup order as Phase 4:
RUFLO_WITNESS_KEY_PATHenv var — JSON file with{ "privateKey": "<hex>" }.verification/witness-key.json(the ADR-103 default path).
- If a key resolves:
signAttributionArtifact(body, privateKeyHex)fromplugins/ruflo-neural-trader/src/signed-attribution.mjs. - If NEITHER path resolves: log
"[WARN] ruflo-neural-trader: no witness signing key found — storing attribution artifact in UNSIGNED degraded mode. Regulator filings will reject UNSIGNED artifacts."and store the body unsigned. NEVER silently fall back.
- Build the
-
Store the (possibly signed) artifact to the canonical
trading-analysisnamespace (ADR-126 Phase 1):mcp__plugin_ruflo-core_ruflo__memory_store({ key: "attribution-SIGNAL_ID-TIMESTAMP", namespace: "trading-analysis", value: JSON.stringify(signedArtifact) })The
trading-analysisnamespace is the canonical home for model-analysis output (regime classifications, technical-indicator summaries, model-training results — and now attribution rankings). Long-lived — no TTL — because the audit trail is the deliverable. -
Return the markdown summary to the agent. Suggested format:
## Feature attribution for signal `SIGNAL_ID` (model: MODEL_ID) | Rank | Feature | Score | |------|---------|-------| | 1 | NAME | 0.42 | | 2 | NAME | 0.18 | | … | … | … | - PageRank iterations: N - Graph: nodeCount nodes, edgeCount edges - Seed: 42 (reproducible — same seed → same ordering) - Path: mcp | local - Signature: ed25519:abcd… (or UNSIGNED — degraded warning above)
Verification
Downstream consumers verify the artifact before any regulator-facing report or paper→live promotion:
import { verifyAttributionArtifact } from 'plugins/ruflo-neural-trader/src/signed-attribution.mjs';
const ok = await verifyAttributionArtifact(artifact, trustedPublicKey);
if (!ok) {
// [ERROR] attribution verification failed — refuse to publish.
// Pin to trustedPublicKey from project config; do NOT trust the
// artifact.witnessPublicKey field (CWE-347 / #1922 — attacker-controllable).
return;
}
Acceptance criteria (ADR-126 Phase 6):
trader-explain <signalId>returns a ranked feature list whose top-3 features overlap the model's attention argmax (when--explainavailable; documented tolerance).- Reproducibility: two runs with the same
signalId+ same--seedproduce byte-identical rank ordering (asserted byscripts/smoke-neural-trader-feature-attribution.mjs). - Signed artifact verifies under the trusted pubkey; tampering any feature score or
graphMetadata.seedinvalidates the signature. - Fallback paths engage cleanly: when MCP unavailable, local kernel runs; when
--explainflag missing, z-score heuristic runs and the artifact is tagged.
Refs:
- ADR-126 Phase 6 (this skill's authoring ADR)
- ADR-126 Phase 4 (the signing scheme this reuses)
- ADR-123 (single-entry PageRank substrate; the same family that Phase 3 leverages for portfolio CG)
plugins/ruflo-neural-trader/src/signed-attribution.ts(the typed contract)plugins/ruflo-neural-trader/src/signed-attribution.mjs(the runtime mirror)scripts/smoke-neural-trader-feature-attribution.mjs(the regression smoke)
Frequently asked questions about Trading Signal Attribution
Similar skills
scvi-tools Deep Learning
Advanced tools for single-cell genomic analysis.
Arize Experiment
Evaluate and compare model performance with ease.
DEFT Mining and Embedding
Automate image mining for machine learning workflows.
TimesFM Forecasting
Zero-shot time series forecasting with Google’s TimesFM.
SHAP
Audit and explain machine learning predictions with SHAP.
scvi-tools
Advanced tools for single-cell omics analysis.
