SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 1.1.1 What a function is: domain, range and notationConcept · 25 min
      2. 1.1.2 Transformations and piecewise functionsConcept · 30 min
      3. 1.1.3 Composition and inverse functionsConcept · 25 min
      4. 1.1.4 Practice set: functionsPractice set · 20 min
      5. 1.1.5 Case study: option payoff diagramsCase study · 30 min

Level 1, Precalculus 1.1 Functions and graphs Lesson 2 of 5

ConceptLesson 1.1.2 in Level 1, Precalculus. About 30 minutes.

Transformations and piecewise functions

Changes outside move the graph up or down

Adding a number to a function's output moves its whole graph up. If g(x)=f(x)+kg(x) = f(x) + k, every output of gg is kk more than the output of ff at the same input. A negative kk moves the graph down.

The shift kk is measured in the output's units. If f(t)f(t) is a temperature in °C at hour tt, then f(t)+5f(t) + 5 is the same day's pattern, 5 °C warmer.

Changes inside move it sideways

Changing the input moves the graph sideways, and the direction surprises most people. g(x)=f(x−h)g(x) = f(x - h) moves the graph hh units to the right.

Here is why. At input xx, gg gives what ff gave at x−hx - h, which is hh units further left. So every feature of ff shows up hh units later in gg.

With the temperature, f(t−2)f(t - 2) is the same pattern 2 hours later.

Rule: Shifts

f(x)+k: up by kf(x−h): right by h\begin{gathered} f(x) + k: \ \text{up by } k \\ f(x - h): \ \text{right by } h \end{gathered}

A change outside the function moves the graph up or down, in the direction you expect. A change inside moves it sideways, the opposite way to the sign: f(x−3)f(x - 3) moves right and f(x+3)f(x + 3) moves left.

Take f(x)=x2f(x) = x^2 and g(x)=(x−3)2−4g(x) = (x - 3)^2 - 4, which is f(x−3)−4f(x - 3) - 4. A table shows the move:

xx0123456
f(x)=x2f(x) = x^20149162536
g(x)g(x)50−3-3−4-4−3-305

Each value of ff turns up in gg three columns later and 4 lower: g(3)=f(0)−4=−4g(3) = f(0) - 4 = -4 and g(5)=f(2)−4=0g(5) = f(2) - 4 = 0.

Algebra says the same. x2x^2 is smallest at x=0x = 0, and (x−3)2(x - 3)^2 is smallest where x−3=0x - 3 = 0, at x=3x = 3. There gg is −4-4, so the lowest point moves from (0,0)(0, 0) to (3,−4)(3, -4).

The zeros of gg come from (x−3)2=4(x - 3)^2 = 4, so x−3=2x - 3 = 2 or −2-2: x=5x = 5 or x=1x = 1.

x2x^2 moved 3 right and 4 down. Every point makes the same move: (2,4)(2, 4) goes to (5,0)(5, 0), and the lowest point (0,0)(0, 0) goes to (3,−4)(3, -4).

The domain moves with the graph. The function x−3\sqrt{x - 3} from lesson 1.1.1 is x\sqrt{x} moved 3 right, which is why its domain starts at 3 instead of 0.

Try it

The cell builds gg from ff exactly as the formula says: f(x - 3) - 4. The two printed rows are the table above.

⌘/Ctrl + Enter runs the cell

Flips and stretches

A minus sign flips a graph, and a multiplier stretches it. Where you put them decides which way.

  • −f(x)-f(x) turns every output upside down: a flip over the xx-axis.
  • f(−x)f(-x) swaps left and right: a flip over the yy-axis.
  • a f(x)a\,f(x) with a>1a > 1 stretches the graph away from the xx-axis; with 0<a<10 < a < 1 it squashes it towards the axis. A negative aa stretches and flips at once.

Follow the point (4,2)(4, 2) of x\sqrt{x} through each one:

xx0149
x\sqrt{x}0123
−x-\sqrt{x}0−1-1−2-2−3-3
2x2\sqrt{x}0246
12x\frac{1}{2}\sqrt{x}00.511.5

The flip −x\sqrt{-x} needs −x≥0-x \ge 0, so its domain is x≤0x \le 0: the domain flips too. It gives 0, 1, 2 and 3 at x=0,−1,−4,−9x = 0, -1, -4, -9.

x\sqrt{x} and three changed copies, each carrying the point (4,2)(4, 2) somewhere new. The flips mirror the graph in an axis; the stretch doubles every height.

Three cases catch people out.

  • Zeros stay put under a stretch or a flip over the xx-axis: 2×02 \times 0 and −0-0 are still 0.
  • A symmetric graph ignores f(−x)f(-x). For x2x^2, (−x)2=x2(-x)^2 = x^2, so the flip over the yy-axis changes nothing.
  • −x2-x^2 is not (−x)2(-x)^2. By the order of operations (lesson 0.3.1), −x2-x^2 means −(x2)-(x^2), the parabola opening downwards. (−x)2(-x)^2 is x2x^2 again.

Multiplying the input acts sideways, again the opposite way. f(2x)f(2x) reaches each height at half the input, so the graph is squeezed towards the yy-axis. x2x^2 reaches 4 at x=2x = 2, but (2x)2(2x)^2 reaches it at x=1x = 1.

Rule: Flips and stretches

−f(x): flip over the x-axisf(−x): flip over the y-axisa f(x): stretch up and down by af(bx): squeeze sideways by b\begin{gathered} -f(x): \ \text{flip over the } x\text{-axis} \\ f(-x): \ \text{flip over the } y\text{-axis} \\ a\,f(x): \ \text{stretch up and down by } a \\ f(bx): \ \text{squeeze sideways by } b \end{gathered}

Outside the function, a change acts on heights as written. Inside, it acts on the input, and the effect runs the opposite way.

Try it

The rows are the x\sqrt{x} table, computed on an array. The last row is −x\sqrt{-x} at 0, −1-1, −4-4 and −9-9.

NumPy prints −0-0 as -0.. It is the same number as 0.

⌘/Ctrl + Enter runs the cell

Several moves at once

Most formulas combine moves: a f(x−h)+ka\,f(x - h) + k shifts right by hh, stretches by aa (flipping if aa is negative), then shifts up by kk. Work from the inside out, the order you would evaluate the formula in (lesson 0.3.1).

The order matters. With f(x)=x2f(x) = x^2, 2f(x)+12f(x) + 1 stretches and then lifts by 1: at x=3x = 3 it gives 19. But 2(f(x)+1)2(f(x) + 1) lifts first, and the stretch doubles the lift too: at x=3x = 3 it gives 20.

A second example: −2(x−1)2+3-2(x - 1)^2 + 3 is x2x^2 moved 1 right, stretched by 2 and flipped, then lifted 3. Its highest point is (1,3)(1, 3). At x=0,1,2,3x = 0, 1, 2, 3 it gives 1, 3, 1 and −5-5.

Lesson 1.2.2 writes every quadratic in this form to find its lowest or highest point.

Try the moves yourself. Set h=3h = 3 and k=−4k = -4 to get the graph of the first figure, then make aa negative and watch the lowest point become the highest.

Explore

Move the sliders: k moves the graph up, h moves it right, a stretches it and a negative a flips it. The dashed curve is the original.

−505−505

y = x²

Compared with y = x²
no change yet
The lowest point
(0, 0) moves to (0, 0)

Piecewise functions

A piecewise function uses a different rule on different parts of its domain. You met one in lesson 0.3.3: the absolute value is xx when x≥0x \ge 0 and −x-x when x<0x < 0. Here is another:

p(x)={2xif x<1x+1if x≥1p(x) = \begin{cases} 2x & \text{if } x < 1 \\ x + 1 & \text{if } x \ge 1 \end{cases}

To evaluate it, first find which piece the input belongs to. p(3)=3+1=4p(3) = 3 + 1 = 4, but p(−2)=2×(−2)=−4p(-2) = 2 \times (-2) = -4. At the boundary, x=1x = 1 falls in the second piece, so p(1)=2p(1) = 2.

Here the left piece also gives 2×1=22 \times 1 = 2 at x=1x = 1, so the two pieces meet and the graph has no break. They need not meet. Take

j(x)={1if x<2xif x≥2j(x) = \begin{cases} 1 & \text{if } x < 2 \\ x & \text{if } x \ge 2 \end{cases}

Just left of 2 the output is 1, as in j(1.99)=1j(1.99) = 1. At 2 it is j(2)=2j(2) = 2. The graph jumps up by 1 at x=2x = 2.

A jump, and pieces that meet. An open dot marks a point the graph comes up to but does not include; a closed dot marks the value the function takes.

Rule: Piecewise functions

find the piece first,then use its rule\begin{gathered} \text{find the piece first,} \\ \text{then use its rule} \end{gathered}

Each input belongs to exactly one piece; the boundary goes to the piece whose condition has ≤\le or ≥\ge. On a graph, a closed dot is on the graph and an open dot is not.

Two more cases matter. If two pieces both claimed x=1x = 1 with different outputs, the rule would not be a function at all. If no piece covers an input, that input is not in the domain.

Lesson 2.1.2 calls a graph with no break continuous, and studies jumps like this one.

Try it

np.where(condition, a, b) takes a where the condition holds and b elsewhere. That is a two-piece function on a whole array.

The first line is pp at −2,0,1,3-2, 0, 1, 3. The second is jj at 0,1.99,2,30, 1.99, 2, 3: the jump shows between 1.99 and 2.

⌘/Ctrl + Enter runs the cell

The ramp

The most useful piecewise function in this course is the ramp, max⁡(x,0)\max(x, 0): "the larger of xx and 0". It is 0 for negative inputs and xx itself for positive ones. Its two pieces meet at a corner, (0,0)(0, 0).

Rule: The ramp

max⁡(x,0)={xif x≥00if x<0\max(x, 0) = \begin{cases} x & \text{if } x \ge 0 \\ 0 & \text{if } x < 0 \end{cases}

Keep a positive number; replace a negative one by 0. max⁡(x−h,0)\max(x - h, 0) is the same ramp moved right by hh.

Every move of this lesson applies. max⁡(x−3,0)\max(x - 3, 0) is flat at 0 up to 3, then climbs with slope 1. The flip over the yy-axis gives max⁡(−x,0)\max(-x, 0), and moved to 3 it is max⁡(3−x,0)\max(3 - x, 0): it falls to 0 at 3 and stays there.

A ramp and its mirror image add up to the absolute value: max⁡(x,0)+max⁡(−x,0)=∣x∣\max(x, 0) + \max(-x, 0) = |x|. For any xx, one of the two is 0 and the other is the distance from 0. Case study 1.1.5 builds every option payoff from these ramps.

Try it

np.maximum(x, 0) is the ramp on a whole array. Python's built-in max compares single numbers only, so use np.maximum for arrays.

The rows are max⁡(x,0)\max(x, 0), max⁡(x−3,0)\max(x - 3, 0) and max⁡(3−x,0)\max(3 - x, 0) at −2,0,1,3,5-2, 0, 1, 3, 5. The last two lines are the ramp plus its mirror, and ∣x∣|x|: they match.

⌘/Ctrl + Enter runs the cell

Common mistakes

  1. The sideways shift goes against the sign. f(x−3)f(x - 3) moves the graph right, not left.
  2. −x2-x^2 is not (−x)2(-x)^2. The first is never positive; the second is never negative.
  3. The order of moves matters. 2f(x)+12f(x) + 1 is not 2(f(x)+1)2(f(x) + 1): the stretch also doubles any lift made before it.
  4. An inside multiplier squeezes. f(2x)f(2x) is narrower than f(x)f(x), not wider.
  5. The domain moves too. x−3\sqrt{x - 3} starts at 3, and −x\sqrt{-x} lives on x≤0x \le 0.
  6. Check which piece applies, including at the boundary: a closed dot is on the graph, an open dot is not.
  7. Use np.maximum on arrays, not Python's max.

Transformations and pieces

0 of 13 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
  13. 13.
How to type answers
  • Powers with ^: x^7, 2^(1/3), a^-2.
  • Multiply with * or by writing side by side: 3x^2, 2(x+1).
  • ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
  • Your first answer to each question is saved: it counts towards your score and brings the question back for review.
  • Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.

Summary card

  • f(x)+kf(x) + k moves the graph up by kk; f(x−h)f(x - h) moves it right by hh. Inside changes act the opposite way to their sign.
  • −f(x)-f(x) flips over the xx-axis, f(−x)f(-x) over the yy-axis, af(x)a f(x) stretches up and down, and f(bx)f(bx) squeezes sideways.
  • In a f(x−h)+ka\,f(x - h) + k, work from the inside out: shift sideways, stretch or flip, then shift up. Order matters.
  • A piecewise function uses a different rule on each part of the domain. Find the piece first; at a jump, the closed dot is the value.
  • The ramp max⁡(x,0)\max(x, 0) keeps positives and zeroes negatives; max⁡(x−h,0)\max(x - h, 0) is the ramp moved right by hh, and max⁡(x,0)+max⁡(−x,0)=∣x∣\max(x, 0) + \max(-x, 0) = |x|.
  • In NumPy: np.where(condition, a, b) and np.maximum(x, 0).

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.