MCP Python Quick Start Guide
MCP Python Quick Start Guide
Access the Mathema Options Pricing System, supporting FX options and structured product pricing and valuation!
1. Overview of MCP Excel/Python Structure
MCP Excel/Python includes core modules such as core constructors (
mcp.tool.tools_main), parameter definitions (mcp.tool.args_def), and server version management (mcp.server_version).The framework supports modeling and analysis of various financial instruments, including curve modeling tools (forward curves, yield curves, bond curves), volatility surface tools (FX volatility, interest rate volatility), and financial product objects (bonds, interest rate swaps).
For data access, MCP supports both local data construction and remote market data services.
Key features include flexible polymorphic parameter input, high-performance C++ computation core (
mcp.pyd), and standardized financial enumeration types. Developers can quickly build financial models using concise APIs, such as creating yield curves locally or fetching volatility surface data remotely, suitable for various financial quantitative analysis and derivative pricing scenarios.
2. Install
Python only (recommended) — no Excel, do not set PYTHONPATH:
pip install mathema-mcpPyPI: mathema-mcp. Windows / Linux, 64-bit CPython 3.9–3.13. Then from mcp.tools import McpCalendar. For table APIs (FixedLegs / McpPayoff and similar): pip install "mathema-mcp[data]". Public wheels have no CUDA.
Excel as well — use the zip:
- Install Python (same 64-bit CPython 3.9–3.13): Anaconda or python.org (see the Installation Guide).
- Download the
mcp_excelzip and runinstall.bat(writespyxll.cfg, registers the add-in). - Configure the IDE (do not set a user PYTHONPATH):
- pip install: any working directory.
- zip install: open the extract root with the target 64-bit interpreter.
import mcploadslib/X64/_mcp.cp3xx-win_amd64.pyd. - VSCode / PyCharm: select that interpreter. There is no
lib/win32.
3. MCP Excel/Python Directory Structure
mcp_excel/
├── lib/X64/ # 64-bit core: tagged pyds, pyxll.xll, CUDA runtime
├── example/ # Example code
│ ├── calendar/ # Calendar module examples
│ ├── curve/ # Yield curve examples
│ └── ... # Other examples
├── mcp/ # Python core modules
│ ├── tool/ # Utility classes
│ │ ├── tools_main.py # Main constructors (YieldCurve, FXForwardPointsCurve, etc.)
│ │ └── args_def.py # Parameter definitions (supports polymorphism)
│ ├── mcp.py # Object function implementations
│ └── utils/
│ └── enums.py # Enum types (DayCounter, Frequency, etc.)
├── install.bat # One-click setup (pyxll.cfg + add-in)
└── test_install.py # Install self-check4. Python Core Module Overview
4.1 Constructors and Parameters
- Module Path:
mcp.tool.tools_mainandmcp.tool.args_def.py - Features: Supports polymorphic parameter input (e.g., dictionaries or keyword arguments).
- Example:
from mcp.tool.tools_main import McpYieldCurve # Construct via dictionary args = { "ReferenceDate": "2024-08-20", "Tenors": ["1M", "3M", "6M"], "Rates": [0.05, 0.055, 0.06], "DayCount": "Act365Fixed", ... ... } curve = McpYieldCurve(args) # Construct via keyword arguments curve = McpYieldCurve( ReferenceDate="2024-08-20", Tenors=["1M", "3M", "6M"], Rates=[0.05, 0.055, 0.06], ... ... )
4.2 Object Functions
- Module Path:
mcp.mcp.py - Functionality: Provides object methods (e.g., interest rate calculations, date adjustments).
- Example:
from mcp.mcp import McpFXVolSurface fxVol = McpFXVolSurface( ... ... ) # Get volatility vol = fxVol.GetVolatility(7.0, "2024-12-31")
4.3 Enum Types
- Module Path:
mcp.utils.enums - Common Enums:
from mcp.utils.enums import DayCounter, Frequency print(DayCounter.Act365Fixed) # Day count convention print(Frequency.Annual) # Payment frequency
5. Object Construction Methods
5.1 Local Construction
- Use Case: Requires manual input of market data and parameters.
- Steps:
- Prepare parameters (refer to definitions in
args_def.py). - Call the constructor (e.g.,
McpYieldCurve).
- Prepare parameters (refer to definitions in
- Example:
from mcp.tool.tools_main import McpFXForwardPointsCurve args = { "ReferenceDate": "2024-08-20", "FXSpotRate": 7.2, "ForwardPoints": [-50, -100, -150], "Tenors": ["1M", "2M", "3M"] } fwd_curve = McpFXForwardPointsCurve(args)
5.2 Construct from a JSON snapshot (LiveStore / RawMD)
- Use case: Build curve / surface objects from a local
MCP_MARKET_DATA_YYYYMMDD.jsoninstead of typing the whole curve. - Entry points:
MLiveMarketDataStore(one snapshot),MRawMarketManager(folder by date),MMarketDataJsonReader(read-only). - Example:
from mcp.mcp import MLiveMarketDataStore store = MLiveMarketDataStore() store.loadSnapshot("data/market_data/MCP_MARKET_DATA_20260810.json") yc2 = store.getYieldCurve2("CNHDEPO_2") print(yc2.ZeroRate("2026/08/10", "MID"))
Server-side constructors (function names ending in
s, orShortName=) are retired. For Excel, download the TC31–TC46 example pack. See Raw Market Data.
6. Quick Verification
# Test module imports
from mcp.tool.tools_main import McpYieldCurve
from mcp.utils.enums import DayCounter
# Print enum values
print("Day count convention:", DayCounter.Act365Fixed)
# Simple construction test
test_curve = McpYieldCurve(
ReferenceDate="2024-08-20",
Tenors=["1M"],
Rates=[0.05]
)
print("Test curve constructed successfully!")7. Notes
- Market data: Load curves / surfaces from a local JSON snapshot (LiveStore / RawMD). Server-side constructors are retired.
- Path Issues: Do not set a user PYTHONPATH. Run from the extract root, or put that folder on
sys.path. - Version Compatibility: 64-bit CPython 3.9–3.13;
import mcpneeds the matching_mcp.cp3xx-win_amd64.pyd.
With this guide, you can quickly set up the environment and start using MCP Python for financial computations!
