MCP Python Quick Start Guide
MCP Python Quick Start Guide
Access the Mammoth 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. Download and Install MCP Excel/Python
Steps:
- Install Python Environment (recommended Python 3.9.12/3.9.13):
- Install via Anaconda or portable Python (refer to Installation Guide).
- Download
mcp_excel
:- Extract
mcp_excel_xxx.zip
to a local directory (e.g.,C:\mcp_excel
).
- Extract
- Configure Development Environment:
- VSCode: Ensure
PYTHONPATH
includeslib/X64
(64-bit systems) orlib/win32
(32-bit systems). - PyCharm: Add
lib/X64
and the project root directory to the interpreter path in project settings.
- VSCode: Ensure
3. MCP Excel/Python Directory Structure
mcp_excel/
├── lib/ # Core library files
│ ├── X64/ # 64-bit system dependencies (DLLs, etc.)
│ └── win32/ # 32-bit system dependencies
├── 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.)
└── .vscode/ # VSCode configuration (includes PYTHONPATH preset)
4. Python Core Module Overview
4.1 Constructors and Parameters
- Module Path:
mcp.tool.tools_main
andmcp.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 Server-Side Construction
- Use Case: Quickly fetch predefined data (requires internet connection).
- Features: Directly construct using short names (
ShortName
), no need for full parameter input. - Example:
from mcp.tool.tools_main import McpYieldCurve # Load predefined yield curve from server curve = McpYieldCurve(ShortName="CNY_IRS_CURVE")
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
- Internet Dependency: Server-side construction requires a stable internet connection (access to MCP servers).
- Path Issues: Ensure
PYTHONPATH
includeslib/X64
orlib/win32
. - Version Compatibility: Python 3.9.x is recommended; other versions may require adjustments.
With this guide, you can quickly set up the environment and start using MCP Python for financial computations!