Speed

A Price from Given Paths

The price of a path-dependent option that pays at expiry is the discounted average of its payoffs over all paths, the knocked-out ones counting as zero; the demo splits a list of four given paths, takes the up-and-out payoff on each and counts the knocked-out ones.

The question

The last lessons priced path-dependent options by simulation without opening the box. What is inside? Suppose someone hands you a list of price paths and an option whose payoff depends on the path. How do you get a price from them, and what goes into the price?

This lesson works on four given paths, typed in as numbers. It does not draw them from the model, so no randomness is involved. The numbers are assumptions of the lesson.

Work it by hand

Take four paths of six prices each, an up-and-out call with the strike 100 and the barrier 120. The payoff on a path is the plain payoff, the last price minus the strike if positive, unless the path touched 120, and then it is zero. The four payoffs are 0, 6, 18 and 4: the first path touched 122.

The price is the mean of the payoffs, discounted from expiry to today. The mean is (0 + 6 + 18 + 4) / 4 = 7: the knocked-out path counts as a zero in the average.

The discounting is one more step: the mean is multiplied by the discount factor for the time of the payoff.

Run it

Lines 1 to 5 define part, which cuts path number k of n points out of the list. Lines 6 and 7 build the up-and-out call and count the paths. The loop of lines 10 to 16 takes each path, keeps its payoff (line 12) and flags it as knocked out if a point is at or above the barrier (lines 13 to 15). Lines 17 to 22 return the four paths for the picture and the payoffs; line 23 returns the number of knocked-out paths, 1.

Four lines over six points, all starting at 100. Path 1 rises to 122 at the fourth point and ends at 109; path 2 dips to 92 and ends at 106; path 3 rises to 118 at the end; path 4 dips to 95 and ends at 104. The program returns 1, the number of paths that touched 120; the payoffs of the four paths are 0, 6, 18 and 4.
fn part(all: FloatList, k: int, n: int) -> FloatList {
  let one = float_list();
  for (i in range(0, n)) { one.add(all.at(k * n + i)); }
  return one;
}
let option = instrument.barrier_call(strike, 1.0, barrier, "up-out");
let count = int(floor(float(paths.len()) / float(points)));
let pay = float_list(); let step = float_list(); let knocked = 0;
for (i in range(0, points)) { step.add(float(i)); }
for (k in range(0, count)) {
  let one = part(paths, k, points);
  pay.add(lmf.round(option.path_payoff(one), 2));
  let hit = 0;
  for (i in range(0, points)) { if (one.at(i) >= barrier) { hit = 1; } }
  knocked = knocked + hit;
}
lmcode_return_put("step", step);
lmcode_return_put("path1", part(paths, 0, points));
lmcode_return_put("path2", part(paths, 1, points));
lmcode_return_put("path3", part(paths, 2, points));
lmcode_return_put("path4", part(paths, 3, points));
lmcode_return_put("payoff", pay);
let answer = knocked;
{
  "answer": 1,
  "step": [
    0,
    1,
    2,
    3,
    4,
    5
  ],
  "path1": [
    100,
    104,
    111,
    122,
    117,
    109
  ],
  "path2": [
    100,
    97,
    92,
    99,
    103,
    106
  ],
  "path3": [
    100,
    108,
    113,
    110,
    116,
    118
  ],
  "path4": [
    100,
    95,
    101,
    107,
    112,
    104
  ],
  "payoff": [
    0,
    6,
    18,
    4
  ]
}

The recording shows the payoffs 0, 6, 18 and 4, rounded to cents with lmf.round.

You can change the paths, points, the strike and the barrier, but the list needs at least four paths of points numbers each: with three paths of six, line 3 stops with "Line 3: FloatList.at: index out of range: 18". Numbers left over after the last whole path are ignored.

A strike or a barrier of 0 or less stops line 6 with "Line 6: option strike must be positive" or "Line 6: barrier must be positive". A negative points stops nothing: there are no paths and the picture is empty. With points 1 every number is a path of its own.

All prices must be positive: a 0 stops line 12 with "Line 12: Option.path_payoff: prices must be positive, got 0 at index 1", and points of 0 stops it with "Line 12: Option.path_payoff: the path is empty". A list holds at most 64 numbers.

Your turn

The list paths holds several price paths of points points each, one after the other, covering years whole years. The up-and-out call has the strike strike and the barrier barrier; money grows at the continuous rate rate.

The program below should return in whole cents the price that these paths give for the call: the mean of the path payoffs, discounted from years. Decide whether it does, and find the candidates that do. Check runs each candidate on the data shown and on seven others.

The number of points of a path, 5, the strike 100, the barrier 115, the rate 0.04, the time 1, and the whole number of cents that the shown program returns.
let option = instrument.barrier_call(strike, float(years), barrier, "up-out");
let curve = market.flat_curve_compounded(rate, "continuous");
let count = int(floor(float(paths.len()) / float(points)));
let total = 0.0;
let alive = 0;
for (k in range(0, count)) {
  let one = float_list();
  let hit = 0;
  for (i in range(0, points)) {
    one.add(paths.at(k * points + i));
    if (paths.at(k * points + i) >= barrier) { hit = 1; }
  }
  total = total + option.path_payoff(one);
  alive = alive + 1 - hit;
}
let value = curve.discount(float(years)) * total / float(alive);
let answer = int(math_round(lmf.round(value, 2) * 100.0));
{
  "answer": 737
}

paths holds several price paths of points points each, one after the other, covering years whole years. An up-and-out call with the strike strike and barrier barrier pays on a path max(last price - strike, 0) unless a price of the path is at or above barrier, then it pays nothing. The price these paths give is the mean of the payoffs over all paths, discounted from years at the continuous rate rate. Return it in whole cents.

Read the result carefully

Four paths are not a price. The standard error of a mean of four payoffs is large, and the lessons before this one needed thousands of paths. The paths here are typed in; paths drawn from the model with model.sample_path would be equally spaced model paths, not histories of any market.

The price is a mean of payoffs, discounted at the model's rate: it takes the model's way of drawing paths for granted, and here that way is simply the list. A knock-out counts as a zero payoff. It describes a model on made-up inputs and is not investment advice.

Recap

  • The price of a path-dependent option that pays at expiry is the discounted mean of the payoffs over all paths.
  • A path on which the option is cancelled pays zero on that path.
  • A mean over a handful of paths has a large standard error; simulation uses thousands.
  • Given paths make the arithmetic visible; where the paths come from is the model's part.