期权策略服务器

MCP期权策略服务器提供高效的看涨和看跌期权交易操作管理工具,适用于金融交易场景。

  • by DefiMan1729
  • Python
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 DefiMan1729/MCP_Options_Strategy

使用说明

MCP期权策略服务器

此存储库包含用于执行的MCP服务器代码 买入期权和卖出期权。 在…上 克劳德桌面。它提供了一种高效管理期权交易操作的简化方法。

入门指南

先决条件

  • 已安装Python 3.8+
  • uv 用于管理依赖关系

设置您的环境

首先,设置您的虚拟环境并安装uv。然后按以下步骤进行:

uv init mcp-server-demo
cd mcp-server-demo

然后将MCP添加到您的项目依赖关系中:

uv add "mcp[cli]"

要使用uv运行mcp命令:

uv run mcp

MCP服务器代码

# server.py
# This script initializes an MCP server for options calculations, 
# providing tools to compute breakeven points and payoffs for Call and Put options.

from mcp.server.fastmcp import FastMCP
from options_library import Put, Call

# Create an instance of the FastMCP server
# "Demo_Options" serves as the namespace for the tools
mcp = FastMCP("Demo_Options")

# Define a tool for Call Option analysis
@mcp.tool()
def call_option(strike: float, premium: float) -> dict:
    """
    Computes breakeven price and potential payoffs for a Call Option.
    
    Parameters:
        strike (float): Strike price of the Call option.
        premium (float): Premium paid to purchase the option.
    
    Returns:
        dict: A dictionary containing:
            - breakeven: Price at which the option breaks even.
            - max_profit: Theoretically infinite (since profits scale with the underlying asset price).
            - max_loss: Fixed loss, equal to the premium paid.
    """
    call = Call(strike, premium)
    return {
        "breakeven": call.breakeven(),
        "max_profit": "infinite",  # Unlimited profit potential
        "max_loss": call.premium   # Limited loss equal to the premium
    }

# Define a tool for Put Option analysis
@mcp.tool()
def put_option(strike: float, premium: float) -> dict:
    """
    Computes breakeven price and potential payoffs for a Put Option.
    
    Parameters:
        strike (float): Strike price of the Put option.
        premium (float): Premium paid to purchase the option.
    
    Returns:
        dict: A dictionary containing:
            - breakeven: Price at which the option breaks even.
            - max_profit: Maximum profit if asset price drops to zero.
            - max_loss: Fixed loss, equal to the premium paid.
    """
    put = Put(strike, premium)
    return {
        "breakeven": put.breakeven(),
        "max_profit": strike - premium,  # Profit is capped at the strike price minus the premium
        "max_loss": premium               # Limited loss equal to the premium
    }

运行MCP服务器

mcp install server.py

Claude Desktop配置文件和屏幕截图

{
  "mcpServers": {
    "server": {
      "command": "/Users/arkaroychowdhury/.local/bin/uv",
      "args": [
        "run",
        "--with",
        "mcp[cli]",
        "mcp",
        "run",
        "/Users/arkaroychowdhury/Desktop/2025-Portfolio/Code/MCP/mcp-server-demo/server.py"
      ]
    }
  }
}