Calculate gamma, vanna, and charm exposures using smoothed IV surfaces
import { getIVSurfaces, calculateGammaVannaCharmExposures, OptionChain, NormalizedOption, } from "@fullstackcraftllc/floe"; // Helper to get a future expiration date (30 days out) const futureDate = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000); const expirationTimestamp = futureDate.getTime(); const expiration = futureDate.toISOString().split("T")[0]; // "YYYY-MM-DD" // Sample option data (normally from your broker API) const sampleOptions: NormalizedOption[] = [ { strike: 445, expiration, expirationTimestamp, optionType: "call", bid: 8.50, ask: 8.70, mark: 8.60, last: 8.55, volume: 1500, openInterest: 25000, impliedVolatility: 0.18, underlying: "SPY", occSymbol: "", bidSize: 100, askSize: 100, timestamp: Date.now(), }, { strike: 445, expiration, expirationTimestamp, optionType: "put", bid: 3.20, ask: 3.40, mark: 3.30, last: 3.25, volume: 2000, openInterest: 30000, impliedVolatility: 0.19, underlying: "SPY", occSymbol: "", bidSize: 100, askSize: 100, timestamp: Date.now(), }, { strike: 450, expiration, expirationTimestamp, optionType: "call", bid: 5.80, ask: 6.00, mark: 5.90, last: 5.85, volume: 3000, openInterest: 45000, impliedVolatility: 0.17, underlying: "SPY", occSymbol: "", bidSize: 100, askSize: 100, timestamp: Date.now(), }, { strike: 450, expiration, expirationTimestamp, optionType: "put", bid: 5.50, ask: 5.70, mark: 5.60, last: 5.55, volume: 2500, openInterest: 35000, impliedVolatility: 0.18, underlying: "SPY", occSymbol: "", bidSize: 100, askSize: 100, timestamp: Date.now(), }, { strike: 455, expiration, expirationTimestamp, optionType: "call", bid: 3.40, ask: 3.60, mark: 3.50, last: 3.45, volume: 2800, openInterest: 38000, impliedVolatility: 0.16, underlying: "SPY", occSymbol: "", bidSize: 100, askSize: 100, timestamp: Date.now(), }, { strike: 455, expiration, expirationTimestamp, optionType: "put", bid: 8.10, ask: 8.30, mark: 8.20, last: 8.15, volume: 1800, openInterest: 28000, impliedVolatility: 0.17, underlying: "SPY", occSymbol: "", bidSize: 100, askSize: 100, timestamp: Date.now(), }, ]; // Bundle into the OptionChain type const chain: OptionChain = { symbol: "SPY", spot: 448.50, riskFreeRate: 0.05, dividendYield: 0.015, options: sampleOptions, }; // Build IV surfaces const ivSurfaces = getIVSurfaces("blackscholes", "totalvariance", chain); console.log("IV Surfaces built for", ivSurfaces.length, "option types"); // Calculate exposures const exposures = calculateGammaVannaCharmExposures(chain, ivSurfaces); for (const exp of exposures) { console.log("\nExpiration:", new Date(exp.expiration).toDateString()); console.log(" Gamma Exposure:", exp.totalGammaExposure.toLocaleString()); console.log(" Vanna Exposure:", exp.totalVannaExposure.toLocaleString()); console.log(" Charm Exposure:", exp.totalCharmExposure.toLocaleString()); console.log(" Net Exposure:", exp.totalNetExposure.toLocaleString()); console.log(" Max Gamma Strike: $" + exp.strikeOfMaxGamma); }
Tips
- • Edit the code and see results instantly in the console below
- • All floe functions are available via the
@fullstackcraftllc/floeimport - • Check the documentation for full API reference
- • Results appear in the console panel at the bottom of the editor