Skip to content

An option's gamma, live

A European option's gamma, its delta's change with the stock's price, d²V/dS² = φ(d₁) / (S σ √T), a call's and a put's alike, per euro (lusine.finance.option_gamma). Below, an option struck at 50 EUR, at 5% and a volatility of 20%, is swept on your GPU as you read across spots from 10 EUR to 150 EUR, a euro a step, with a year left and with a tenth of a year; and thirty-two options are held to Black-Scholes in float64.

This page runs the program on your GPU through WebGPU, so it needs a browser with WebGPU (a recent Chrome, Edge, Safari or Firefox). Without it the program does not run and nothing is drawn below.

What it shows

  • The strip above the controls is green while every check holds, and turns red for good once one fails.
  • The sweep: the chart draws gamma, in thousandths per euro, against the spot, a point a step, with a year left and with a tenth of a year: a hump below the strike, the shorter life's taller and narrower. Below it, the spot, the year's gamma, the spot of its highest so far, and where Black and Scholes put the peak.
  • The checks: Hull's example, chapter 19's running example (a stock at 49, a strike of 50, 5%, 20%, twenty weeks) a gamma of 0.066 per euro, to half a unit in the last digit printed (Hull, Options, Futures, and Other Derivatives, 9th ed.); Black-Scholes in float64, the thirty-two options' gammas each within 10⁻⁵ per spot of φ(d₁) / (S σ √T) in float64, and within 10⁻⁵ of it relative where gamma S is above 10⁻³, at the parameters as binary32 holds them; where it peaks, gamma positive at every spot, and the year's highest within a step of S = K e^(−(r + 3σ²/2) T), where d₁ = −σ √T; the life, at the strike a tenth of a year's gamma above a year's, and at 20 EUR below it. Each is held at every step.

Every number here is computed by the program on the GPU; the page only reads the values back and draws them. The sweep's option, its two lives and its spots, and Hull's examples are the program's settings, which the host may write; this page offers no control to change them yet.

The program

The options, the sweep and the checks, the panels the page draws, and the one procedure, main, run each step: the spot a euro on, the two gammas at it and the highest so far, the thirty-two options, and the checks.

// The option gamma's live page: a year's gamma and a tenth of a year's swept across the spot, the year's peak found
// where Black and Scholes put it; thirty-two options held to Black-Scholes in float64; and Hull's example, with the
// page's checks computed here on the GPU and shown by the panels the program declares.

namespace option_gamma;

lusine.version version = { { number = 1 } };

// The reader's settings: the seed the options are drawn from; the sweep's option, its strike, rate, volatility over a
// year and life; and the spot the sweep starts at and its step.
host struct {
  integer seed = 391; float<EUR> strike = 50.0 EUR; float<year^-1> rate = 0.05 year^-1; float volatility = 0.2;
  float<year> years = 1.0 year; float<year> period = 1.0 year; float<EUR> first = 10.0 EUR;
  float<EUR> stride = 1.0 EUR;
} settings;

// Hull's examples: Example 15.6, a stock at 42 EUR, a strike of 40 EUR, 10% a year, a volatility of 20% a year and six
// months left; and chapter 19's running example, 49 EUR, 50 EUR, 5%, 20% and twenty weeks.
host struct {
  float<EUR> spot = 42.0 EUR; float<EUR> strike = 40.0 EUR; float<year^-1> rate = 0.1 year^-1; float volatility = 0.2;
  float<year> years = 0.5 year;
} example;
host struct {
  float<EUR> spot = 49.0 EUR; float<EUR> strike = 50.0 EUR; float<year^-1> rate = 0.05 year^-1; float volatility = 0.2;
  float<year> years = 0.38461538461538464 year;
} running;

// The sweep's shorter life, a tenth of a year, and the spots its gamma is compared at: the strike, and 20 EUR.
host struct { float<year> years = 0.1 year; float<EUR> far = 20.0 EUR; } short;

// Thirty-two options, each with its gamma, phi(d1) / (S sigma sqrt(T)), by Black-Scholes in float64 with scipy's exact
// normal distribution, at the parameters as binary32 holds them; the kernel's gamma, and whether it is within 1e-5 of
// it per spot, and within 1e-5 of it relative where gamma S is above 1e-3.
struct option {
  bool call; float<EUR> spot; float<EUR> strike; float<year^-1> rate; float volatility; float<year> years;
  float<EUR^-1> reference; float<EUR^-1> gamma; bool holds;
};
host table<option> options(capacity = 32) = {
  { call = true, spot = 20.886307268226673 EUR, strike = 58.665533887237984 EUR,
    rate = 0.013447202845124347 year^-1, volatility = 0.15902594726357758, years = 4.38507015721194 year,
    reference = 0.001279942820277855 EUR^-1 },
  { call = false, spot = 188.59482662705486 EUR, strike = 135.69979791601557 EUR,
    rate = 0.05057192816027696 year^-1, volatility = 0.3115418699091693, years = 4.222032830755394 year,
    reference = 0.001670949731561072 EUR^-1 },
  { call = true, spot = 118.91243378167061 EUR, strike = 185.2483042029888 EUR,
    rate = 0.09011600873524846 year^-1, volatility = 0.31585264386633055, years = 3.721298802897474 year,
    reference = 0.005461640569918566 EUR^-1 },
  { call = true, spot = 163.8803382421281 EUR, strike = 27.370130355000377 EUR,
    rate = 0.08699557563034188 year^-1, volatility = 0.3805289170746753, years = 2.9718848042202395 year,
    reference = 9.648100012714949e-06 EUR^-1 },
  { call = false, spot = 156.01246541016698 EUR, strike = 98.66825482181102 EUR,
    rate = 0.14785047611735416 year^-1, volatility = 0.7774526364639268, years = 2.9756117175286025 year,
    reference = 0.0007766774217967641 EUR^-1 },
  { call = true, spot = 120.21559443564263 EUR, strike = 39.4609317943744 EUR,
    rate = 0.031629090453178174 year^-1, volatility = 0.41657887517742265, years = 2.621120091497525 year,
    reference = 0.0005291105891869825 EUR^-1 },
  { call = true, spot = 125.27283792580695 EUR, strike = 113.42753373611995 EUR,
    rate = 0.13960486210071893 year^-1, volatility = 0.32822630365082595, years = 0.663718099301309 year,
    reference = 0.00828666542951872 EUR^-1 },
  { call = true, spot = 111.5146720923226 EUR, strike = 91.70554427769596 EUR,
    rate = 0.09035406599957747 year^-1, volatility = 0.6424737027251702, years = 0.9491809736885719 year,
    reference = 0.004273856530801543 EUR^-1 },
  { call = true, spot = 104.7904253041208 EUR, strike = 54.552235260291766 EUR,
    rate = 0.035530099141647786 year^-1, volatility = 0.5662054014919639, years = 4.101686172995604 year,
    reference = 0.0014826789088365165 EUR^-1 },
  { call = true, spot = 131.9704638511787 EUR, strike = 199.51590533067628 EUR,
    rate = 0.12150206984240143 year^-1, volatility = 0.07353334528136175, years = 1.013456937268504 year,
    reference = 2.1732227404879156e-05 EUR^-1 },
  { call = true, spot = 189.31412648919076 EUR, strike = 101.79493838011325 EUR,
    rate = 0.1486055774391051 year^-1, volatility = 0.17001756302296653, years = 3.6964262270876262 year,
    reference = 5.870741932204867e-06 EUR^-1 },
  { call = false, spot = 184.9460138697643 EUR, strike = 154.73367705909305 EUR,
    rate = 0.06516181953678835 year^-1, volatility = 0.8088997581932528, years = 4.43441302148932 year,
    reference = 0.0006717672486069121 EUR^-1 },
  { call = true, spot = 184.149544077138 EUR, strike = 138.86885284372516 EUR,
    rate = 0.08453121905364037 year^-1, volatility = 0.8815777025835502, years = 4.812131996853199 year,
    reference = 0.00046677469784899315 EUR^-1 },
  { call = false, spot = 179.92226669131634 EUR, strike = 66.09962335996232 EUR,
    rate = 0.09058104655070943 year^-1, volatility = 0.4365392531203102, years = 0.6805432126265991 year,
    reference = 4.5655602496276234e-05 EUR^-1 },
  { call = true, spot = 58.98985403872521 EUR, strike = 69.53690348359211 EUR,
    rate = 0.09882627092796568 year^-1, volatility = 0.8984296966945114, years = 4.194961386027854 year,
    reference = 0.0021045087478601295 EUR^-1 },
  { call = false, spot = 70.83381725423173 EUR, strike = 196.1692404299365 EUR,
    rate = 0.048636007021675504 year^-1, volatility = 0.619002303682292, years = 0.44163010411418885 year,
    reference = 0.0011690043718923556 EUR^-1 },
  { call = true, spot = 182.0562557898536 EUR, strike = 173.70967347304358 EUR,
    rate = 0.04764858389327849 year^-1, volatility = 0.6800378619360005, years = 4.203906336381006 year,
    reference = 0.0010722360390222766 EUR^-1 },
  { call = false, spot = 66.23051665247758 EUR, strike = 170.51126513679412 EUR,
    rate = 0.0634771790745104 year^-1, volatility = 0.7740285718864518, years = 2.4297303435717232 year,
    reference = 0.004985548438748237 EUR^-1 },
  { call = true, spot = 61.040122087469854 EUR, strike = 25.81738810852937 EUR,
    rate = -0.01776675074159802 year^-1, volatility = 0.6865046104255538, years = 4.1593741745940465 year,
    reference = 0.002105611113125875 EUR^-1 },
  { call = true, spot = 183.22855401336517 EUR, strike = 180.44889574953785 EUR,
    rate = 0.022967575251798763 year^-1, volatility = 0.44718485541057645, years = 4.795045054343254 year,
    reference = 0.0018373103691331674 EUR^-1 },
  { call = false, spot = 55.846083764705995 EUR, strike = 53.78166280056927 EUR,
    rate = 0.12564516571602508 year^-1, volatility = 0.47603203171217895, years = 0.9746002449187416 year,
    reference = 0.012879534965383722 EUR^-1 },
  { call = false, spot = 49.43203182526905 EUR, strike = 181.98461219516167 EUR,
    rate = 0.12752664626939325 year^-1, volatility = 0.10648053312598907, years = 0.6180760422632282 year,
    reference = 6.142424028702072e-48 EUR^-1 },
  { call = true, spot = 155.62101568917203 EUR, strike = 162.04319920333035 EUR,
    rate = 0.10691574785743298 year^-1, volatility = 0.60801310807133, years = 2.030221913104255 year,
    reference = 0.002415650595299135 EUR^-1 },
  { call = false, spot = 143.56758434849291 EUR, strike = 148.75367003537065 EUR,
    rate = 0.12858898784657127 year^-1, volatility = 0.7002982559148344, years = 4.144197661866689 year,
    reference = 0.0011093580915492143 EUR^-1 },
  { call = false, spot = 197.30127196208014 EUR, strike = 87.76729450260797 EUR,
    rate = 0.13782776344187664 year^-1, volatility = 0.284284922323631, years = 4.1099414619067645 year,
    reference = 9.760391245039906e-05 EUR^-1 },
  { call = true, spot = 176.93386638351492 EUR, strike = 24.762009772194894 EUR,
    rate = 0.002562164252424219 year^-1, volatility = 0.5123741136193225, years = 0.8223266264332635 year,
    reference = 2.2327035498250282e-07 EUR^-1 },
  { call = true, spot = 22.383447260917606 EUR, strike = 87.65377119357558 EUR,
    rate = 0.12941660432027086 year^-1, volatility = 0.8920939592482549, years = 4.887267819355272 year,
    reference = 0.007481853102132635 EUR^-1 },
  { call = false, spot = 198.92285038640267 EUR, strike = 28.77192047369769 EUR,
    rate = 0.07350521936785097 year^-1, volatility = 0.259816172475044, years = 4.990816046864923 year,
    reference = 4.073363062214668e-07 EUR^-1 },
  { call = true, spot = 29.333652993672846 EUR, strike = 155.9661717776625 EUR,
    rate = 0.13608761873657335 year^-1, volatility = 0.7921456835739259, years = 0.5821716906310608 year,
    reference = 0.0014862288509238405 EUR^-1 },
  { call = true, spot = 96.2014567940601 EUR, strike = 187.00927996286674 EUR,
    rate = 0.028803522459524823 year^-1, volatility = 0.3952282877503409, years = 4.334615968395207 year,
    reference = 0.004891109766812094 EUR^-1 },
  { call = false, spot = 84.30148792212937 EUR, strike = 34.445458985634986 EUR,
    rate = 0.07128430993582072 year^-1, volatility = 0.24547475493628396, years = 4.191866317697686 year,
    reference = 0.00029899782361227247 EUR^-1 },
  { call = true, spot = 159.96599103543278 EUR, strike = 135.11847347833998 EUR,
    rate = 0.09059069229451537 year^-1, volatility = 0.11230768482870263, years = 0.8190242915046948 year,
    reference = 0.001245131944831025 EUR^-1 },
};

// The sweep: the step, from 0 to 140 and round again; the spot, from 10 EUR to 150 EUR; gamma with a year left and with
// a tenth, and each in thousandths per euro for the chart; the year's largest gamma so far and the spot it was at; and
// where Black and Scholes put the peak, d1 = -sigma sqrt(T), at S = K e^(-(r + 3 sigma^2 / 2) T).
struct {
  integer step = -1; float<EUR> spot; float<EUR^-1> year; float<EUR^-1> tenth; float year_shown; float tenth_shown;
  float<EUR^-1> highest; float<EUR> highest_at; float<EUR> peak;
} sweep;

// The checks: Hull's chapter 19 example's gamma 0.066 per euro to half a unit in the last digit printed; the thirty-two
// options each within 1e-5 per spot of the float64 gamma, and within 1e-5 of it relative where gamma S is above 1e-3;
// gamma positive, and highest within a step of the spot where Black and Scholes put the peak; and at the strike a tenth
// of a year's gamma above a year's, and at 20 EUR below it.
struct { bool hull = true; bool reference = true; bool peak = true; bool life = true; } checks;

// A strip of lamps the page draws, lit green while every check holds and red once one fails.
struct lamp { vector<float, 4> colour; };
lattice<lamp, 2> lamps(spacing = 1 m, boundary = wall);

vector<float, 4> lamp_colour(bool holds)
{
  return holds ? vector<float, 4>(0.15, 0.6, 0.3, 1.0) : vector<float, 4>(0.75, 0.15, 0.15, 1.0);
}

float eps() { return 1.0 / 8388608.0; }

integer failing(table<bool> holds) { return count(holds) where !holds; }

bool near(float<EUR^-1> gamma, float<EUR^-1> reference, float<EUR> spot)
{
  return abs(gamma - reference) * spot <= 0.00001
      && (reference * spot <= 0.001 || abs(gamma / reference - 1.0) <= 0.00001);
}

bool life(float<EUR> strike, float<EUR> far, float<year^-1> rate, float volatility, float<year> period,
          float<year> years, float<year> short)
{
  let at_year = lusine.finance.option_gamma(spot = strike, strike, rate, volatility, period, years);
  let at_tenth = lusine.finance.option_gamma(spot = strike, strike, rate, volatility, period, years = short);
  let far_year = lusine.finance.option_gamma(spot = far, strike, rate, volatility, period, years);
  let far_tenth = lusine.finance.option_gamma(spot = far, strike, rate, volatility, period, years = short);
  return at_tenth > at_year && far_tenth < far_year;
}

output table<lusine.widget> panels = {
  lusine.series { { panel = "the sweep", chart = "gamma, thousandths per euro", quantity = sweep.year_shown,
                    steps = 141, against = sweep.spot, label = "a year left" } },
  lusine.series { { panel = "the sweep", chart = "gamma, thousandths per euro", quantity = sweep.tenth_shown,
                    steps = 141, against = sweep.spot, label = "a tenth of a year" } },
  lusine.value { { panel = "the sweep", quantity = sweep.spot, label = "spot" } },
  lusine.value { { panel = "the sweep", quantity = sweep.year, label = "a year left" } },
  lusine.value { { panel = "the sweep", quantity = sweep.highest_at, label = "highest so far at" } },
  lusine.value { { panel = "the sweep", quantity = sweep.peak, label = "the peak" } },
  lusine.value { { panel = "the checks", quantity = checks.hull, label = "Hull's example" } },
  lusine.value { { panel = "the checks", quantity = checks.reference, label = "Black-Scholes in float64" } },
  lusine.value { { panel = "the checks", quantity = checks.peak, label = "where it peaks" } },
  lusine.value { { panel = "the checks", quantity = checks.life, label = "the life" } },
};

void main()
{
  sweep.step = sweep.step >= 140 ? 0 : sweep.step + 1;
  sweep.spot = settings.first + float(sweep.step) * settings.stride;
  sweep.year = lusine.finance.option_gamma(sweep.spot, settings.strike, settings.rate, settings.volatility,
                                           settings.period, settings.years);
  sweep.tenth = lusine.finance.option_gamma(sweep.spot, settings.strike, settings.rate, settings.volatility,
                                            settings.period, years = short.years);
  sweep.year_shown = sweep.year * 1000.0 EUR;
  sweep.tenth_shown = sweep.tenth * 1000.0 EUR;
  sweep.highest_at = sweep.step == 0 || sweep.year > sweep.highest ? sweep.spot : sweep.highest_at;
  sweep.highest = sweep.step == 0 || sweep.year > sweep.highest ? sweep.year : sweep.highest;
  sweep.peak = settings.strike
               * exp(-(settings.rate + 1.5 * settings.volatility * settings.volatility / settings.period)
                     * settings.years);
  options.gamma = lusine.finance.option_gamma(options.spot, options.strike, options.rate, options.volatility,
                                              settings.period, options.years);
  options.holds = near(options.gamma, options.reference, options.spot);
  checks.hull = checks.hull && abs(lusine.finance.option_gamma(running.spot, running.strike, running.rate,
                                                              running.volatility, settings.period, running.years)
                                   - 0.066 EUR^-1) <= 0.0005 EUR^-1;
  checks.reference = checks.reference && failing(holds = options.holds) == 0;
  checks.peak = checks.peak && sweep.year > 0.0 EUR^-1
                && (sweep.step < 140 || abs(sweep.highest_at - sweep.peak) <= settings.stride);
  checks.life = checks.life && life(settings.strike, short.far, settings.rate, settings.volatility, settings.period,
                                    settings.years, short = short.years);
  lamps.colour = lamp_colour(holds = checks.hull && checks.reference && checks.peak && checks.life);
}

The kernel's other proof (a thousand options against Black-Scholes in float64) is on its proof page.