Logo von X2strategy

X2strategy

Organisation
ALAGENT-HKU
x2strategy

ALAGENT X2Strategy: any research input (PDF paper, Markdown draft, DOCX report, text notes, or keyword search) → structured strategy specification → executable Backtrader code → backtest → diagnosis report. Two core capabilities: (1) paper2spec extracts multi-strategy specs from any document via 5-layer LLM extraction, and (2) spec2code generates validated Backtrader code, runs backtests, and compares against paper metrics. Use this skill whenever the user wants to analyze a quant paper, extract trading strategies, generate strategy code, run a backtest, search for papers, or go end-to-end from any input to executable results. Also triggers on: "look at this paper", "what strategies does this use", "implement this strategy", "search for momentum papers", "turn this into code", or any request about quantitative finance research → implementation. Even if the user doesn't mention "strategy" explicitly — if they provide a finance paper or research document, use this skill.

Übersicht

HerausgeberALAGENT-HKU
Repositoryx2strategy
Skill-Namex2strategy
Sterne
282
Forks
46
Mitgelieferte Dateien
66
Links
  • Anweisungen in Markdown

    Eine SKILL.md-Datei, die das Modell bei Bedarf lädt. So werden nur dann Token verbraucht, wenn eine Anfrage tatsächlich dazu passt.

  • Funktioniert mit jedem LLM

    KI-Skills bestehen aus reinem Markdown, nicht aus anbieterspezifischem Code. Daher funktionieren sie mit GPT, Claude, Gemini, Grok oder einem lokalen Modell.

  • Mitgelieferte Dateien: 66

    Skripte, Vorlagen und Referenzmaterial, die das Modell bei der Arbeit lesen kann. Die Dateien sind schreibgeschützt und werden niemals ausgeführt.

  • Open Source

    Von ALAGENT-HKU auf GitHub veröffentlicht. Prüfen Sie vor der Installation die Quelldateien.

Installation

Installieren Sie den KI-Skill X2strategy in TypingMind, um ihn mit jedem LLM zu nutzen, oder fügen Sie ihn einem anderen Agenten hinzu, der SKILL.md lesen kann.

1

In TypingMind installieren

TypingMind installiert einen Skill direkt aus seinem GitHub-Ordner. Dabei liest die App SKILL.md, bündelt die Ressourcendateien und speichert das Ergebnis lokal.

  1. Öffnen Sie die App und gehen Sie zu Plugins → Skills.
  2. Wählen Sie „Von GitHub installieren“.
  3. Fügen Sie die unten angegebene URL des Skill-Ordners ein und bestätigen Sie.
    https://github.com/ALAGENT-HKU/x2strategy/tree/main
  4. Aktivieren Sie den Skill in jedem Chat, in dem er verfügbar sein soll.
Plugins → Skills → Skill hinzufügen → Über GitHub-URL. Fügen Sie dann die Ordner-URL ein und klicken Sie auf „Weiter“.
2

In einem anderen Agenten installieren

Jeder Agent, der das Agent-Skills-Format unterstützt, kann diesen Skill nutzen. Kopieren Sie den Ordner in das Skill-Verzeichnis des jeweiligen Agenten.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ALAGENT-HKU/x2strategy.git \
  .claude/skills/x2strategy
Starten Sie Claude Code nach dem Kopieren neu, damit der neue Skill erkannt wird.

In TypingMind verwenden

Aktivieren Sie X2strategy in einem beliebigen Chat in TypingMind. Den Rest übernimmt das Modell. Name und Beschreibung des Skills stehen im System-Prompt. Sobald eine Anfrage passt, lädt das Modell selbstständig die vollständigen Anweisungen — Sie müssen den Skill nie manuell aufrufen, und er verbraucht erst Token, wenn er tatsächlich genutzt wird.

Das Modell lädt X2strategy automatisch, sobald eine passende Anfrage gestellt wird.

Funktioniert mit jedem KI-Modell

KI-Skills bestehen aus reinen Markdown-Anweisungen statt aus anbieterspezifischem Code. Daher ist X2strategy nicht an das Modell gebunden, für das der Skill geschrieben wurde. Installieren Sie ihn einmal in TypingMind und nutzen Sie ihn mit GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder einem selbst betriebenen lokalen Modell — alles mit Ihren eigenen API-Schlüsseln.

  • Wird nur bei Bedarf geladen

    Der System-Prompt enthält nur den Namen und die Beschreibung. Die Anweisungen werden bei der ersten passenden Anfrage geladen. Ein ungenutzter Skill verursacht daher keine Kosten.

  • Modell im laufenden Chat wechseln

    Da der Skill aus Anweisungen statt aus Code besteht, funktioniert er auch nach einem Modellwechsel — das nächste Modell liest dieselbe SKILL.md-Datei.

Skill-Anweisungen

Dies ist der Inhalt von SKILL.md, den das Modell lädt. Lesen Sie ihn vor der Installation — ein Skill besteht aus Anweisungen, denen Ihr Modell folgt.

X2Strategy

Any finance-related input → Strategy spec → Executable code → Backtest → Diagnosis.

Capabilities

CapabilityWhat it doesDeep dive
paper2specAny document (PDF/MD/DOCX/TXT) → structured strategy specificationreferences/paper2spec.md
spec2codeStrategy spec → Backtrader code → validate → backtest → diagnosisreferences/spec2code.md

Input format auto-detected from extension:

FormatExtensionNotes
PDF (papers).pdfPyMuPDF → Mode A (direct) or Mode B (FAISS)
Markdown (drafts).md, .markdownDirect text read
DOCX (reports).docxpython-docx (requires uv sync --extra docx)
Plain text.txtDirect read

Interaction Principles

You are the executor. The user is the requester.

  • Run tools silently, present results and insights in natural language.
  • Never show CLI commands (uv run python scripts/...) unless user asks.
  • Offer next actions conversationally: "Would you like me to implement the second strategy as well?"

When reporting results, focus on what you found, not how:

❌ Bad:  "I ran `uv run python scripts/analyze.py paper.pdf` and got 3 strategies."
✅ Good: "This paper contains 3 independent strategies: [1] minimum distance method, [2] ADF stationarity, and [3] Johansen cointegration. Which one should I implement?"

Use interactive tools aggressively. When your platform provides interactive question tools — vscode_askQuestions (VS Code Copilot), AskUserQuestion (Claude Code), or equivalent — use them for ALL user-facing choices. Interactive tools present clickable options, which is faster and less error-prone than asking the user to type.

Apply interactive tools to:

  • First-Run Setup choices (workspace path, API provider, key input)
  • Input confirmation (proceed / add clarification / adjust settings)
  • Review checkpoints and implementation approval
  • needs_human_review resolution after extraction or repair
  • Search result selection (pick papers from a numbered list)
  • Any scenario where the user picks from options

If no interactive tool is available, fall back to numbered text menus.

Progress Marker Protocol

Run tools silently, but make long pipelines traceable. While working through the eight-step workflow, prefix status lines with one of three structured markers so the user (and any outer parser) can follow phase progress without reading raw command output. The markers carry the discipline; the surrounding prose stays natural-language.

MarkerWhen to emitFormat
[PROGRESS]Entering or finishing a workflow step[PROGRESS] <step> — <one-line status>
[ARTIFACT]A concrete file was written[ARTIFACT] <workspace-relative-path> — <what it is>
[ERROR]A step failed or a check did not pass[ERROR] <step> — <what failed> — <next action>

Rules:

  • One marker per line, at the start of the line, then plain language.
  • Every [ARTIFACT] must name a concrete workspace-relative path that was actually written (this satisfies the Output Paths contract below).
  • [ERROR] must always be followed by what you will do next (retry once, stop and report, ask the user) — never a bare failure.
  • Markers supplement natural-language reporting; they do not replace it. Still explain what you found, not how you ran it. Never show the CLI command.

Example:

[PROGRESS] paper2spec/extract — extracting strategy specs from content.json
[ARTIFACT] library/upsa/spec.json — 1 strategy, 4 indicators, 3 logic steps
[PROGRESS] HITL review — 1 open needs_human_review item, asking for resolution

Iteration & Retry Discipline

Generation and repair must be bounded. Translate the backend's hard turn gate (--max-turns) into agent discipline:

  • Generate once, then at most one smoke-test repair round. Write the code, validate, run. If it fails, apply one targeted fix round (see the triage flow in references/spec2code.md) and re-run.
  • If it still fails after that one repair round, stop and report. Emit an [ERROR] line, summarize what failed and the most likely root cause, and ask the user how to proceed. Do not keep patching incrementally.
  • A single runtime-error category gets at most 3 fix attempts. If the same error class persists, the strategy logic likely needs a fundamentally different approach — say so rather than tweaking further.
  • Never silently loop. Each retry must be visible via a [PROGRESS] or [ERROR] marker so the user can see the gate working.

First Response Contract

For any paper2code, research-to-code, or “use this skill” request, the first response must not promise immediate implementation. First identify the visible inputs, then use an interactive dialog to confirm setup status, input files, extra instructions/clarifications, and intended workflow scope. Only proceed after that confirmation.


First-Run Setup

On first use, walk through three steps. If a step is already configured, report the detected value and ask the user to confirm or change it. Always confirm task scope before extraction or implementation. Persist all choices to .env (gitignored) for session stability.

Step 1 — Workspace Location

Present choice via interactive tool:

  • ./library/ (default, recommended)
  • Custom path

Write PAPER2SPEC_LIBRARY_PATH=/absolute/path to .env. Scan the directory for existing metadata.json to detect prior analyses.

Step 2 — LLM API Key

Check env for DEEPSEEK_API_KEY, OPENROUTER_API_KEY, OPENAI_API_KEY, or ANTHROPIC_API_KEY. If none found, present via interactive tool:

An LLM API key is required for strategy extraction and code generation. Recommended options:
  1. DeepSeek (best cost-performance, about ¥0.7 per paper) → https://platform.deepseek.com
  2. OpenRouter (one key for access to multiple models) → https://openrouter.ai/keys
Please provide your API key and tell me which provider it belongs to.

Once received, write key + matching model to .env, then verify: uv run python -c "from paper2spec.llm import chat; print(chat('Say OK'))".

See references/skill-internals.md for .env format examples per provider.

Step 3 — Python Environment

bash
cd <skill-path>
uv sync --all-extras    # Recommended: installs everything

If uv unavailable: pip install -e ".[codegen,agent,dev]". Always use uv run to execute scripts (auto-activates correct venv).

See references/skill-internals.md for selective install options and non-uv alternatives.

Completion

Once configured, confirm naturally with examples:

✅ Setup complete. You can now ask me for tasks directly, for example:

  • "Analyze this paper" + attach a PDF file
  • "Search for papers about momentum trading"
  • "Implement this strategy based on this paper" + provide the file path
  • "I wrote a strategy draft in Markdown; extract the spec and generate code"
  • "Compare the strategy differences between these two papers"

Just tell me what you want to do, and I will handle the rest.

Single Workflow

Use one workflow for all tasks. Do not choose between competing routers.

  1. Setup — verify .env, library path, API key if needed, Python environment, and user-selected scope.
  2. Input confirmation — identify the paper/spec/data/instruction files or search results; ask whether to add clarification, constraints, selected-plan preferences, known pitfalls, or reference files.
  3. paper2spec: PDF/text to content — parse the selected document into grounded content artifacts.
  4. paper2spec: extract — extract candidate strategy specs/plans from the content plus user instructions.
  5. paper2spec: repair/review — read references/extraction_quality.md, retrieve relevant operator pitfalls when high-risk formulas are present, and repair only the selected plan/spec with grounded evidence.
  6. HITL review — after repair, always inspect needs_human_review. If any item exists, present it through the interactive dialog and do not continue until answered or explicitly accepted. If none exists, still report that review found no open items and ask for implementation approval.
  7. spec2code — after HITL approval, confirm the implementation target and generate code for that target.
  8. Validation/backtest/diagnosis — validate generated code, run available checks/backtests, compare against expected or reference outputs, summarize mismatches, then ask what to do next.

No bypass: never silently chain extraction → repair → implementation. User-provided papers, instructions, data files, existing specs, or reference outputs are evidence, not permission to skip review or HITL.

When previous Copilot, VS Code, or agent logs are mentioned, verify that the referenced path exists and contains the needed files before using them. If the path is missing, empty, or incomplete, regenerate the required artifacts from the original paper/instructions/data instead of relying on the log summary.

Output Paths

Default generated artifacts go under PAPER2SPEC_LIBRARY_PATH/<slug>/, where <slug> is the paper or task slug confirmed with the user. If a custom output path is requested, confirm it before writing files.

Expected artifact paths:

  • content.json and content.md from paper2spec parsing
  • spec.json and spec.md from extraction and repair
  • operator_pitfall_context.md when pitfall retrieval is used
  • strategy.py, strategy_1.py, or the user-confirmed implementation filename from spec2code
  • data/ for any data used by generated strategy code
  • results/backtest_output.txt, results/metrics.json, and results/diagnosis_report.md from validation/backtest/diagnosis
  • results/portfolio_vs_assets.csv and results/portfolio_vs_assets.png comparing the strategy portfolio value against same-capital buy-and-hold curves for every used equity/ETF/asset in one image; asset curves must use distinguishable colors and symbol labels/legend entries, and SPY and portfolio must be boldface (comparing same-parameter portfolio curves at 0%, 0.01%, and 0.05% commission in one image)
  • results/key_pred/ with one CSV and one PNG per key observerable factors used by the strategy

Every status update after file generation should name the concrete workspace-relative path that was written.

Spec2Code Metrics

For every runnable strategy, spec2code should compute and report at least: Sharpe ratio, maximum drawdown, total return, and return value/final portfolio value. If a strategy is not runnable as a broker-connected strategy, report why and still compute the metrics that are meaningful for the confirmed research/backtest contract.

Spec2Code-generated code must cache all network data locally, save headless-safe visual diagnostics, plot all used asset prices together, compare the strategy account value against same-capital buy-and-hold curves for all used assets, include a 0% / 0.01% / 0.05% commission equity-curve comparison for trading strategies, and include a combined portfolio-vs-assets chart where all three commission portfolio curves are plotted with all asset buy-and-hold curves.

For US equity strategies, SPY must be included and highlighted as the market baseline in asset and portfolio-vs-assets plots. See references/spec2code.md and references/data_sources.md for the required data cache and visualization contract.


Agent Pipeline Flow

1. Setup: confirm environment, library path, keys if needed, and task scope
2. Confirm inputs: paper/spec/data/instructions/search result + clarifications
3. paper2spec: parse PDF/text/doc to content artifacts
4. paper2spec: extract candidate specs/plans
5. paper2spec: select target plan/spec and repair with extraction_quality + matched pitfalls
6. HITL: inspect needs_human_review and resolve through interactive dialog
7. spec2code: confirm output contract, generate code, validate, run checks/backtest
8. Diagnose results and ask next action

For code generation patterns: references/spec2code.md For Backtrader patterns: references/backtrader_patterns.md


Internal Toolchain

Agent-only. Run silently; present results in natural language.

bash
# Document → spec
uv run python scripts/analyze.py <file> -o library/<slug>/

# Step-by-step paper2spec
uv run python scripts/parse.py <file> -o content.json
uv run python scripts/extract.py content.json -o spec.json

# Matched operator-pitfall context for repair/review
uv run python scripts/operator_pitfalls.py spec.json -o operator_pitfall_context.md

# Validate generated code
uv run python scripts/validate_strategy.py library/<slug>/strategy_1.py

# Run backtest
uv run python library/<slug>/strategy_1.py

# Search papers
uv run python scripts/search.py "<query>" -n 5

For full flags, output formats, and library management: references/skill-internals.md


Configuration

VariableDefaultPurpose
PAPER2SPEC_LIBRARY_PATH./libraryOutput root
PAPER2SPEC_MODELopenai/gpt-4o-miniDefault LLM (litellm-supported)
DEEPSEEK_API_KEY—DeepSeek (recommended)
OPENROUTER_API_KEY—OpenRouter (multi-model)
OPENAI_API_KEY—OpenAI direct
PAPER2SPEC_ARXIV_MIN_INTERVAL3.0Seconds between arXiv requests
PAPER2SPEC_SEARCH_MAX_RETRIES3Retry on HTTP 429/5xx

Any litellm-supported model works. The --model flag on any script overrides PAPER2SPEC_MODEL. Full config + .env examples: references/skill-internals.md


References

Read on demand for implementation details:

Limitations

  • Mode A truncates at 100K chars (first 90K + last 10K). Use Mode B for >100 page papers.
  • Tables/formulas: not yet extracted from PDFs.
  • Multi-strategy: conservative — may merge borderline-distinct strategies.
  • DOCX: paragraph text only (tables, images not preserved — use PDF for rich docs).
  • SSRN search: best-effort HTML scraping, may break on layout changes.

Mitgelieferte Dateien

Das Modell liest diese Dateien bei Bedarf, während der Skill geladen ist. Sie werden als lesbare Dateien bereitgestellt und niemals ausgeführt.

Weitere Dateien: 6.

Häufig gestellte Fragen

Was macht der KI-Skill X2strategy?

ALAGENT X2Strategy: any research input (PDF paper, Markdown draft, DOCX report, text notes, or keyword search) → structured strategy specification → executable Backtrader code → backtest → diagnosis report. Two core capabilities: (1) paper2spec extracts multi-strategy specs from any document via 5-layer LLM extraction, and (2) spec2code generates validated Backtrader code, runs backtests, and compares against paper metrics. Use this skill whenever the user wants to analyze a quant paper, extract trading strategies, generate strategy code, run a backtest, search for papers, or go end-to-end...

Warum X2strategy in TypingMind nutzen?

Weil Sie den Skill einmal installieren und mit jedem Modell verwenden können. X2strategy besteht aus reinem Markdown statt aus anbieterspezifischem Code. So funktioniert derselbe Skill mit GPT-5, Claude, Gemini, Grok oder einem lokalen Modell – und Sie können das Modell mitten im Chat wechseln, ohne dass der Skill seine Funktion verliert. TypingMind verwendet Ihre eigenen API-Schlüssel. Sie bezahlen die Anbieter daher direkt statt über ein Abonnement pro Nutzerplatz, und Ihre Skills und Chats bleiben in Ihrem eigenen Speicher.

Wie installiere ich X2strategy in TypingMind?

Öffnen Sie in TypingMind Plugins → Skills → Von GitHub installieren und fügen Sie https://github.com/ALAGENT-HKU/x2strategy/tree/main ein. TypingMind liest die Datei SKILL.md, bündelt die zugehörigen Dateien und installiert alles als Skill, den Sie für jeden Chat einzeln aktivieren können.

Welche KI-Modelle können X2strategy nutzen?

Jedes Modell, das Sie mit TypingMind verbinden. KI-Skills bestehen aus reinen Markdown-Anweisungen statt aus anbieterspezifischem Code. Daher können GPT, Claude, Gemini, Grok und lokale Modelle diesen Skill laden, wenn eine Anfrage dazu passt.

Wie viele KI-Modelle kann ich mit X2strategy verwenden?

So viele Sie möchten. In TypingMind können Sie X2strategy mit jedem Modell verwenden, das Skills unterstützt, etwa mit GPT, Claude, Gemini, Grok, DeepSeek, Mistral oder Llama. Dabei nutzen Sie Ihre eigenen API-Schlüssel.

Ist der KI-Skill X2strategy kostenlos?

Der Skill wird von ALAGENT-HKU auf GitHub veröffentlicht. Prüfen Sie im Repository, ob dort Lizenzbedingungen angegeben sind. Sie bezahlen nur Ihren eigenen KI-Anbieter für die verwendeten Token.

Was sind KI-Skills?

Ein KI-Skill ist ein wiederverwendbares Anweisungspaket, das einem KI-Modell vermittelt, wie es eine bestimmte Aufgabe erledigt. Es folgt dem offenen Format Agent Skills: Die Datei SKILL.md enthält den Namen und die Beschreibung des Skills. Hinzu kommen bei Bedarf Skripte, Vorlagen oder Referenzdateien für das Modell. Das Modell liest die Anweisungen nur, wenn Ihre Anfrage zum Skill passt. Ein installierter Skill verursacht daher erst Kosten, wenn er verwendet wird.

Wie unterscheiden sich KI-Skills von Plugins oder MCP-Servern?

Ein Plugin oder MCP-Server stellt einem Modell neue aufrufbare Tools bereit – Code, der auf einem System ausgeführt wird und ein Ergebnis zurückgibt. Ein KI-Skill vermittelt dem Modell stattdessen Wissen und Vorgehensweisen: wie es eine Aufgabe angeht, welche Schritte es befolgt und wie eine gute Ausgabe aussieht. Skills bestehen aus reinem Markdown und kommen daher ohne Server, API-Schlüssel und Laufzeitumgebung aus. Sie funktionieren mit jedem Modell.

Alle anzeigen

Jetzt eigenen KI-Arbeitsbereich einrichten

Abonnieren Sie unseren Newsletter und erfahren Sie mehr über neue Funktionen und kommende Gewinnspiele 👇