Calculate gamma, vanna, and charm exposures using smoothed IV surfaces
import { getIVSurfaces, calculateGammaVannaCharmExposures, OptionChain, NormalizedOption, } from "@fullstackcraftllc/floe"; // Sample option data (normally from your broker API) const sampleOptions: NormalizedOption[] = [ { strike: 445, expiration: "2024-01-19", expirationTimestamp: Date.now() + 30 * 24 * 60 * 60 * 1000, optionType: "call", bid: 8.50, ask: 8.70, mark: 8.60, last: 8.55, volume: 1500, openInterest: 25000, impliedVolatility: 0.18, }, { strike: 445, expiration: "2024-01-19", expirationTimestamp: Date.now() + 30 * 24 * 60 * 60 * 1000, optionType: "put", bid: 3.20, ask: 3.40, mark: 3.30, last: 3.25, volume: 2000, openInterest: 30000, impliedVolatility: 0.19, }, { strike: 450, expiration: "2024-01-19", expirationTimestamp: Date.now() + 30 * 24 * 60 * 60 * 1000, optionType: "call", bid: 5.80, ask: 6.00, mark: 5.90, last: 5.85, volume: 3000, openInterest: 45000, impliedVolatility: 0.17, }, { strike: 450, expiration: "2024-01-19", expirationTimestamp: Date.now() + 30 * 24 * 60 * 60 * 1000, optionType: "put", bid: 5.50, ask: 5.70, mark: 5.60, last: 5.55, volume: 2500, openInterest: 35000, impliedVolatility: 0.18, }, ]; // Bundle into an OptionChain 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:", ivSurfaces); // 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()); }
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