Skip to main content
Glama

option_greeks

Calculate Black-Scholes option Greeks such as Delta, Gamma, Theta, Vega, and Rho using asset price, strike price, time to expiration, risk-free rate, and volatility for call or put options.

Instructions

Calculate the Greeks for a Black-Scholes option

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
KYesStrike price of the option
SYesCurrent price of the asset
TYesTime to expiration in years
optionTypeNoOption type: "call" or "put"call
rYesRisk-free interest rate
sigmaYesVolatility of the asset

Implementation Reference

  • Core handler function implementing the Black-Scholes Greeks calculation (delta, gamma, vega, theta, rho) for call and put options.
    const optionGreeks = (S, K, T, r, sigma, optionType = 'call') => { try { const d1 = (Math.log(S / K) + (r + 0.5 * sigma * sigma) * T) / (sigma * Math.sqrt(T)); const d2 = d1 - sigma * Math.sqrt(T); let delta, gamma, vega, theta, rho; if (optionType === 'call') { delta = normalCDF(d1); gamma = normalPDF(d1) / (S * sigma * Math.sqrt(T)); vega = S * normalPDF(d1) * Math.sqrt(T); theta = -(S * normalPDF(d1) * sigma) / (2 * Math.sqrt(T)) - r * K * Math.exp(-r * T) * normalCDF(d2); rho = K * T * Math.exp(-r * T) * normalCDF(d2); } else if (optionType === 'put') { delta = normalCDF(d1) - 1; gamma = normalPDF(d1) / (S * sigma * Math.sqrt(T)); vega = S * normalPDF(d1) * Math.sqrt(T); theta = -(S * normalPDF(d1) * sigma) / (2 * Math.sqrt(T)) + r * K * Math.exp(-r * T) * normalCDF(-d2); rho = -K * T * Math.exp(-r * T) * normalCDF(-d2); } else { throw new Error('Invalid option type. Must be "call" or "put".'); } return { delta, gamma, vega, theta, rho }; } catch (e) { return `Error: ${e.message}`; } };
  • Input and output schema validation using Zod for the option_greeks tool, defining parameters and expected return types.
    inputSchema: z.object({ S: z.number().describe('Current price of the asset'), K: z.number().describe('Strike price of the option'), T: z.number().describe('Time to expiration in years'), r: z.number().describe('Risk-free interest rate'), sigma: z.number().describe('Volatility of the asset'), optionType: z.enum(['call', 'put']).default('call') .describe('Option type: "call" or "put"') }), outputSchema: z.union([ z.object({ delta: z.number(), gamma: z.number(), vega: z.number(), theta: z.number(), rho: z.number() }), z.string() ]),
  • index.js:571-598 (registration)
    Tool registration using ai.defineTool, specifying name, description, schemas, and a wrapper handler that delegates to the optionGreeks function.
    ai.defineTool( { name: 'option_greeks', description: 'Calculate the Greeks for a Black-Scholes option', inputSchema: z.object({ S: z.number().describe('Current price of the asset'), K: z.number().describe('Strike price of the option'), T: z.number().describe('Time to expiration in years'), r: z.number().describe('Risk-free interest rate'), sigma: z.number().describe('Volatility of the asset'), optionType: z.enum(['call', 'put']).default('call') .describe('Option type: "call" or "put"') }), outputSchema: z.union([ z.object({ delta: z.number(), gamma: z.number(), vega: z.number(), theta: z.number(), rho: z.number() }), z.string() ]), }, async ({ S, K, T, r, sigma, optionType }) => { return optionGreeks(S, K, T, r, sigma, optionType); } );

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nbiish/mcp-calc-tools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server