Skip to main content
Glama
nbiish
by nbiish

black_scholes

Calculate option prices using the Black-Scholes model for financial analysis. Input asset price, strike price, time to expiration, risk-free rate, and volatility to determine call or put option values.

Instructions

Calculate Black-Scholes option price

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

  • The handler function executed when the 'black_scholes' tool is called, which destructures inputs and invokes the core Black-Scholes function.
    async ({ S, K, T, r, sigma, optionType }) => {
      return blackScholes(S, K, T, r, sigma, optionType);
    }
  • Zod schemas defining the input parameters (S, K, T, r, sigma, optionType) and output (number or error string) for the black_scholes tool.
    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.number(), z.string()]),
  • index.js:551-569 (registration)
    Registration of the 'black_scholes' tool using ai.defineTool, including name, description, schemas, and handler.
    ai.defineTool(
      {
        name: 'black_scholes',
        description: 'Calculate Black-Scholes option price',
        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.number(), z.string()]),
      },
      async ({ S, K, T, r, sigma, optionType }) => {
        return blackScholes(S, K, T, r, sigma, optionType);
      }
    );
  • Core helper function that computes the Black-Scholes option price using the normal CDF approximation.
    const blackScholes = (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);
    
        if (optionType === 'call') {
          return S * normalCDF(d1) - K * Math.exp(-r * T) * normalCDF(d2);
        } else if (optionType === 'put') {
          return K * Math.exp(-r * T) * normalCDF(-d2) - S * normalCDF(-d1);
        } else {
          throw new Error('Invalid option type. Must be "call" or "put".');
        }
      } catch (e) {
        return `Error: ${e.message}`;
      }
    };
  • Helper function approximating the cumulative distribution function (CDF) of the standard normal distribution, used in Black-Scholes.
    const normalCDF = (x) => {
      const t = 1 / (1 + 0.2316419 * Math.abs(x));
      const d = 0.3989423 * Math.exp(-x * x / 2);
      const p = d * t * (0.319381530 + t * (-0.356563782 + t * (1.781477937 + t * (-1.821255978 + t * 1.330274429))));
      return x >= 0 ? 1 - p : p;
    };
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure but offers minimal information. It states what the tool does but doesn't describe computational characteristics, error conditions, precision, or what happens with invalid inputs. For a mathematical calculation tool with 6 parameters, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise at just 5 words, front-loading the essential information with zero wasted words. Every word earns its place by specifying the calculation type and target, making it efficient for agent comprehension.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mathematical calculation tool with 6 parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what the output represents (e.g., price in what units/currency), doesn't mention the Black-Scholes model assumptions or limitations, and provides no context about when this calculation is appropriate versus alternatives.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has 100% description coverage, with each parameter clearly documented in the input schema. The description doesn't add any parameter information beyond what's already in the schema, so it meets the baseline of 3 for high schema coverage without providing additional value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Calculate') and resource ('Black-Scholes option price'), making it immediately understandable. It doesn't explicitly differentiate from sibling tools like 'option_greeks', but the focus on price calculation rather than Greek calculations provides implicit distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'option_greeks' or other financial calculation tools in the sibling list. It doesn't mention prerequisites, typical use cases, or limitations that would help an agent decide when this is the appropriate choice.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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