# Pairs Trading Cointegration Strategy AI Agent Connect

> Deterministic pairs trading engine using Engle-Granger cointegration to identify mean-reverting asset pairs.

## Overview
- **Category:** finance
- **Price:** Free
- **Endpoint:** https://edge.vinkius.com/vk_preview_gVhHQcUXa5feMBoutCrUc926mCkFyVloRvHYiZMj/ai-agent-connect
- **Tags:** pairs-trading, cointegration, quant, mean-reversion, engle-granger

## Description

This MCP server provides a deterministic engine for pairs trading based on the Engle-Granger methodology. It allows AI agents to identify statistically significant cointegrated relationships between asset pairs and generate precise trading signals. Using `analyze_pair_cointegration`, agents can determine the hedge ratio, p-value, and half-life of mean reversion. Once a pair is validated, `generate_trading_signals` produces entry, exit, and stop-loss signals based on z-score deviations. Finally, `calculate_position_sizing` ensures trades remain dollar-neutral by calculating the exact quantities of each asset required based on the calculated hedge ratio.

## Tools

### analyze_pair_cointegration
Determine if a specific pair of assets exhibits a statistically significant cointegrated relationship

### generate_trading_signals
Calculate daily z-scores and generate specific entry, exit, and stop-loss signals

### calculate_position_sizing
Determine the exact quantities of Asset A and Asset B to trade to maintain a dollar-neutral profile

## Prompt Examples

**Prompt:** 
```
Analyze the cointegration between these two price series: [100, 101, 102, 101, 100] and [50, 50.5, 51, 50.5, 50].
```

**Response:** 
```
The pair is cointegrated with a p-value of 0.03 and a hedge ratio of 0.5.
```

**Prompt:** 
```
Generate trading signals for a pair with a hedge ratio of 1.5 and z-scores of 2.5, -0.1, and -2.5.
```

**Response:** 
```
The first signal is BUY_SPREAD, the second is HOLD, and the third is SELL_SPREAD.
```

**Prompt:** 
```
Calculate the position size for $10,000 capital with Asset A at $100, Asset B at $50, and a hedge ratio of 2.0.
```

**Response:** 
```
To maintain a dollar-neutral position, you should trade 66.67 units of Asset A and 133.33 units of Asset B.
```

## Frequently Asked Questions

**How does the engine confirm a pair is tradeable?**
The engine uses `analyze_pair_cointegration` to perform an ADF test. A pair is considered tradeable if the p-value is less than 0.05 and the half-life of mean reversion is below the specified limit.

**What is a dollar-neutral position?**
A dollar-neutral position is achieved using `calculate_position_sizing`, where the total dollar value of the long position equals the total dollar value of the short position, minimizing market exposure.

**Can I customize the entry and exit thresholds?**
Yes, the `generate_trading_signals` tool allows you to specify custom entry, exit, and stop-loss z-score thresholds.
