# Statistical Arbitrage Pairs Strategy AI Agent Connect

> Execute deterministic pairs trading using cointegration tests and z-score signals.

## Overview
- **Category:** finance
- **Price:** Free
- **Endpoint:** https://edge.vinkius.com/vk_preview_pJhH92MSTPFYcNSl8DqLL4oAsumypYyYqmqWuN4O/ai-agent-connect
- **Tags:** arbitrage, pairs-trading, cointegration, quantitative, mean-reversion

## Description

This MCP server provides a deterministic engine for statistical arbitrage. It identifies mean-reverting relationships between two assets by calculating the logarithmic spread and performing an Augmented Dickey-Fuller (ADF) test. Users can use `analyze_pairs_cointegration` to verify if a pair is suitable for trading, `generate_trading_signals` to identify entry and exit points based on z-score thresholds, and `calculate_position_metrics` to determine precise target prices and stop-loss levels. The engine enforces strict filters, such as requiring a half-life of mean reversion under 30 days, to ensure high-quality trading opportunities.

## Tools

### analyze_pairs_cointegration
Evaluates whether two assets exhibit a stable, mean-reverting relationship suitable for trading

### calculate_position_metrics
Provides detailed trade execution parameters for a specific signal

### generate_trading_signals
Determines specific entry, exit, and stop-loss triggers for a pair based on z-score thresholds and cointegration filters

## Prompt Examples

**Prompt:** 
```
Check if these two assets are cointegrated: Asset A prices [100, 101, 102, 101, 100] and Asset B prices [50, 51, 52, 51, 50].
```

**Response:** 
```
The assets are cointegrated with a p-value of 0.02 and a half-life of 12 days, making them suitable for the strategy.
```

**Prompt:** 
```
Generate trading signals for Asset A [10, 11, 12, 11, 10] and Asset B [20, 22, 24, 22, 20] with an entry z-score of 2.0.
```

**Response:** 
```
A BUY spread signal was generated at bar index 2 with entry prices A: 12.0 and B: 24.0, using a hedge ratio of 2.0.
```

**Prompt:** 
```
Calculate the trade metrics for a spread with mean 0, std dev 1, hedge ratio 1.5, and entry prices A: 100, B: 50.
```

**Response:** 
```
The target spread is 0.0, with stop-loss prices calculated at A: 97.0 and B: 48.5 based on the z-score limit.
```

## Frequently Asked Questions

**How does the engine determine if a pair is tradeable?**
The engine uses `analyze_pairs_cointegration` to check if the spread is stationary via an ADF test. A pair is only considered tradeable if the p-value is below 0.05 and the half-life of mean reversion is less than 30 days.

**What information is provided for each trade signal?**
By using `generate_trading_signals`, you receive the bar index, signal type (BUY/SELL/EXIT), entry prices for both assets, the hedge ratio, and specific stop-loss and target prices.

**Can I customize the entry and exit thresholds?**
Yes, when calling `generate_trading_signals`, you can specify custom `entryZScore`, `exitZScore`, and `stopLossZScore` parameters to match your specific risk profile.
