blsprice — Compute Black-Scholes European call and put option prices.
blsprice(Price,Strike,Rate,Time,Volatility) prices European call and put options under the Black-Scholes model. Optional Yield is the continuously compounded dividend or foreign risk-free yield and defaults to zero.
Syntax
[Call, Put] = blsprice(Price, Strike, Rate, Time, Volatility)
[Call, Put] = blsprice(Price, Strike, Rate, Time, Volatility, Yield)Inputs
Price- Type
NumericArray- Required
- Yes
- Description
- Current underlying asset price.
Strike- Type
NumericArray- Required
- Yes
- Description
- Exercise price.
Rate- Type
NumericArray- Required
- Yes
- Description
- Continuously compounded risk-free rate.
Time- Type
NumericArray- Required
- Yes
- Description
- Time to expiration in years.
Volatility- Type
NumericArray- Required
- Yes
- Description
- Annualized asset volatility.
Yield- Type
NumericArray- Required
- No
- Default
0- Description
- Continuously compounded yield.
Returns
Call- Type
NumericArray- Description
- European call option price.
Put- Type
NumericArray- Description
- European put option price.
Returned values from blsprice depend on how many outputs the caller requests.
Errors
RunMat:BlackScholes:InvalidArgument- When
- Inputs, option values, or requested output count are invalid.
- Message
Black-Scholes builtin: invalid argument
RunMat:BlackScholes:InvalidInput- When
- Inputs are nonnumeric, nonfinite, or have incompatible shapes.
- Message
Black-Scholes builtin: invalid input
RunMat:BlackScholes:Internal- When
- Runtime cannot materialize the requested output.
- Message
Black-Scholes builtin: internal error
Inputs and outputs
With one output, blsprice returns the call price; [Call, Put] requests both. A zero-output request produces no output. More than two outputs are rejected before pricing or provider work.
The five required inputs and optional Yield can be scalars or arrays with MATLAB-compatible implicit-expansion dimensions. Empty Yield selects zero. Invalid financial domains and NaN inputs produce elementwise NaN rather than aborting the entire array calculation.
Double inputs produce double call and put prices. Single inputs produce single prices unless a nonscalar double array is also present; scalar double parameters, whether represented as scalar values or 1-by-1 arrays, can accompany single inputs. With no single input the result is double. This input-class rule is independent of provider choice and is RunMat behavior, not a claim about MATLAB's undocumented output-class combinations.
Single-result pricing rounds inputs to single at the calculation boundary. A finite double scalar that would overflow to infinity or underflow to zero in single is rejected before provider work. Fixed-width integer and logical pricing inputs use the double route; a wide integer may round when it enters binary64. The public compatibility target documents double inputs. Single, fixed-width integer, and logical pricing inputs are RunMat-only extensions, admitted before provider work.
GPU and execution
Resident real gpuArray inputs can use the owning provider's black_scholes_price hook. Host scalar or tensor arguments in a mixed call become temporary inputs for that same provider. A provider without the hook uses the host pricing implementation. Resident results from a provider are checked for owner, shape, and physical precision before they are returned.
The provider hook accepts physical single or double inputs only when its precision matches the input-derived result class. A mixed call with a nonscalar double array cannot silently narrow to a single provider; it falls back to host double pricing if that provider cannot execute double. Single is available only in RunMat compatibility mode. This is a custom provider operation, not a fused elementwise kernel. The function can suspend for fallback gathers and does not mutate its arguments.
Examples
European stock option
[Call, Put] = blsprice(100, 95, 0.10, 0.25, 0.50); fprintf('Call = %.4f, Put = %.4f\n', Call, Put);Expected output:
Call = 13.6953, Put = 6.3497Stock index option with yield
[Call, Put] = blsprice(910, 980, 0.02, 0.25, 0.25, 0.025); fprintf('Call = %.4f, Put = %.4f\n', Call, Put);Expected output:
Call = 19.6863, Put = 90.4683Using blsprice with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how blsprice changes the result.
Run a small blsprice example, explain the result, then change one input and compare the output.
FAQ
Can a GPU-resident call remain resident?⌄
Yes when the input owner implements the pricing hook and returns valid owned outputs. Otherwise the operation falls back to the host implementation; there is no generic GPU pricing kernel.
Related Finance functions
Source you can read
Every RunMat function's source is public. Read exactly how blsprice is executed, line by line, in Rust.
- View the source for blsprice in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.