Skip to main content
Glama
nbiish
by nbiish

option_greeks

Calculate option Greeks (Delta, Gamma, Theta, Vega, Rho) using the Black-Scholes model to analyze risk and sensitivity in options trading.

Instructions

Calculate the Greeks for a Black-Scholes option

Input Schema

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

Implementation Reference

  • Core implementation of the option_greeks tool logic, calculating Delta, Gamma, Vega, Theta, and Rho using Black-Scholes formulas 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 definitions for the option_greeks tool using Zod validation.
      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)
    Registration of the 'option_greeks' tool with Genkit's ai.defineTool, linking schema and handler 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);
      }
    );

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