# jackson-video-resources/markov-hedge-fund-method architecture

> Architecture diagram of the GitHub repository jackson-video-resources/markov-hedge-fund-method, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jackson-video-resources/markov-hedge-fund-method
- Repository: https://github.com/jackson-video-resources/markov-hedge-fund-method

## Overview

#### Purpose and Distribution

This repository packages the “Markov Hedge Fund Method” as a Claude Code plugin/skill for regime detection on market price series. Its primary user-facing entry point is the `regime` skill, installed through the plugin metadata in `.claude-plugin/plugin.json` and invoked as `/markov-hedge-fund-method:regime`.

#### Core Regime Analysis Engine

The executable analysis implementation is `scripts/markov_regime.py`. It accepts either a market ticker, fetched through `yfinance`, or a user-provided CSV containing date and close data. Inline PEP 723 dependency metadata allows `uv` to provision runtime dependencies on first use.

The engine labels observations Bull, Bear, or Sideways from rolling returns using configurable lookback and threshold defaults.

#### Markov Modeling and Forecasting

`scripts/markov_regime.py` derives a 3×3 maximum-likelihood transition matrix from historical regime labels. It uses matrix powers for n-step regime forecasts and computes a stationary distribution as the long-run regime baseline.

Its main output translates predicted probabilities into a signed directional signal: bull probability minus bear probability, with associated conviction and regime-stickiness context.

#### Validation and Optional Statistical Path

The same Python pipeline performs a walk-forward backtest designed to avoid lookahead bias, reporting strategy-oriented metrics including Sharpe ratio and maximum drawdown. It can optionally fit a Hidden Markov Model using `hmmlearn`; this path degrades gracefully if that dependency cannot be installed or compiled.

#### Skill Contract and Composition Boundary

`skills/regime/SKILL.md` defines the Claude-facing invocation behavior, JSON output contract, inputs, and composition patterns. This is the integration boundary for agents or existing trading workflows: consumers can use the regime result as a standalone signal, trade-confirmation filter, or tail-risk gate without adopting a specific execution system.

The skill orchestrates user intent and invokes the Python analysis rather than embedding market-model logic itself.

#### Plugin Metadata and Installation

`.claude-plugin/marketplace.json` and `.claude-plugin/plugin.json` expose the repository to Claude Code’s plugin marketplace and map the installed plugin to its skill content. The plugin has no service backend, credentials, or account requirement; market-data access occurs directly from the local runtime via `yfinance` when ticker input is selected.

#### Alternate Delivery and Visualization Artifacts

`markov-hedge-fund-method.md` is a transparent/manual bootstrap artifact that instructs Claude Code to create and validate an equivalent local skill installation. It is an alternate onboarding route, not part of normal runtime execution.

`pine-script/markov-hedge-fund-method.pine` is an independent TradingView Pine Script v5 indicator. It implements chart-side visualization of regime state, transition probabilities, and stationary distribution, but does not share runtime integration with the Claude/Python pipeline.

Main entry points: [`skills/regime/SKILL.md`](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/skills/regime/SKILL.md) (regime skill), [`scripts/markov_regime.py`](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py) (Bull/Bear/Sideways labels), [`.claude-plugin/plugin.json`](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/.claude-plugin/plugin.json) (Plugin manifest), [`.claude-plugin/marketplace.json`](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/.claude-plugin/marketplace.json) (Marketplace manifest)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_plugin["Claude Code Plugin"]
  node_marketplace["Marketplace manifest<br/>plugin metadata<br/>[marketplace.json]"]
  node_plugin_manifest["Plugin manifest<br/>plugin metadata<br/>[plugin.json]"]
  node_regime_skill["regime skill<br/>Claude skill<br/>[SKILL.md]"]
  node_consumer_workflow["Agent or trading workflow<br/>consumer"]
end

subgraph group_analysis["Local Analysis Pipeline"]
  node_analysis_engine["Regime analysis engine<br/>Python CLI<br/>[markov_regime.py]"]
  node_ticker_input(("Ticker input<br/>market input"))
  node_csv_input["Price CSV<br/>market input"]
  node_yfinance{{"yfinance<br/>market data client"}}
  node_price_series[("Price series<br/>normalized data")]
  node_regime_labels["Bull/Bear/Sideways labels<br/>regime classifier<br/>[markov_regime.py]"]
  node_transition_model["Transition model<br/>Markov model<br/>[markov_regime.py]"]
  node_forecast["Forecast and baseline<br/>probability model<br/>[markov_regime.py]"]
  node_directional_signal["Directional signal<br/>JSON result<br/>[markov_regime.py]"]
  node_walk_forward["Walk-forward backtest<br/>validation<br/>[markov_regime.py]"]
  node_optional_hmm["Optional HMM fit<br/>statistical path<br/>[markov_regime.py]"]
end

subgraph group_alternate["Alternate Delivery"]
  node_bootstrap_guide["Manual bootstrap guide<br/>onboarding artifact"]
  node_pine_indicator["TradingView indicator<br/>Pine Script v5"]
end

node_marketplace -->|"publishes"| node_plugin_manifest
node_plugin_manifest -->|"installs"| node_regime_skill
node_consumer_workflow -->|"invokes /regime"| node_regime_skill
node_regime_skill -->|"orchestrates"| node_analysis_engine
node_ticker_input -->|"selects"| node_yfinance
node_yfinance -->|"fetches history"| node_price_series
node_csv_input -->|"provides"| node_price_series
node_price_series -->|"rolling returns"| node_regime_labels
node_regime_labels -->|"historical states"| node_transition_model
node_transition_model -->|"transition matrix"| node_forecast
node_forecast -->|"probabilities"| node_directional_signal
node_directional_signal -->|"JSON output"| node_consumer_workflow
node_regime_labels -->|"walk-forward states"| node_walk_forward
node_transition_model -->|"strategy evaluation"| node_walk_forward
node_price_series -.->|"optional fit"| node_optional_hmm
node_bootstrap_guide -.->|"alternate installation"| node_regime_skill

click node_marketplace "https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/.claude-plugin/marketplace.json"
click node_plugin_manifest "https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/.claude-plugin/plugin.json"
click node_regime_skill "https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/skills/regime/SKILL.md"
click node_analysis_engine "https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py"
click node_regime_labels "https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py"
click node_transition_model "https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py"
click node_forecast "https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py"
click node_directional_signal "https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py"
click node_walk_forward "https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py"
click node_optional_hmm "https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py"
click node_bootstrap_guide "https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/markov-hedge-fund-method.md"
click node_pine_indicator "https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/pine-script/markov-hedge-fund-method.pine"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_marketplace,node_plugin_manifest,node_regime_skill,node_consumer_workflow toneBlue
class node_analysis_engine,node_ticker_input,node_csv_input,node_yfinance,node_price_series,node_regime_labels,node_transition_model,node_forecast,node_directional_signal,node_walk_forward,node_optional_hmm toneAmber
class node_bootstrap_guide,node_pine_indicator toneMint
```

## Components

### Claude Code Plugin

- [Marketplace manifest](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/.claude-plugin/marketplace.json): plugin metadata · Publishes the plugin to Claude Code marketplaces. · `.claude-plugin/marketplace.json`
- [Plugin manifest](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/.claude-plugin/plugin.json): plugin metadata · Maps the installed plugin to its skill content. · `.claude-plugin/plugin.json`
- [regime skill](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/skills/regime/SKILL.md): Claude skill · Defines invocation, inputs, JSON output, and composition behavior. · `skills/regime/SKILL.md`
- **Agent or trading workflow**: consumer · Uses the result as a signal, confirmation filter, or tail-risk gate.

### Local Analysis Pipeline

- [Regime analysis engine](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py): Python CLI · Local executable pipeline for ticker or CSV analysis. · `scripts/markov_regime.py`
- **Ticker input**: market input
- **Price CSV**: market input · User-provided date and close series.
- **yfinance**: market data client · Fetches ticker price history from the local runtime.
- **Price series**: normalized data
- [Bull/Bear/Sideways labels](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py): regime classifier · Classifies rolling returns using configurable lookback and thresholds. · `scripts/markov_regime.py`
- [Transition model](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py): Markov model · Builds the 3×3 maximum-likelihood transition matrix. · `scripts/markov_regime.py`
- [Forecast and baseline](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py): probability model · Uses matrix powers for n-step forecasts and computes stationary distribution. · `scripts/markov_regime.py`
- [Directional signal](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py): JSON result · Reports bull-minus-bear signal, conviction, and regime stickiness. · `scripts/markov_regime.py`
- [Walk-forward backtest](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py): validation · Avoids lookahead bias and reports Sharpe ratio and maximum drawdown. · `scripts/markov_regime.py`
- [Optional HMM fit](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/scripts/markov_regime.py): statistical path · Uses hmmlearn when installation succeeds; otherwise degrades gracefully. · `scripts/markov_regime.py`

### Alternate Delivery

- [Manual bootstrap guide](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/markov-hedge-fund-method.md): onboarding artifact · Instructs Claude Code to create an equivalent local skill installation. · `markov-hedge-fund-method.md`
- [TradingView indicator](https://github.com/jackson-video-resources/markov-hedge-fund-method/blob/main/pine-script/markov-hedge-fund-method.pine): Pine Script v5 · Independent chart-side regime and transition visualization. · `pine-script/markov-hedge-fund-method.pine`

## Connections

- Marketplace manifest → Plugin manifest: publishes
- Plugin manifest → regime skill: installs
- Agent or trading workflow → regime skill: invokes /regime
- regime skill → Regime analysis engine: orchestrates
- Ticker input → yfinance: selects
- yfinance → Price series: fetches history
- Price CSV → Price series: provides
- Price series → Bull/Bear/Sideways labels: rolling returns
- Bull/Bear/Sideways labels → Transition model: historical states
- Transition model → Forecast and baseline: transition matrix
- Forecast and baseline → Directional signal: probabilities
- Directional signal → Agent or trading workflow: JSON output
- Bull/Bear/Sideways labels → Walk-forward backtest: walk-forward states
- Transition model → Walk-forward backtest: strategy evaluation
- Price series → Optional HMM fit: optional fit
- Manual bootstrap guide → regime skill: alternate installation
