/**
* MCP Tool: price_option_black_scholes
*
* Price a European option via Black-Scholes and return price + Greeks.
*/
import { z } from "zod";
import {
priceBlackScholes,
greeksBlackScholes,
BlackScholesParams,
BlackScholesResult,
Greeks,
} from "@quant-companion/core";
export const priceOptionBlackScholesSchema = z.object({
spot: z.number().positive().describe("Current spot price of the underlying"),
strike: z.number().positive().describe("Strike price of the option"),
rate: z
.number()
.describe("Risk-free interest rate (annualized, e.g., 0.05 for 5%)"),
vol: z.number().positive().describe("Volatility (annualized, e.g., 0.25 for 25%)"),
timeToMaturity: z
.number()
.nonnegative()
.describe("Time to maturity in years (e.g., 0.5 for 6 months)"),
dividendYield: z
.number()
.optional()
.default(0)
.describe("Dividend yield (annualized, default 0)"),
optionType: z
.enum(["call", "put"])
.describe("Option type: 'call' or 'put'"),
});
export type PriceOptionBlackScholesInput = z.infer<
typeof priceOptionBlackScholesSchema
>;
export interface PriceOptionBlackScholesOutput {
price: number;
d1: number;
d2: number;
greeks: Greeks;
}
export function priceOptionBlackScholes(
input: PriceOptionBlackScholesInput
): PriceOptionBlackScholesOutput {
const params: BlackScholesParams = {
spot: input.spot,
strike: input.strike,
rate: input.rate,
vol: input.vol,
timeToMaturity: input.timeToMaturity,
dividendYield: input.dividendYield,
optionType: input.optionType,
};
const result: BlackScholesResult = priceBlackScholes(params);
const greeks: Greeks = greeksBlackScholes(params);
return {
price: result.price,
d1: result.d1,
d2: result.d2,
greeks,
};
}
export const priceOptionBlackScholesDefinition = {
name: "price_option_black_scholes",
description:
"Price a European option using the Black-Scholes formula. Returns the theoretical price and Greeks (Delta, Gamma, Theta, Vega, Rho). Use this for standard option pricing when you have all inputs.",
inputSchema: {
type: "object",
properties: {
spot: {
type: "number",
description: "Current spot price of the underlying asset",
},
strike: {
type: "number",
description: "Strike price of the option",
},
rate: {
type: "number",
description:
"Risk-free interest rate (annualized decimal, e.g., 0.05 for 5%)",
},
vol: {
type: "number",
description: "Volatility (annualized decimal, e.g., 0.25 for 25%)",
},
timeToMaturity: {
type: "number",
description: "Time to expiration in years (e.g., 0.5 for 6 months)",
},
dividendYield: {
type: "number",
description: "Dividend yield (annualized decimal, default 0)",
},
optionType: {
type: "string",
enum: ["call", "put"],
description: "Option type: 'call' or 'put'",
},
},
required: ["spot", "strike", "rate", "vol", "timeToMaturity", "optionType"],
},
};