← Back to documentation

API Reference

Complete documentation for all floe functions and types.

Pricing Functions

blackScholes

Calculates the theoretical price of a European option using the Black-Scholes-Merton model.

import { blackScholes } from "@fullstackcraftllc/floe";

const price = blackScholes({
  spot: 100,           // Current price of underlying
  strike: 105,         // Option strike price
  timeToExpiry: 0.25,  // Time to expiration in years
  riskFreeRate: 0.05,  // Annual risk-free interest rate
  volatility: 0.20,    // Annualized volatility (as decimal)
  optionType: "call",  // "call" or "put"
  dividendYield: 0.02  // Optional: continuous dividend yield (as decimal)
});

blackScholes computes the price only, at full double precision. It no longer rounds to cents or computes Greeks. At zero time to expiration it returns the intrinsic value, and at zero volatility the discounted deterministic payoff max(0, ±(S·e^(−qT) − K·e^(−rT))). A zero spot is valid, so a put is worth K·e^(−rT) there. Negative spot, time or volatility, a nonpositive strike, non-finite numbers and unknown option types throw a RangeError. Releases up to 0.0.21 returned a rounded price and returned 0 for these edge and invalid inputs. calculateGreeks().price still rounds to two decimals.

Implied Volatility

calculateImpliedVolatility

Uses the Black-Scholes model with iterative bisection to compute the implied volatility given an option price.

import { calculateImpliedVolatility } from "@fullstackcraftllc/floe";

const iv = calculateImpliedVolatility(
  3.50,      // price: observed option price
  100,       // spot: current underlying price
  105,       // strike: option strike price
  0.05,      // riskFreeRate: annual risk-free rate (as decimal)
  0.02,      // dividendYield: continuous dividend yield (as decimal)
  0.25,      // timeToExpiry: time to expiration in years
  "call"     // optionType: "call" or "put"
);

console.log(`Implied Volatility: ${iv.toFixed(2)}%`);
// Note: Returns IV as a percentage (e.g., 20.0 for 20% volatility)

The bisection now inverts the unrounded price, so it is no longer limited to cent precision. It still returns 0 instead of throwing when the price, spot, strike or time is nonpositive or any input is not finite.

Greeks

calculateGreeks

Calculate all Greeks up to third order for European call and put options. Returns a complete Greeks object containing the option price and all sensitivity measures.

import { calculateGreeks } from "@fullstackcraftllc/floe";

const greeks = calculateGreeks({
  spot: 100,
  strike: 105,
  timeToExpiry: 0.25,
  riskFreeRate: 0.05,
  volatility: 0.20,
  optionType: "call",      // "call" or "put"
  dividendYield: 0.02      // optional
});

// Access individual Greeks from the returned object:
console.log(`Price: ${greeks.price}`);
console.log(`Delta: ${greeks.delta}`);
console.log(`Gamma: ${greeks.gamma}`);
console.log(`Theta: ${greeks.theta}`);   // per day
console.log(`Vega: ${greeks.vega}`);     // per 1% volatility change
console.log(`Rho: ${greeks.rho}`);       // per 1% rate change

Greeks Interface

The calculateGreeks function returns a Greeks object with all sensitivity measures:

interface Greeks {
  price: number;   // Option theoretical value
  delta: number;   // Rate of change of option price with respect to underlying
  gamma: number;   // Rate of change of delta with respect to underlying
  theta: number;   // Time decay (per day)
  vega: number;    // Sensitivity to volatility (per 1% change)
  rho: number;     // Sensitivity to interest rate (per 1% change)
  vanna: number;   // Sensitivity of delta to volatility
  charm: number;   // Delta decay (per day)
  volga: number;   // Sensitivity of vega to volatility (also known as vomma)
  speed: number;   // Rate of change of gamma
  zomma: number;   // Sensitivity of gamma to volatility
  color: number;   // Gamma decay
  ultima: number;  // Sensitivity of volga to volatility
}

Time Utilities

getTimeToExpirationInYears

Convert an expiration timestamp to time in years:

import { getTimeToExpirationInYears } from "@fullstackcraftllc/floe";

const expirationTimestamp = Date.now() + 30 * 24 * 60 * 60 * 1000; // 30 days from now
const timeToExpiry = getTimeToExpirationInYears(expirationTimestamp);
// Returns: ~0.0822 (30/365)

getMillisecondsToExpiration

Get milliseconds until expiration:

import { getMillisecondsToExpiration } from "@fullstackcraftllc/floe";

const ms = getMillisecondsToExpiration(expirationTimestamp);

Statistical Utilities

cumulativeNormalDistribution

Standard normal cumulative distribution function (CDF):

import { cumulativeNormalDistribution } from "@fullstackcraftllc/floe";

const prob = cumulativeNormalDistribution(1.96);
// Returns: ~0.975 (97.5% probability)

normalPDF

Standard normal probability density function:

import { normalPDF } from "@fullstackcraftllc/floe";

const density = normalPDF(0);
// Returns: ~0.3989 (peak of the normal curve)

IV Surfaces

getIVSurfaces

Generate implied volatility surfaces for all options across all expirations. Used as input for dealer exposure calculations.

import { getIVSurfaces, OptionChain } from "@fullstackcraftllc/floe";

const chain: OptionChain = {
  symbol: 'SPY',
  spot: 450.50,
  riskFreeRate: 0.05,
  dividendYield: 0.02,
  options: normalizedOptions
};

const surfaces = getIVSurfaces('blackscholes', 'totalvariance', chain);
// Returns array of IVSurface objects with rawIVs and smoothedIVs

getIVForStrike

Lookup a specific IV from the surface:

import { getIVForStrike } from "@fullstackcraftllc/floe";

const iv = getIVForStrike(surfaces, expirationTimestamp, 'call', 105);
// Returns smoothed IV as percentage (e.g., 23.0 for 23%)

smoothTotalVarianceSmile

Apply total variance smoothing to a volatility smile:

import { smoothTotalVarianceSmile } from "@fullstackcraftllc/floe";

const smoothedIVs = smoothTotalVarianceSmile(
  [90, 95, 100, 105, 110],  // strikes
  [22, 20, 18, 20, 22],      // raw IVs as percentages
  0.25                        // time to expiry in years
);

Dealer Exposures

calculateGammaVannaCharmExposures

Calculate aggregate dealer exposures across an option chain:

import { 
  calculateGammaVannaCharmExposures, 
  getIVSurfaces 
} from "@fullstackcraftllc/floe";

const ivSurfaces = getIVSurfaces('blackscholes', 'totalvariance', chain);
const exposureVariants = calculateGammaVannaCharmExposures(chain, ivSurfaces);

// exposureVariants contains canonical, stateWeighted, and flowDelta modes.
// Project canonical mode if downstream code expects ExposurePerExpiry.
const exposures = exposureVariants.map(e => ({ spotPrice: e.spotPrice, expiration: e.expiration, ...e.canonical }));

for (const expiry of exposures) {
  console.log(`Expiration: ${new Date(expiry.expiration).toDateString()}`);
  console.log(`  Total Gamma: ${expiry.totalGammaExposure}`);
  console.log(`  Total Vanna: ${expiry.totalVannaExposure}`);
  console.log(`  Total Charm: ${expiry.totalCharmExposure}`);
}

calculateSharesNeededToCover

Calculate dealer hedging requirements:

import { calculateSharesNeededToCover } from "@fullstackcraftllc/floe";

const coverage = calculateSharesNeededToCover(
  900_000_000,   // shares outstanding
  -5_000_000,    // net exposure
  450.50         // spot price
);

console.log(`Action: ${coverage.actionToCover}`);
console.log(`Shares: ${coverage.sharesToCover}`);
console.log(`Implied Move: ${coverage.impliedMoveToCover}%`);

Implied PDF

estimateImpliedProbabilityDistribution

Estimate implied probability distribution for a single expiration:

import { estimateImpliedProbabilityDistribution } from "@fullstackcraftllc/floe";

const result = estimateImpliedProbabilityDistribution("QQQ", 502.50, callOptions);

if (result.success) {
  const dist = result.distribution;
  console.log(`Mode: ${dist.mostLikelyPrice}`);
  console.log(`Expected Move: ${dist.expectedMove}`);
}

estimateImpliedProbabilityDistributions

Process all expirations at once:

import { estimateImpliedProbabilityDistributions } from "@fullstackcraftllc/floe";

const distributions = estimateImpliedProbabilityDistributions("QQQ", 502.50, options);

getProbabilityInRange

Get probability of finishing in a price range:

import { getProbabilityInRange } from "@fullstackcraftllc/floe";

const prob = getProbabilityInRange(distribution, 495, 510);
// Returns probability (e.g., 0.65 for 65%)

getCumulativeProbability

Get cumulative probability up to a price:

import { getCumulativeProbability } from "@fullstackcraftllc/floe";

const prob = getCumulativeProbability(distribution, 500);

getQuantile

Get strike at a probability quantile:

import { getQuantile } from "@fullstackcraftllc/floe";

const p10 = getQuantile(distribution, 0.10);  // 10th percentile
const p90 = getQuantile(distribution, 0.90);  // 90th percentile

Dataset API Clients

NewApiClient

Use the unified API client to query hindsight, dealer surface, and AMT datasets:

import { NewApiClient } from "@fullstackcraftllc/floe";

const client = NewApiClient(process.env.FLOE_DATA_API_KEY!);

GetHindsightData

const events = await client.GetHindsightData(undefined, {
  start_date: "2026-03-01",
  end_date: "2026-03-16",
  country: "US",
  min_volatility: 2,
  event: "CPI",
});

GetHindsightSample

const sample = await client.GetHindsightSample(undefined);

GetDealerMinuteSurfaces

const rows = await client.GetDealerMinuteSurfaces(undefined, {
  symbol: "SPY",
  trade_date: "2026-03-10",
});

GetAMTSessionStats

const rows = await client.GetAMTSessionStats(undefined, {
  symbol: "NQ",
  session_id: "2026-03-10",
});

GetAMTEvents

const rows = await client.GetAMTEvents(undefined, {
  symbol: "NQ",
  session_id: "2026-03-10",
});

Exposure-Adjusted Implied PDF

estimateExposureAdjustedPDF

Modify the Breeden-Litzenberger implied PDF to account for dealer gamma, vanna, and charm positioning effects:

import {
  estimateExposureAdjustedPDF,
  calculateGammaVannaCharmExposures,
  getIVSurfaces,
} from "@fullstackcraftllc/floe";

const ivSurfaces = getIVSurfaces('blackscholes', 'totalvariance', chain);
const exposureVariants = calculateGammaVannaCharmExposures(chain, ivSurfaces);
const exposures = exposureVariants.map(e => ({ spotPrice: e.spotPrice, expiration: e.expiration, ...e.canonical }));

// Use call options for the same expiration as the exposures
const callOptions = chain.options.filter(
  o => o.optionType === 'call' && o.expirationTimestamp === exposures[0].expiration
);

const result = estimateExposureAdjustedPDF(
  'SPY',
  chain.spot,
  callOptions,
  exposures[0],      // ExposurePerExpiry for the target expiration
  {}                  // Optional: partial ExposureAdjustmentConfig overrides
);

if (result.success) {
  console.log(`Baseline mode: $${result.baseline.mostLikelyPrice}`);
  console.log(`Adjusted mode: $${result.adjusted.mostLikelyPrice}`);
  console.log(`Mean shift: ${result.comparison.meanShift.toFixed(2)}`);
  console.log(`Skew change: ${result.comparison.skewChange.toFixed(4)}`);
  console.log(`Kurtosis change: ${result.comparison.kurtosisChange.toFixed(4)}`);
}

Preset Configurations

Four regime-specific configurations are exported:

import {
  DEFAULT_ADJUSTMENT_CONFIG,  // Balanced for normal markets
  LOW_VOL_CONFIG,             // Strong gamma pinning, moderate vanna
  CRISIS_CONFIG,              // Amplified vanna cascade, weak pinning
  OPEX_CONFIG,                // Strong pinning + accelerated charm
} from "@fullstackcraftllc/floe";

// Use a preset
const result = estimateExposureAdjustedPDF('SPY', spot, calls, exposures[0], CRISIS_CONFIG);

getEdgeAtPrice

Compare cumulative probabilities between baseline and adjusted distributions at a given price:

import { getEdgeAtPrice } from "@fullstackcraftllc/floe";

// Positive edge = adjusted PDF assigns more probability below this price
const edge = getEdgeAtPrice(result, 445.0);
console.log(`Edge at $445: ${(edge * 100).toFixed(2)}%`);

getSignificantAdjustmentLevels

Find strikes where the exposure adjustment has the largest effect:

import { getSignificantAdjustmentLevels } from "@fullstackcraftllc/floe";

const levels = getSignificantAdjustmentLevels(result, 0.01); // 1% threshold

for (const level of levels) {
  console.log(`$${level.strike}: baseline ${(level.baselineProb * 100).toFixed(1)}% → adjusted ${(level.adjustedProb * 100).toFixed(1)}% (edge: ${(level.edge * 100).toFixed(2)}%)`);
}

Hedge Flow Analysis

Combines dealer gamma and vanna exposures into an actionable price-space response curve, paired with a charm integral that captures time-decay pressure independently.

deriveRegimeParams

Extract market regime parameters from the IV surface:

import { deriveRegimeParams, getIVSurfaces } from "@fullstackcraftllc/floe";

const ivSurfaces = getIVSurfaces('blackscholes', 'totalvariance', chain);

// Use a call surface for regime derivation
const callSurface = ivSurfaces.find(s => s.putCall === 'call');
const regime = deriveRegimeParams(callSurface, chain.spot);

console.log(`Regime: ${regime.regime}`);         // 'calm' | 'normal' | 'stressed' | 'crisis'
console.log(`ATM IV: ${(regime.atmIV * 100).toFixed(1)}%`);
console.log(`Spot-Vol Correlation: ${regime.impliedSpotVolCorr.toFixed(3)}`);
console.log(`Vol of Vol: ${regime.impliedVolOfVol.toFixed(4)}`);
console.log(`Expected Daily Vol Move: ${(regime.expectedDailyVolMove * 100).toFixed(2)} pts`);

computeHedgeImpulseCurve

Compute the hedge impulse curve H(S) = GEX(S) - (k/S) × VEX(S) across a price grid:

import {
  computeHedgeImpulseCurve,
  calculateGammaVannaCharmExposures,
  getIVSurfaces,
} from "@fullstackcraftllc/floe";

const ivSurfaces = getIVSurfaces('blackscholes', 'totalvariance', chain);
const exposureVariants = calculateGammaVannaCharmExposures(chain, ivSurfaces);
const exposures = exposureVariants.map(e => ({ spotPrice: e.spotPrice, expiration: e.expiration, ...e.canonical }));
const callSurface = ivSurfaces.find(s => s.putCall === 'call');

const curve = computeHedgeImpulseCurve(
  exposures[0],    // ExposurePerExpiry for target expiration
  callSurface,     // IVSurface for regime/k derivation
  {                // Optional HedgeImpulseConfig
    rangePercent: 3,         // ±3% price grid (default)
    stepPercent: 0.05,       // 0.05% grid step (default)
    kernelWidthStrikes: 2,   // kernel = 2 × strike spacing (default)
  }
);

// Instantaneous reading at current spot
console.log(`Impulse at spot: ${curve.impulseAtSpot.toFixed(0)}`);
console.log(`Slope at spot: ${curve.slopeAtSpot.toFixed(0)}`);
console.log(`Regime: ${curve.regime}`);
console.log(`Spot-vol coupling k: ${curve.spotVolCoupling.toFixed(2)}`);
console.log(`Strike spacing: ${curve.strikeSpacing}`);
console.log(`Kernel width: ${curve.kernelWidth.toFixed(1)} points`);

// Key levels
console.log(`
Zero crossings (flip levels):`);
for (const zc of curve.zeroCrossings) {
  console.log(`  $${zc.price.toFixed(1)} (${zc.direction})`);
}

console.log(`
Attractors (positive impulse basins):`);
for (const ext of curve.extrema.filter(e => e.type === 'basin')) {
  console.log(`  $${ext.price.toFixed(1)} (impulse: ${ext.impulse.toFixed(0)})`);
}

console.log(`
Accelerators (negative impulse peaks):`);
for (const ext of curve.extrema.filter(e => e.type === 'peak')) {
  console.log(`  $${ext.price.toFixed(1)} (impulse: ${ext.impulse.toFixed(0)})`);
}

// Directional asymmetry
const a = curve.asymmetry;
console.log(`
Directional bias: ${a.bias}`);
console.log(`Asymmetry ratio: ${a.asymmetryRatio.toFixed(2)}`);

// Nearest attractors
if (curve.nearestAttractorAbove) {
  console.log(`Nearest attractor above: $${curve.nearestAttractorAbove.toFixed(1)}`);
}
if (curve.nearestAttractorBelow) {
  console.log(`Nearest attractor below: $${curve.nearestAttractorBelow.toFixed(1)}`);
}

computeCharmIntegral

Compute the cumulative charm exposure from now until expiration:

import { computeCharmIntegral } from "@fullstackcraftllc/floe";

const charm = computeCharmIntegral(
  exposures[0],    // ExposurePerExpiry
  { timeStepMinutes: 15 }  // Optional CharmIntegralConfig
);

console.log(`Minutes remaining: ${charm.minutesRemaining.toFixed(0)}`);
console.log(`Total charm to close: ${charm.totalCharmToClose.toLocaleString()}`);
console.log(`Direction: ${charm.direction}`);  // 'buying' | 'selling' | 'neutral'

// Time-bucketed curve for visualization
console.log(`\nCharm curve (${charm.buckets.length} buckets):`);
for (const bucket of charm.buckets.slice(0, 5)) {
  console.log(`  ${bucket.minutesRemaining.toFixed(0)} min remaining: cumulative ${bucket.cumulativeCEX.toLocaleString()}`);
}

// Per-strike breakdown (top contributors)
console.log(`\nTop charm contributors:`);
for (const sc of charm.strikeContributions.slice(0, 5)) {
  console.log(`  $${sc.strike}: ${sc.charmExposure.toLocaleString()} (${(sc.fractionOfTotal * 100).toFixed(1)}%)`);
}

analyzeHedgeFlow

Convenience function that computes both the impulse curve and charm integral in a single call:

import { analyzeHedgeFlow } from "@fullstackcraftllc/floe";

const analysis = analyzeHedgeFlow(
  exposures[0],    // ExposurePerExpiry
  callSurface,     // IVSurface
  { rangePercent: 3, kernelWidthStrikes: 2 },  // Optional impulse config
  { timeStepMinutes: 15 }                       // Optional charm config
);

// Access both panels
const { impulseCurve, charmIntegral, regimeParams } = analysis;

console.log(`Regime: ${regimeParams.regime}`);
console.log(`Impulse regime: ${impulseCurve.regime}`);
console.log(`Impulse at spot: ${impulseCurve.impulseAtSpot.toFixed(0)}`);
console.log(`Charm to close: ${charmIntegral.totalCharmToClose.toLocaleString()}`);
console.log(`Charm direction: ${charmIntegral.direction}`);

Model-Free Implied Volatility

Computes implied volatility from the full option chain using the CBOE variance swap methodology. Model-free (no Black-Scholes inversion required) and applicable to any optionable underlying.

computeVarianceSwapIV

Compute model-free implied variance for a single expiration:

import { computeVarianceSwapIV } from "@fullstackcraftllc/floe";

// Pass all options for one expiration (both calls and puts)
const todayOptions = chain.options.filter(
  o => o.expirationTimestamp === todayExpiration
);

const result = computeVarianceSwapIV(todayOptions, chain.spot, 0.05);

console.log(`Implied Vol: ${(result.impliedVolatility * 100).toFixed(1)}%`);
console.log(`Forward: $${result.forward.toFixed(2)}`);
console.log(`K₀ (ATM strike): $${result.k0}`);
console.log(`Time to expiry: ${(result.timeToExpiry * 365).toFixed(2)} days`);
console.log(`Strikes contributing: ${result.numStrikes}`);
console.log(`Put contribution: ${result.putContribution.toFixed(6)}`);
console.log(`Call contribution: ${result.callContribution.toFixed(6)}`);

computeImpliedVolatility

Single-term or two-term interpolated implied volatility. Supports the standard CBOE VIX interpolation when two expirations are provided:

import { computeImpliedVolatility } from "@fullstackcraftllc/floe";

// Single-term: IV from one expiration
const singleTerm = computeImpliedVolatility(todayOptions, chain.spot, 0.05);
console.log(`0DTE IV: ${(singleTerm.impliedVolatility * 100).toFixed(1)}%`);

// Two-term interpolation: bracket a target maturity
const tomorrowOptions = chain.options.filter(
  o => o.expirationTimestamp === tomorrowExpiration
);

const interpolated = computeImpliedVolatility(
  todayOptions,          // near-term options
  chain.spot,
  0.05,
  tomorrowOptions,       // far-term options
  1                      // target: 1-day constant maturity
);

console.log(`Interpolated IV: ${(interpolated.impliedVolatility * 100).toFixed(1)}%`);
console.log(`Is interpolated: ${interpolated.isInterpolated}`);
console.log(`Near-term IV: ${(interpolated.nearTerm.impliedVolatility * 100).toFixed(1)}%`);
console.log(`Far-term IV: ${(interpolated.farTerm?.impliedVolatility ?? 0 * 100).toFixed(1)}%`);

Realized Volatility

Computes annualized realized volatility from price observations using quadratic variation. Tick-based, stateless, no windowing — pass all observations and it computes from the full series.

computeRealizedVolatility

import { computeRealizedVolatility, PriceObservation } from "@fullstackcraftllc/floe";

// Accumulate price observations from streaming data
const observations: PriceObservation[] = [
  { price: 600.10, timestamp: 1708099800000 },
  { price: 600.25, timestamp: 1708099860000 },
  { price: 599.80, timestamp: 1708099920000 },
  // ... every tick from the session
];

const rv = computeRealizedVolatility(observations);

console.log(`Realized Vol: ${(rv.realizedVolatility * 100).toFixed(1)}%`);
console.log(`Observations: ${rv.numObservations}`);
console.log(`Returns computed: ${rv.numReturns}`);
console.log(`Elapsed: ${rv.elapsedMinutes.toFixed(0)} minutes`);
console.log(`Quadratic variation: ${rv.quadraticVariation.toFixed(8)}`);

OCC Symbol Utilities

buildOCCSymbol

Build an OCC-formatted option symbol:

import { buildOCCSymbol } from "@fullstackcraftllc/floe";

const symbol = buildOCCSymbol({
  symbol: 'AAPL',
  expiration: '2025-01-17',
  optionType: 'call',
  strike: 150,
  padded: false  // optional, default false
});
// Returns: 'AAPL250117C00150000'

parseOCCSymbol

Parse an OCC symbol into components:

import { parseOCCSymbol } from "@fullstackcraftllc/floe";

const parsed = parseOCCSymbol('AAPL250117C00150000');
// Returns: { symbol: 'AAPL', expiration: Date, optionType: 'call', strike: 150 }

generateStrikesAroundSpot

Generate strike prices around a spot price:

import { generateStrikesAroundSpot } from "@fullstackcraftllc/floe";

const strikes = generateStrikesAroundSpot({
  spot: 450,
  strikesAbove: 10,
  strikesBelow: 10,
  strikeIncrementInDollars: 5
});
// Returns: [400, 405, 410, ..., 495, 500]

generateOCCSymbolsForStrikes

Generate OCC symbols for specific strikes:

import { generateOCCSymbolsForStrikes } from "@fullstackcraftllc/floe";

const symbols = generateOCCSymbolsForStrikes(
  'SPY',
  '2025-12-20',
  [440, 445, 450, 455, 460],
  ['call', 'put']  // optional, default both
);

generateOCCSymbolsAroundSpot

Convenience function combining strike generation and OCC symbol creation:

import { generateOCCSymbolsAroundSpot } from "@fullstackcraftllc/floe";

const symbols = generateOCCSymbolsAroundSpot('SPY', '2025-12-20', 600, {
  strikesAbove: 10,
  strikesBelow: 10,
  strikeIncrementInDollars: 1
});

Broker Adapters

createOptionChain

Create an option chain from raw broker data:

import { createOptionChain } from "@fullstackcraftllc/floe";

const chain = createOptionChain(
  'SPY',           // symbol
  450.50,          // spot
  0.05,            // riskFreeRate
  0.02,            // dividendYield
  rawBrokerData,   // raw options from broker
  'schwab'         // broker name for adapter selection
);

getAdapter

Get a specific broker adapter:

import { getAdapter } from "@fullstackcraftllc/floe";

const adapter = getAdapter('schwab');
const normalizedOption = adapter(rawOptionData);

Available Adapters

import { 
  genericAdapter,
  schwabAdapter,
  ibkrAdapter,
  tdaAdapter,
  brokerAdapters 
} from "@fullstackcraftllc/floe";

// brokerAdapters is a map: { generic, schwab, ibkr, tda }

Real-Time Market Data (FloeClient)

Supported Brokers

Broker Enum Value Authentication
Tradier Broker.TRADIER API Token
TastyTrade Broker.TASTYTRADE OAuth access token (15 min; refresh and pass to updateAuthToken)
TradeStation Broker.TRADESTATION OAuth Token
Webull Broker.WEBULL OAuth Token + signed proxy
Charles Schwab Broker.SCHWAB OAuth Token
Interactive Brokers Broker.IBKR OAuth Token

Basic Usage

import { FloeClient, Broker } from "@fullstackcraftllc/floe";

const client = new FloeClient({ verbose: false });
await client.connect(Broker.TRADIER, 'your-api-token');

client.on('optionUpdate', (option) => {
  console.log(`${option.occSymbol}: ${option.bid} / ${option.ask}`);
});

client.on('tickerUpdate', (ticker) => {
  console.log(`${ticker.symbol}: ${ticker.spot}`);
});

client.subscribeToOptions(['SPY251220C00600000']);
client.subscribeToTickers(['SPY']);
await client.fetchOpenInterest();

client.disconnect();

For TastyTrade, the auth token is an OAuth access token, and those expire after 15 minutes. An open stream keeps running on its DxLink quote token, but a reconnect needs a current access token, so refresh it before it expires and hand it over:

client.updateAuthToken(newAccessToken);

A failed TastyTrade connect() rejects with a TastyTradeApiError that carries the HTTP status and TastyTrade's error code (for example quote_streamer.customer_not_found_error for an account that isn't fully opened). Open interest arrives on DxLink Summary events, so fetchOpenInterest() resolves immediately for TastyTrade.

For Webull, keep request signing in your server-side proxy and pass the proxy configuration through the normal auth-token argument:

import { Broker, createWebullAuthToken, FloeClient } from "@fullstackcraftllc/floe";

const client = new FloeClient();
const authToken = createWebullAuthToken({
  accessToken: webullOAuthAccessToken,
  proxyUrl: '/.netlify/functions/webullMarketData',
});

await client.connect(Broker.WEBULL, authToken);

Direct Broker Client Access

import { TradierClient, TastyTradeClient, TradeStationClient, WebullClient } from "@fullstackcraftllc/floe";

// Use broker clients directly for advanced scenarios
const tradier = new TradierClient(token, { verbose: true });

Core Types

OptionType

type OptionType = 'call' | 'put';

BlackScholesParams

interface BlackScholesParams {
  spot: number;
  strike: number;
  timeToExpiry: number;
  volatility: number;
  riskFreeRate: number;
  optionType: OptionType;
  dividendYield?: number;
}

NormalizedOption

interface NormalizedOption {
  occSymbol: string;
  underlying: string;
  strike: number;
  expiration: string;
  expirationTimestamp: number;
  optionType: OptionType;
  bid: number;
  bidSize: number;
  ask: number;
  askSize: number;
  mark: number;
  last: number;
  volume: number;
  openInterest: number;
  liveOpenInterest?: number;
  impliedVolatility: number;
  timestamp: number;
}

NormalizedTicker

interface NormalizedTicker {
  symbol: string;
  spot: number;
  bid: number;
  bidSize: number;
  ask: number;
  askSize: number;
  last: number;
  volume: number;
  timestamp: number;
}

OptionChain

interface OptionChain {
  symbol: string;
  spot: number;
  riskFreeRate: number;
  dividendYield: number;
  options: NormalizedOption[];
}

IVSurface

interface IVSurface {
  expirationDate: number;
  putCall: OptionType;
  strikes: number[];
  rawIVs: number[];
  smoothedIVs: number[];
}

ExposureVector

interface ExposureVector {
  gammaExposure: number;
  vannaExposure: number;
  charmExposure: number;
  netExposure: number;
}

ExposureModeBreakdown

interface ExposureModeBreakdown {
  totalGammaExposure: number;
  totalVannaExposure: number;
  totalCharmExposure: number;
  totalNetExposure: number;
  strikeOfMaxGamma: number;
  strikeOfMinGamma: number;
  strikeOfMaxVanna: number;
  strikeOfMinVanna: number;
  strikeOfMaxCharm: number;
  strikeOfMinCharm: number;
  strikeOfMaxNet: number;
  strikeOfMinNet: number;
  strikeExposures: StrikeExposure[];
}

StrikeExposureVariants

interface StrikeExposureVariants {
  strikePrice: number;
  canonical: ExposureVector;
  stateWeighted: ExposureVector;
  flowDelta: ExposureVector;
}

ExposureVariantsPerExpiry

interface ExposureVariantsPerExpiry {
  spotPrice: number;
  expiration: number;
  canonical: ExposureModeBreakdown;
  stateWeighted: ExposureModeBreakdown;
  flowDelta: ExposureModeBreakdown;
  strikeExposureVariants: StrikeExposureVariants[];
}

ExposurePerExpiry (Canonical Projection)

interface ExposurePerExpiry {
  spotPrice: number;
  expiration: number;
  totalGammaExposure: number;
  totalVannaExposure: number;
  totalCharmExposure: number;
  totalNetExposure: number;
  strikeOfMaxGamma: number;
  strikeOfMinGamma: number;
  strikeOfMaxVanna: number;
  strikeOfMinVanna: number;
  strikeOfMaxCharm: number;
  strikeOfMinCharm: number;
  strikeOfMaxNet: number;
  strikeOfMinNet: number;
  strikeExposures: StrikeExposure[];
}

ImpliedProbabilityDistribution

interface ImpliedProbabilityDistribution {
  symbol: string;
  expiryDate: number;
  calculationTimestamp: number;
  underlyingPrice: number;
  strikeProbabilities: StrikeProbability[];
  mostLikelyPrice: number;
  medianPrice: number;
  expectedValue: number;
  expectedMove: number;
  tailSkew: number;
  cumulativeProbabilityAboveSpot: number;
  cumulativeProbabilityBelowSpot: number;
}

RegimeParams

type MarketRegime = 'calm' | 'normal' | 'stressed' | 'crisis';

interface RegimeParams {
  regime: MarketRegime;
  atmIV: number;                 // decimal (e.g. 0.18 for 18%)
  impliedSpotVolCorr: number;    // typically [-0.9, -0.5] for indices
  impliedVolOfVol: number;
  expectedDailyMove: number;
  expectedDailyVolMove: number;
}

HedgeImpulseCurve

interface HedgeImpulseCurve {
  spot: number;
  expiration: number;
  computedAt: number;
  spotVolCoupling: number;       // k coefficient derived from IV skew
  kernelWidth: number;           // in price units
  strikeSpacing: number;         // detected modal strike spacing
  curve: HedgeImpulsePoint[];    // full price grid
  impulseAtSpot: number;         // H(S) at current spot
  slopeAtSpot: number;           // dH/dS at current spot
  zeroCrossings: ZeroCrossing[];
  extrema: ImpulseExtremum[];
  asymmetry: DirectionalAsymmetry;
  regime: ImpulseRegime;         // 'pinned' | 'expansion' | 'squeeze-up' | 'squeeze-down' | 'neutral'
  nearestAttractorAbove: number | null;
  nearestAttractorBelow: number | null;
}

interface HedgeImpulsePoint {
  price: number;
  gamma: number;    // kernel-smoothed GEX at this price
  vanna: number;    // kernel-smoothed VEX at this price
  impulse: number;  // gamma - (k/S) * vanna
}

interface ZeroCrossing {
  price: number;
  direction: 'rising' | 'falling';
}

interface ImpulseExtremum {
  price: number;
  impulse: number;
  type: 'basin' | 'peak';  // basin = attractor, peak = accelerator
}

interface DirectionalAsymmetry {
  upside: number;
  downside: number;
  integrationRangePercent: number;
  bias: 'up' | 'down' | 'neutral';
  asymmetryRatio: number;
}

CharmIntegral

interface CharmIntegral {
  spot: number;
  expiration: number;
  computedAt: number;
  minutesRemaining: number;
  totalCharmToClose: number;
  direction: 'buying' | 'selling' | 'neutral';
  buckets: CharmBucket[];
  strikeContributions: Array<{
    strike: number;
    charmExposure: number;
    fractionOfTotal: number;
  }>;
}

interface CharmBucket {
  minutesRemaining: number;
  instantaneousCEX: number;
  cumulativeCEX: number;
}

VarianceSwapResult

interface VarianceSwapResult {
  impliedVolatility: number;   // annualized, decimal
  annualizedVariance: number;
  forward: number;             // forward price F
  k0: number;                  // ATM strike
  timeToExpiry: number;
  expiration: number;
  numStrikes: number;
  putContribution: number;
  callContribution: number;
}

ImpliedVolatilityResult

interface ImpliedVolatilityResult {
  impliedVolatility: number;
  nearTerm: VarianceSwapResult;
  farTerm: VarianceSwapResult | null;
  targetDays: number | null;
  isInterpolated: boolean;
}

PriceObservation

interface PriceObservation {
  price: number;
  timestamp: number;  // milliseconds
}

RealizedVolatilityResult

interface RealizedVolatilityResult {
  realizedVolatility: number;   // annualized, decimal
  annualizedVariance: number;
  quadraticVariation: number;   // raw sum of squared log returns
  numObservations: number;
  numReturns: number;
  elapsedMinutes: number;
  elapsedYears: number;
  firstObservation: number;
  lastObservation: number;
}

Vol Response Model

buildVolResponseObservation(current, previous)

Build a single observation for the vol response regression from consecutive IV/RV/spot readings.

import { buildVolResponseObservation } from "@fullstackcraftllc/floe";

const observation = buildVolResponseObservation(
  { iv: 0.22, rv: 0.18, spot: 600.50, timestamp: Date.now() },
  { iv: 0.215, spot: 600.00 }
);

Parameters:

Name Type Description
current { iv: number; rv: number; spot: number; timestamp: number } Current tick values (IV and RV as annualized decimals)
previous { iv: number; spot: number } Previous tick values

Returns: VolResponseObservation

computeVolResponseZScore(observations, config?)

Fit an expanding-window OLS regression on accumulated observations and compute a z-score classifying whether IV is bid or offered relative to the price path.

Regression model: ΔIV(t) ~ α + β₁·return + β₂·|return| + β₃·RV + β₄·IV_level

import { computeVolResponseZScore } from "@fullstackcraftllc/floe";

const result = computeVolResponseZScore(observations, {
  minObservations: 30,
  volBidThreshold: 1.5,
  volOfferedThreshold: -1.5,
});

if (result.isValid) {
  console.log("Z-Score:", result.zScore.toFixed(2));
  console.log("Signal:", result.signal);  // 'vol_bid' | 'vol_offered' | 'neutral'
  console.log("R²:", result.rSquared.toFixed(3));
}

Parameters:

Name Type Description
observations VolResponseObservation[] All accumulated observations for the session
config VolResponseConfig Optional configuration overrides

Returns: VolResponseResult

VolResponseObservation

interface VolResponseObservation {
  timestamp: number;        // milliseconds
  deltaIV: number;          // IV(t) - IV(t-1), as decimal
  spotReturn: number;       // ln(S(t) / S(t-1))
  absSpotReturn: number;    // |spotReturn|
  rvLevel: number;          // current RV, annualized decimal
  ivLevel: number;          // current IV, annualized decimal
}

VolResponseCoefficients

interface VolResponseCoefficients {
  intercept: number;       // regression intercept
  betaReturn: number;      // signed spot return (spot-vol correlation)
  betaAbsReturn: number;   // |return| (vol-of-vol / convexity response)
  betaRV: number;          // RV level (RV mean-reversion effect)
  betaIVLevel: number;     // IV level (IV mean-reversion effect)
}

VolResponseConfig

interface VolResponseConfig {
  minObservations?: number;      // default: 30
  volBidThreshold?: number;      // default: 1.5
  volOfferedThreshold?: number;  // default: -1.5
}

VolResponseResult

interface VolResponseResult {
  isValid: boolean;
  minObservations: number;
  numObservations: number;
  coefficients: VolResponseCoefficients;
  rSquared: number;
  residualStdDev: number;
  expectedDeltaIV: number;
  observedDeltaIV: number;
  residual: number;
  zScore: number;
  signal: 'vol_bid' | 'vol_offered' | 'neutral' | 'insufficient_data';
  timestamp: number;
}

Profit and loss

All functions are synchronous and exported from @fullstackcraftllc/floe. The engine uses IEEE-754 doubles, full-precision European Black–Scholes–Merton pricing and a 365-day year. Round amounts when displaying them.

Entry point Result
calculatePnL(position, market, scenario?) One spot, signed position value, P&L, total entry cost and scenario metadata
calculatePnLCurve(position, market, options?) Financial points, optional roots, expiration bounds and sampled extrema
calculatePnLCurves(items, defaults?) Packed P&L buffer, shared grids and per-position metadata
calculatePnLSurface(position, market, options) Two axis vectors, width, height, P&L buffer and min/max across the grid
preparePnLPosition(position, market) Reusable snapshot with calculatePoint, calculateCurve, calculateSurface, calculateEnvelope and resolveSmile

Positions and market context

Each PnLPosition has one underlying, a nonempty legs array, optional id, symbol and nonnegative fees. Positive quantities are long. Negative quantities are short. Prices use a single currency.

Input Meaning
{ type: 'stock', quantity, entryPrice, id? } Actual signed share count and cost per share
{ type: 'option', optionType, strike, expirationTimestamp, quantity, entryPrice, multiplier?, impliedVolatility?, id? } Call or put, positive strike, signed contracts, premium per unit. Multiplier defaults to 100. IV is an annualized decimal.
{ spot, asOfTimestamp, riskFreeRate, dividendYield?, ivSurfaces? } Nonnegative reference spot, millisecond Unix time, continuously compounded annual decimal rates, optional legacy percentage surfaces
totalEntryCost Sum of signed units times entry price. A positive amount is a debit. A negative amount is a credit. Fees are separate.
positionValue, pnl Signed market value and profit relative to entry. The engine deducts total position fees once. Each leg result is before fees.

scenario.spot and evaluationTimestamp default to the reference state. Each option uses its own remaining time. The earliest expiry is the final supported evaluation timestamp. A front-expiration calendar curve prices the later leg with its remaining time value. An all-stock position has an open-ended horizon. Prices at the original market state can yield a profit or loss against historical entry premiums.

import { calculatePnL, preparePnLPosition } from '@fullstackcraftllc/floe';
import type { PnLPosition } from '@fullstackcraftllc/floe';

const now = Date.now();
const market = { asOfTimestamp: now, spot: 354, riskFreeRate: 0.04 };
const expirationTimestamp = now + 7 * 86400000;
const position: PnLPosition = { symbol: 'AAPL', fees: 1.50, legs: [
  { type: 'stock', quantity: 100, entryPrice: 350 },
  { type: 'option', optionType: 'call', strike: 360, quantity: -1,
    entryPrice: 3, impliedVolatility: 0.25, expirationTimestamp },
] };
const point = calculatePnL(position, market, { spot: 355, includeLegBreakdown: true });
const p = preparePnLPosition(position, market);
const reference = p.calculateCurve({ evaluationTimestamp: expirationTimestamp });
const nextDay = p.calculateCurve({ evaluationTimestamp: now + 86400000, volatilityShift: 0.05 });

Preparation snapshots legs and smiles, indexes strikes and expirations, and caches invariant payoff and volatility data. An expiry-only position can omit IV. A positive-time leg needs a leg IV, matching-side surface, or resolver. The callback receives a frozen leg copy. Callback closures remain under caller control.

Curves, roots and bounds

priceRange: { min, max, points } specifies a uniform base grid. The default uses 500 points spanning the reference spot and every strike, widened on each side by a factor of exp(±2σ√T), where σ is the largest baseline IV among the option legs and T the years to the earliest expiration. The widening is clamped to between 5% and 75% in log terms. Without any known IV the default runs from 80% of the lower of spot and strikes to 120% of the upper (with a one-unit minimum upper reference). Alternatively pass a nonempty strictly increasing spots array. Ordinary curves insert reference spot, strikes, isolated roots and finite zero-interval boundaries inside the domain. priceRange.points in the result is the actual count. Compact batches keep the input grid and list significant coordinates separately.

breakEvens.prices contains isolated prices. ranges contains closed zero-P&L intervals. A null upper endpoint means the interval extends indefinitely. At a shared expiration the engine evaluates the payoff at spot zero and at every strike, then reads crossings from the signs at consecutive knots and from the slope of the last ray. This finds global roots and intervals even outside the plotted range. Knot values within 1024 × Number.EPSILON times the summed magnitude of their terms count as exactly zero, so decimal premiums such as 0.1 + 0.2 cannot turn a flat zero-P&L ray into a 3e-13 profit and hide its break-even.

Theoretical roots use a separate search grid containing the strikes and reference spot. Bisection refines sign changes. Local-extremum refinement searches for tangencies and pairs of crossings. Set rootSearch: { min, max, samples, spotTolerance, pnlTolerance } to control the search. Defaults use the plotted domain, 129 samples, a spot tolerance of 1e-8 and a monetary residual tolerance of 1e-7. The result reports the domain, method, global completeness, and whether detected brackets converged. complete: false applies to every numerical search. Narrow features, discontinuities, flat regions and roots outside the search can escape discovery. Numerical zero intervals are not certified.

expirationStatistics contains maxProfit, maxLoss, and the corresponding price regions. Bounds have kind finite (nonnegative amount), unlimited, or unavailable. Mixed-expiry lifetime bounds are unavailable. sampledStatistics gives the minimum and maximum P&L actually calculated on the selected grid and their spots.

Volatility scenarios

All P&L volatility values and shifts are decimals. 0.05 adds five percentage points. Legacy IVSurface values from getIVSurfaces() are percentages and are converted once. Supply distinct sorted strikes per expiration and option side. Smoothed values take precedence over raw values. Strike interpolation is linear with flat wings. Between observed expirations the engine interpolates total variance (IV squared times years). Beyond the tenor endpoints it holds the nearest smile's IV constant.

volatilityModel.kind Assumption
constant (default) Keep the leg's entry-independent base IV, or interpolate the reference surface if the leg has no IV.
stickyStrike Read the reference smile at the absolute contract strike and original tenor.
stickyMoneyness Read the original tenor at strike × reference spot / scenario spot. At zero spot use the upper wing.
coupled Add directional and absolute log-return stresses to the constant baseline.
dynamic Move the smile with spot moneyness, roll its tenor down to remaining time, and apply the configured stresses. Without a surface the leg IV supplies the base level.

For coupled and dynamic models, let u = log(max(scenarioSpot / referenceSpot, 1e-8)) and m = log(strike / referenceSpot) - u. The finite floor defines the zero-spot stress convention. Relative models require a positive reference spot. The additive adjustment is betaReturn*u + betaAbsReturn*abs(u) + skew*m + curvature*m*m + annualDrift*elapsedYears. Coefficients default to zero. A parallel shift applies last. Finite negative final values floor at zero, with no arbitrary upper IV cap. Nonfinite resolved values throw.

computeVolResponseZScore().coefficients has matching return-coefficient names. Use coefficients from an observation interval appropriate for the scenario, or state your own horizon-scaling assumption. FLOE applies no automatic statistical scaling. Regime correlation and vol-of-vol from deriveRegimeParams() can inform stress selection. Rolling an observed term structure forward is an assumed scenario. Transformed smiles have no forecasting or static-arbitrage guarantee.

A custom resolver replaces the built-in model, then the parallel shift and floor apply. It can supply the entire IV when baseIV is undefined. Time fields timeToExpiry and elapsedTime are years. The two timestamp fields are Unix milliseconds.

const custom = p.calculatePoint({
  volatilityResolver: ({ baseIV, referenceSpot, scenarioSpot }) =>
    (baseIV ?? 0.25) + (scenarioSpot < referenceSpot ? 0.04 : 0),
  volatilityShift: 0.01,
});
const smile = p.resolveSmile(1, [340, 350, 360, 370], {
  spot: 345, volatilityModel: { kind: 'dynamic', betaReturn: -0.25, curvature: 0.2 },
});
const stress = p.calculateEnvelope({ priceRange: { min: 310, max: 400, points: 100 } },
  [-0.08, 0, 0.08].map(volatilityShift => ({ volatilityShift })));

resolveSmile substitutes each requested strike into the selected option leg. It returns decimal IVs and requires positive remaining time. Envelopes evaluate every supplied stress at every requested price and return the lowest and highest P&L. These deterministic ranges carry no probability level.

Output detail and Greeks

Curves and batch rows include roots and statistics by default. Disable them with includeBreakEvens: false and includeStatistics: false. Use includeExpirationCurve for concurrent reference-horizon P&L, includeLegBreakdown for price, signed value, leg-level P&L, IV and remaining years, or includeGreeks for aggregate delta, gamma, theta, vega and rho. Enabling point detail in a batch adds ordinary point objects alongside the compact P&L buffer.

Delta is monetary change per unit of spot, gamma per squared unit, theta per calendar day, vega per one percentage point of IV, and rho per one percentage point of rates. Signed units include contract multipliers. FLOE uses its conventional fixed-IV Greeks with their existing per-unit rounding at regular points. At deterministic payoff kinks it takes the midpoint delta, with zero gamma and vega as reporting conventions. At expiry theta and rho are zero.

greeks hold each leg's scenario IV fixed. With includeGreeks, each point also carries scenarioSensitivities: { delta, gamma, bump }: central differences of the full scenario P&L in spot, so they include any IV change that the volatility model or resolver applies as spot moves. The bump is 1e-4 × max(spot, 1) in spot units, one-sided at zero spot. Without spot-dependent IV the two deltas agree up to rounding. Under a coupled or dynamic model they differ by roughly vega times the model's dIV/dspot. At an expiring strike the finite-difference gamma reports the kink's slope change divided by the bump.

Batch curves and workers

import { calculatePnLCurves } from '@fullstackcraftllc/floe';
const batch = calculatePnLCurves([{ prepared: p }, { position, market }], {
  evaluationTimestamp: expirationTimestamp,
  priceRange: { min: 300, max: 400, points: 40 },
  includeBreakEvens: true, includeStatistics: false,
});
const row = batch.rows[1];
const prices = batch.grids[row.gridIndex];
const profit = batch.pnl.subarray(row.offset, row.offset + row.length);
// When every row has the same length, index rows directly:
const n = batch.pointsPerCurve!;
const third = batch.pnl.subarray(2 * n, 3 * n);

calculatePnLCurves(items, defaults?) returns { grids, pnl, rows, positionIds, pointsPerCurve }. Each item is { position, market } or { prepared }, with optional options that override the batch defaults, including its own grid. Rows preserve input order and carry their index, position ID, symbol, offset, length, gridIndex and the curve metadata. positionIds[i] mirrors row i. pointsPerCurve is the shared row length, or null when lengths differ. Subarrays are zero-copy views. Rows with identical coordinates share one grid array, whether the coordinates came from equal price ranges or equal spots. Compact rows keep their base grid, so exact roots and strikes are listed in significantSpots instead of being inserted. A 100 × 50 table uses 40 KB for the P&L values, 100 × 500 uses 400 KB, and 1,000 × 500 uses 4 MB, plus coordinates and metadata.

By default a failure rejects the whole call with a RangeError naming the first failing row in input order, for example Batch row 7: Evaluation after earliest expiration. Pass onError: 'collect' to keep going. A failed row then has an error message instead of curve metadata, and its span of pnl holds NaN. When its own options define no grid and its position could not be prepared, the span is empty and gridIndex is -1. Screener tables that evaluate every row at one horizon need this mode, because a contract expiring before the horizon cannot be valued there.

const page = calculatePnLCurves(rows, { onError: 'collect', evaluationTimestamp: nextWeek, priceRange });
for (const row of page.rows) {
  // Compare with undefined: that check narrows the row type, a truthiness check does not.
  if (row.error !== undefined) showPlaceholder(row.index, row.error);
  else drawSparkline(page.grids[row.gridIndex], page.pnl.subarray(row.offset, row.offset + row.length), row.breakEvens);
}

Inside a Web Worker, receive plain positions and built-in scenario configurations and prepare positions there. Choose deterministic callback implementations inside the worker. Functions and prepared evaluators cannot be structured-cloned. Transfer buffer ownership back to the caller as follows. The sender's transferred buffers become detached. Every typed array FLOE returns is typed as PnLFloat64Array, which is Float64Array<ArrayBuffer> on TypeScript 5.7 and later, so the transfer list type-checks without casts.

self.postMessage(batch, { transfer: [batch.pnl.buffer, ...batch.grids.map(g => g.buffer)] });

Use one worker, or a small pool sized to the hardware, for a whole results page. Spawning a worker per contract costs more in startup and messaging than the curves themselves.

Two-dimensional surfaces

const surface = p.calculateSurface({
  x: { dimension: 'spot', values: [335, 345, 355, 365] },
  y: { dimension: 'time', values: [now, now + 86400000, expirationTimestamp] },
  volatilityShift: 0.02,
});
const rowOneColumnTwo = surface.pnl[1 * surface.width + 2];

Each axis is a distinct dimension with finite, strictly increasing coordinates. Use spot in currency per share, time as absolute Unix milliseconds, and volatility shift in additive decimal units. Set the third dimension in the scenario. An unspecified fixed spot defaults to the market spot. Both axis vectors and the row-major values are transferable Float64Arrays. Surface metadata uses the first axis coordinates for time and shift when those vary. A 200 × 100 grid uses 160 KB of P&L values. Generate surfaces only when needed.

Performance and model scope

Start screener rows with 30–50 expiration points and prepare positions once for interactive sliders. Request detailed theoretical curves on demand and generate surfaces only when a view needs them. A worker or small pool can serve large pages. Use request IDs to discard stale results during rapid changes.

Run npm run benchmark:pnl for reproducible Node CPU, heap and ArrayBuffer measurements. It reports the median, p95 and maximum of 25 runs after five warm-ups, plus evaluation counts and output sizes. Medians measured on an Apple M3 Max with Node 23 (hardware-dependent, never a pass/fail criterion):

Workload Median
100 expiration curves × 50 points 0.54 ms
100 expiration curves × 500 points 1.6 ms
1 theoretical curve × 501 points, with roots and statistics 0.25 ms
100 theoretical curves × 500 points, one leg / four legs 4.3 ms / 11.7 ms
100 four-leg curves × 500 points, coupled IV 17 ms
1 spot/time surface, 200 × 100 2.0 ms
100 spot/time surfaces, 200 × 100 132 ms
100,000 prices: blackScholes / calculateGreeks 4.9 ms / 7.9 ms

For the target browser, open the Batch P&L — 100 Positions playground example. It warms up, times 15 runs with performance.now() and prints the median and slowest run. Repeat on representative hardware and time rendering separately from evaluation.

European pricing approximates American-style equity options. Scenarios omit early exercise, assignment, discrete dividend payments, slippage, liquidity, tax, margin, collateral and interest on collateral. They stop at the earliest expiration because valuation beyond settlement can depend on exercise decisions and the price path. Continuous dividend yield enters the theoretical price only.