SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 1.2.1 Lines: slope and interceptConcept · 25 min
      2. 1.2.2 Quadratics and completing the squareConcept · 25 min
      3. 1.2.3 Practice set: lines and quadraticsPractice set · 20 min
      4. 1.2.4 Case study: the minimum-variance two-asset portfolioCase study · 30 min

Level 1, Precalculus 1.2 Lines and quadratics Lesson 1 of 4

ConceptLesson 1.2.1 in Level 1, Precalculus. About 25 minutes.

Lines: slope and intercept

What a slope measures

A straight line changes at a steady rate. Every step of 1 to the right changes yy by the same amount, and that amount is the line's slope. Its units are units of yy per unit of xx.

A candle is 24 cm tall when it is lit, and it burns down 1.5 cm every hour. Here is its height hh after tt hours.

tt (hours)01234
hh (cm)2422.52119.518

Each hour takes off the same 1.5 cm, so the points lie on a straight line. Its slope is −1.5-1.5 cm per hour, negative because the height falls. The starting height, 24 cm at t=0t = 0, is where the line meets the vertical axis.

Slope from two points: rise over run

Usually you are not told the rate. You have two points on the line instead. Going from the first point to the second, the run is the change in xx and the rise is the change in yy.

Rule: Slope from two points

m=y2−y1x2−x1m = \frac{y_2 - y_1}{x_2 - x_1}

The slope mm of the line through (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is the rise divided by the run. Any two points of the line give the same slope, in either order, as long as top and bottom use the same order.

For (1,3)(1, 3) and (4,9)(4, 9), the run is 4−1=34 - 1 = 3 and the rise is 9−3=69 - 3 = 6, so m=6÷3=2m = 6 \div 3 = 2.

Two other points of the same line, (2,5)(2, 5) and (3,7)(3, 7), give 2÷1=22 \div 1 = 2 again. In reverse order, 3−91−4=−6−3=2\frac{3 - 9}{1 - 4} = \frac{-6}{-3} = 2.

Rising, falling and flat

The sign of the rise, over a positive run, gives the sign of the slope.

Rise over run on three lines, each with a run of 3. The dot marked cc is where each line crosses the yy-axis.

  • Positive: the line climbs from left to right. From (1,3)(1, 3) to (4,9)(4, 9) the slope is 2.
  • Negative: the line falls. From (1,6)(1, 6) to (4,3)(4, 3) the rise is −3-3, so the slope is −3÷3=−1-3 \div 3 = -1.
  • Zero: the line is flat. From (1,4)(1, 4) to (4,4)(4, 4) the rise is 0, so the slope is 0.

The size of the slope is the steepness. A slope of −3-3 is as steep as 3, but falls. A slope of 12\frac{1}{2} climbs 1 for every 2 steps to the right.

Vertical lines have no slope

Through (2,1)(2, 1) and (2,5)(2, 5) the run is 2−2=02 - 2 = 0, so rise over run would divide by zero. A vertical line has no slope at all, which is not the same as a slope of 0. Its equation is x=2x = 2, and it fails the vertical line test of lesson 1.1.1, so it is not the graph of a function.

Try it

slope is the rule above, with each point written as a pair (x, y). The cell checks every case in this section, including both orders for the first line.

The vertical line raises ZeroDivisionError, which the try block catches. Each slope prints as a decimal (2.0, not 2) because / in Python always gives one.

⌘/Ctrl + Enter runs the cell

The equation of a line

Every line that is not vertical can be written as

y=mx+cy = mx + c

where mm is the slope and cc is the intercept: the value of yy where the line crosses the yy-axis, at x=0x = 0. Lesson 1.1.1 called it f(0)f(0), and it is in the units of yy. The candle is h=−1.5t+24h = -1.5t + 24: slope −1.5-1.5 cm per hour, intercept 24 cm.

Rule: Line through two points

m=y2−y1x2−x1c=y1−m x1\begin{gathered} m = \frac{y_2 - y_1}{x_2 - x_1} \\ c = y_1 - m\,x_1 \end{gathered}

Find the slope first. Then put one point into y=mx+cy = mx + c and solve for the intercept: y1=mx1+cy_1 = m x_1 + c gives c=y1−mx1c = y_1 - m x_1.

Example 1, by a table and by algebra. Take (1,3)(1, 3) and (4,9)(4, 9) again, with slope 2. Each step of 1 in xx adds 2 to yy, so one step back from (1,3)(1, 3) gives y=1y = 1 at x=0x = 0. The table steps forward from there and lands on (4,9)(4, 9):

xx01234
yy13579

The algebra agrees: c=3−2×1=1c = 3 - 2 \times 1 = 1, so the line is y=2x+1y = 2x + 1. Check it with the other point: 2×4+1=92 \times 4 + 1 = 9.

Example 2, a falling line. Through (2,7)(2, 7) and (6,−1)(6, -1), the slope is −1−76−2=−84=−2\frac{-1 - 7}{6 - 2} = \frac{-8}{4} = -2. Then c=7−(−2)(2)=7+4=11c = 7 - (-2)(2) = 7 + 4 = 11, so y=−2x+11y = -2x + 11. Check: −2×6+11=−1-2 \times 6 + 11 = -1.

From one point and a slope

Sometimes you know one point (x1,y1)(x_1, y_1) and the slope mm. Then you can write the line down at once, without finding cc first.

Rule: Point and slope

y=y1+m(x−x1)y = y_1 + m(x - x_1)

At x=x1x = x_1 the bracket is 0, so y=y1y = y_1: the line passes through the point. Each step of 1 to the right adds mm. Multiplying out gives y=mx+(y1−mx1)y = mx + (y_1 - m x_1), the same line as before.

Slope 3 through (2,5)(2, 5) gives y=5+3(x−2)y = 5 + 3(x - 2), which multiplies out to y=3x−1y = 3x - 1. Write Δx\Delta x (read "delta xx") for a change in xx. A change of Δx\Delta x moves yy by m Δxm\,\Delta x: from x=2x = 2 to 2.5, yy rises 3×0.5=1.53 \times 0.5 = 1.5, to 6.5.

Lines written another way

A line may come as 3x+2y=63x + 2y = 6, and its slope is not 3. Make yy the subject first, as in lesson 0.3.2: 2y=−3x+62y = -3x + 6, so y=−1.5x+3y = -1.5x + 3, with slope −1.5-1.5 and intercept 3.

An equation with no yy in it, such as 2x=42x = 4, is the vertical line x=2x = 2.

Try it

line_through returns the slope and the intercept from two points, using the rule above. It recovers both examples.

np.polyfit(x, y, 1) does the same from a list of xx values and a list of yy values; the 1 means a straight line. Given four points that are not quite on a line, it returns the line that fits them best, here y=1.94x+1.09y = 1.94x + 1.09. Module 5.10 explains how.

⌘/Ctrl + Enter runs the cell

Where a line crosses the xx-axis

On the xx-axis, y=0y = 0. So the crossing, the line's zero from lesson 1.1.1, solves mx+c=0mx + c = 0, which gives x=−cmx = -\frac{c}{m}.

For y=−2x+11y = -2x + 11 the crossing is at x=5.5x = 5.5. For the candle, −1.5t+24=0-1.5t + 24 = 0 gives t=16t = 16: the candle burns out after 16 hours.

A flat line breaks the formula, because m=0m = 0 would put zero on the bottom. The line y=4y = 4 never meets the xx-axis, and y=0y = 0 is the axis itself.

Try it

crossing returns −cm-\frac{c}{m}, or None for a flat line.

It gives 5.5 for y=−2x+11y = -2x + 11 and 16.0 for the candle.

⌘/Ctrl + Enter runs the cell

Where two lines meet

Two lines meet where they give the same yy for the same xx. So set the two right-hand sides equal and solve, as in lesson 0.3.2. For y=2x+1y = 2x + 1 and y=−x+7y = -x + 7:

2x+1=−x+73x=6x=2\begin{aligned} 2x + 1 &= -x + 7 \\ 3x &= 6 \\ x &= 2 \end{aligned}

Then y=2×2+1=5y = 2 \times 2 + 1 = 5, so they meet at (2,5)(2, 5). The other line agrees: −2+7=5-2 + 7 = 5.

Lines with different slopes cross at one point. Lines with the same slope stay the same distance apart, here 3, so they never meet.

Rule: Where two lines meet

m1x+c1=m2x+c2m_1 x + c_1 = m_2 x + c_2

Different slopes: exactly one meeting point. Same slope and different intercepts: parallel lines, which never meet. Same slope and same intercept: one line written twice, so every point is shared.

For the parallel lines y=2x+1y = 2x + 1 and y=2x−2y = 2x - 2, the equation is 2x+1=2x−22x + 1 = 2x - 2. Taking 2x2x from both sides leaves 1=−21 = -2, which is false for every xx, so there is no meeting point.

Try it

meet solves m1x+c1=m2x+c2m_1 x + c_1 = m_2 x + c_2, which gives x=c2−c1m1−m2x = \frac{c_2 - c_1}{m_1 - m_2}, then finds yy from the first line.

It returns None when the slopes are equal, because the bottom would be 0.

⌘/Ctrl + Enter runs the cell

Lesson 1.6.1 joins data points with lines, and lesson 2.2.1 uses rise over run to measure how fast a curve changes. Case study 1.2.4 meets a line in finance.

Common mistakes

  1. Use the same order on top and bottom. y2−y1x1−x2\frac{y_2 - y_1}{x_1 - x_2} has the wrong sign.
  2. Rise over run, not run over rise. For (1,3)(1, 3) and (4,9)(4, 9), 36=0.5\frac{3}{6} = 0.5 is upside down; the slope is 2.
  3. Watch the signs in c=y1−mx1c = y_1 - m x_1. With m=−2m = -2 and the point (2,7)(2, 7), c=7+4=11c = 7 + 4 = 11, not 7−4=37 - 4 = 3.
  4. The intercept cc is on the yy-axis, at x=0x = 0. The crossing of the xx-axis is −cm-\frac{c}{m}.
  5. Make yy the subject before reading the slope. The slope of 3x+2y=63x + 2y = 6 is −1.5-1.5, not 3.
  6. Flat and vertical are different. A flat line has slope 0. A vertical line has no slope and cannot be written as y=mx+cy = mx + c.
  7. Equal slopes mean parallel lines. Solving gives a false statement such as 1=−21 = -2, so the lines never meet.

Lines

0 of 12 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.
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

  • Slope m=y2−y1x2−x1m = \frac{y_2 - y_1}{x_2 - x_1}: the change in yy for each step of 1 in xx, in units of yy per unit of xx. Positive rises, negative falls, 0 is flat; a vertical line has no slope.
  • A line is y=mx+cy = mx + c, with intercept cc the value of yy at x=0x = 0. From two points: find mm, then c=y1−mx1c = y_1 - m x_1.
  • From one point and the slope: y=y1+m(x−x1)y = y_1 + m(x - x_1). A change Δx\Delta x moves yy by m Δxm\,\Delta x.
  • A line crosses the xx-axis at x=−cmx = -\frac{c}{m}; a flat line never does, unless it is the axis.
  • Two lines meet where m1x+c1=m2x+c2m_1 x + c_1 = m_2 x + c_2: once if the slopes differ, never if they are parallel.

Free further reading

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

  • Lines

    Paul's Online Notes. Notes.

    Slope, the slope-intercept and point-slope forms, and parallel and perpendicular lines.

  • Common Graphs

    Paul's Online Notes. Notes.

    Lines, parabolas, circles and other standard graphs, and how to sketch them.