SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons

Level 0, Orientation and fluency 0.2 Reading maths Lesson 2 of 4

ConceptLesson 0.2.2 in Level 0, Orientation and fluency. About 15 minutes.

Sums and products: Σ and Π

What Σ means

The capital Greek letter Σ\Sigma (sigma) means "add up". Here is a sum written out in full and in sigma notation:

∑i=14i2=12+22+32+42=1+4+9+16=30\begin{aligned} \sum_{i=1}^{4} i^2 &= 1^2 + 2^2 + 3^2 + 4^2 \\ &= 1 + 4 + 9 + 16 = 30 \end{aligned}

Read it as "the sum of i2i^2 for ii from 1 to 4". The letter ii is the index. It starts at the number below the Σ\Sigma, goes up by 1 each time, and stops at the number on top. The expression to the right of Σ\Sigma is the term: work it out for each ii and add the results.

Rule: Sigma notation

∑i=mnai=am+am+1+⋯+an\sum_{i=m}^{n} a_i = a_m + a_{m+1} + \cdots + a_n

Start the index at mm, add one term for each whole number up to nn, and include nn itself. That makes n−m+1n - m + 1 terms.

Try it

A sum is a loop that keeps a running total. Python's sum does the same in one line.

Both need range(1, 5) to reach i=4i = 4, because a range stops just before its second number. The upper limit nn becomes range(m, n + 1).

⌘/Ctrl + Enter runs the cell

Sums of data

Most sums in this course add up a list of values. With x1=4x_1 = 4, x2=8x_2 = 8, x3=15x_3 = 15, x4=16x_4 = 16:

∑i=14xi=4+8+15+16=43xˉ=1n∑i=1nxi=434=10.75\begin{gathered} \sum_{i=1}^{4} x_i = 4 + 8 + 15 + 16 = 43 \\[6pt] \bar{x} = \frac{1}{n}\sum_{i=1}^{n} x_i = \frac{43}{4} = 10.75 \end{gathered}

The second formula is the average from lesson 0.2.1, written with Σ\Sigma. When the limits are the whole list, books often drop them and write ∑ixi\sum_i x_i, or just ∑xi\sum x_i.

The name of the index does not matter. ∑i=1nxi\sum_{i=1}^{n} x_i and ∑k=1nxk\sum_{k=1}^{n} x_k are the same sum, just as renaming a loop variable does not change a loop.

Try it

For a list of numbers, sum(x) is ∑xi\sum x_i. NumPy has np.sum and np.mean, which work on whole arrays at once.

⌘/Ctrl + Enter runs the cell

Three rules for sums

Write a sum out in full and these rules are ordinary arithmetic. They let you pull numbers out of a sum and split it into simpler pieces.

Rule: Constant multiple

∑i=1nc ai=c∑i=1nai\sum_{i=1}^{n} c\, a_i = c \sum_{i=1}^{n} a_i

A number that multiplies every term can come out in front. Doubling every value doubles the total.

Rule: Sum of two sequences

∑i=1n(ai+bi)=∑i=1nai+∑i=1nbi\sum_{i=1}^{n} (a_i + b_i) = \sum_{i=1}^{n} a_i + \sum_{i=1}^{n} b_i

A sum of sums can be split into two sums, and two sums can be joined into one.

Rule: Sum of a constant

∑i=1nc=n c\sum_{i=1}^{n} c = n\,c

Adding the same number cc once for each of nn terms gives nn times cc. For example, ∑i=153=15\sum_{i=1}^{5} 3 = 15.

Together they handle sums like ∑i=14(2xi+1)\sum_{i=1}^{4} (2x_i + 1) with the four values above. Split it, pull out the 2, and add the constant four times: 2×43+4×1=902 \times 43 + 4 \times 1 = 90.

Try it

Check the rules on the same data. Each line prints the long way and the short way.

⌘/Ctrl + Enter runs the cell

Weighted sums

A weighted sum multiplies each value by its own weight, then adds:

∑i=1nwixi=w1x1+w2x2+⋯+wnxn\sum_{i=1}^{n} w_i x_i = w_1 x_1 + w_2 x_2 + \cdots + w_n x_n

With weights 0.5,0.3,0.20.5, 0.3, 0.2 and values 10,20,3010, 20, 30, that is 5+6+6=175 + 6 + 6 = 17. When the weights add up to 1, as here, the result is a weighted average. Case study 0.2.4 uses exactly this sum for a portfolio.

Try it

Pair up the weights and values with zip, or let NumPy do it. The @ operator multiplies in pairs and adds, which is a weighted sum in one symbol.

⌘/Ctrl + Enter runs the cell

Products with Π

The capital Greek letter Π\Pi (pi) does for multiplication what Σ\Sigma does for addition:

∏i=14i=1×2×3×4=24\prod_{i=1}^{4} i = 1 \times 2 \times 3 \times 4 = 24

Rule: Pi notation

∏i=mnai=am⋅am+1⋯an∏i=1nc=cn\begin{gathered} \prod_{i=m}^{n} a_i = a_m \cdot a_{m+1} \cdots a_n \\ \prod_{i=1}^{n} c = c^n \end{gathered}

Multiply the term for each index from mm to nn. Multiplying the same cc nn times gives cnc^n.

Products appear whenever something grows in steps. Say a value grows by 10%, then falls by 5%, then grows by 20%. Write gig_i for the growth in step ii, so g1=0.10g_1 = 0.10, g2=−0.05g_2 = -0.05 and g3=0.20g_3 = 0.20.

∏i=13(1+gi)=1.10×0.95×1.20=1.254\begin{aligned} \prod_{i=1}^{3} (1 + g_i) &= 1.10 \times 0.95 \times 1.20 \\ &= 1.254 \end{aligned}

So the value ends up multiplied by 1.254. Lesson 1.4.3 shows how logarithms turn a Π\Pi into a Σ\Sigma.

Try it

math.prod is the product of a list, as sum is its sum.

The second line prints 1.2539999999999998. That is rounding inside the computer, not an error.

⌘/Ctrl + Enter runs the cell

Empty sums and empty products

What if the top limit is below the bottom one, as in ∑i=10ai\sum_{i=1}^{0} a_i? Then there are no terms at all. By convention an empty sum is 0 and an empty product is 1.

These are the values that change nothing: adding 0 or multiplying by 1 leaves a total as it was. Python follows the same convention, and the coding exercise in lesson 0.2.3 relies on it.

Try it

range(1, 1) is empty, so both of these have nothing to add or multiply.

⌘/Ctrl + Enter runs the cell

Common mistakes

Try it

  1. The sum of squares is not the square of the sum. For 1, 2, 3: ∑ai2=14\sum a_i^2 = 14, but (∑ai)2=36\left(\sum a_i\right)^2 = 36.
  2. The sum of products is not the product of sums. With the weights above, ∑wixi=17\sum w_i x_i = 17, but (∑wi)(∑xi)=1×60=60\left(\sum w_i\right)\left(\sum x_i\right) = 1 \times 60 = 60.
  3. Count the terms. ∑i=1nc\sum_{i=1}^{n} c is ncn c, not cc. And range(1, n) stops one short of nn.
⌘/Ctrl + Enter runs the cell

Sums and products

0 of 9 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
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

  • ∑i=mnai\sum_{i=m}^{n} a_i adds the term for every index from mm to nn, both included: n−m+1n - m + 1 terms. In Python, sum(a(i) for i in range(m, n + 1)).
  • Constants come out: ∑c ai=c∑ai\sum c\,a_i = c\sum a_i. Sums split: ∑(ai+bi)=∑ai+∑bi\sum (a_i + b_i) = \sum a_i + \sum b_i. And ∑i=1nc=nc\sum_{i=1}^{n} c = nc.
  • A weighted sum is ∑wixi\sum w_i x_i, or w @ x in NumPy.
  • ∏i=mnai\prod_{i=m}^{n} a_i multiplies the terms; math.prod in Python.
  • An empty sum is 0 and an empty product is 1.
  • ∑ai2≠(∑ai)2\sum a_i^2 \neq \left(\sum a_i\right)^2 and ∑aibi≠(∑ai)(∑bi)\sum a_i b_i \neq \left(\sum a_i\right)\left(\sum b_i\right).

Free further reading

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