Statistical Bootstrapping by Case Resampling

This entry is part 17 of 17 in the series Numpy Strategies

NumPy Strategies 0.1.7

I haven’t blogged in a while, because I am supposed to work on a Big Secret Project (BSP). Obviously, I am not allowed to talk about that. The Product Owner/Manager of our FHF (Fantasy Hedge Funds) has come up with the following User Story:

  • Measure the margin of error of a small data sample.

This is about the data that we are using. Our Product Master is worried that we don’t have enough data to do anything meaningful. One way to solve this issue is to apply Statistical Bootstrapping or a type of bootstrapping called Case Resampling. We will apply this method to the problem of computing the mean of the AAPL stock price and the normal distribution.

The steps of the algorithm are:

  1. Store the empirical distribution from our data.
  2. Generate random samples from this distribution of the same size as the original sample.
  3. Calculate and store the means of these samples.
  4. Determine in which percentile of the means distribution the mean of the original sample lies.

The code on Github and below performs these steps.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import numpy
import sys
import matplotlib.pyplot
from matplotlib.finance import quotes_historical_yahoo
from datetime import date
import scipy.stats
 
def random_indices(N):
   return numpy.random.randint(0, N, N)
 
def random_values(values):
   return numpy.take(values, random_indices(len(values)))
 
def generate_means(values):
   NTRIES = int(sys.argv[2])
 
   means = numpy.zeros(NTRIES)
 
   for i in xrange(NTRIES):
      means[i] = random_values(values).mean()
 
   return means
 
def format_mean(values):
   return "Mean=%.3f" % (values.mean())
 
def plot_percentile(values, means):
   matplotlib.pyplot.hist(means)
   percentile = scipy.stats.percentileofscore(means, values.mean())
   matplotlib.pyplot.legend([format_mean(means), "Percentile=%.2f" %(percentile)])
 
def plot(values):
   matplotlib.pyplot.hist(values)
   matplotlib.pyplot.legend([format_mean(values)])
 
today = date.today()
start = (today.year - 1, today.month, today.day)
quotes = quotes_historical_yahoo(sys.argv[1], start, today)
close =  numpy.array([q[4] for q in quotes])
close_means = generate_means(close)
 
normal_values = numpy.random.normal(size=len(close))
normal_means = generate_means(normal_values)
 
matplotlib.pyplot.subplot(221)
matplotlib.pyplot.title("Close Values")
plot(close)
 
matplotlib.pyplot.subplot(222)
matplotlib.pyplot.title("Normal Values")
plot(normal_values)
 
matplotlib.pyplot.subplot(223)
matplotlib.pyplot.title("Close Means")
plot_percentile(close, close_means)
 
matplotlib.pyplot.subplot(224)
matplotlib.pyplot.title("Normal Means")
plot_percentile(normal_values, normal_means)
 
matplotlib.pyplot.show()

After running the program I get the following plots for the AAPL close price and the Gaussian distribution with 400 generated samples.

Case Resampling


If you liked this post and are interested in NumPy check out NumPy Beginner’s Guide by yours truly.

Share
Posted in programming | Tagged , , , | Leave a comment

Simulated Random Trading

This entry is part 15 of 17 in the series Numpy Strategies

NumPy Strategies 0.1.6

Our Product Owner and Product Manager got talking about our latest strategy. They decided that our Fantasy Hedge Fund needs to have simulations of these strategies. The new User Story:

  • Simulate periodic trading with random buying and selling.

We will simulate trading by taking some random days from a trading year.

1. Get close prices

Let’s start by downloading historical data for a stock. For instance, AAPL.

1
2
3
4
5
today = date.today()
start = (today.year - 1, today.month, today.day)
 
quotes = quotes_historical_yahoo(sys.argv[1], start, today)
close =  numpy.array([q[4] for q in quotes])

2. Generate random indices

Generate random integers with the NumPy randint function.

1
   return numpy.random.randint(0, high, size)

3. Simulate trades

Simulate trades with the random indices from the previous step. Use the NumPy take function to extract random close prices from the array of step 1.

1
2
3
   buys = numpy.take(close, get_indices(len(close), nbuys))
   sells = numpy.take(close, get_indices(len(close), nbuys))
   profits[i] = sells.sum() - buys.sum()

4. Plot a histogram of the profits

Let’s plot a histogram of the profits for a large number of simulations.

1
2
matplotlib.pyplot.hist(profits)
matplotlib.pyplot.show()

The resulting histogram of 2000 simulations for AAPL with 5 buys and sells in a year:

Random Periodic Simulation

What just happened?

This is the Retrospective of Sprint 16. One thing we noticed is that the profits variance is HUGE! So it will be hard to beat a random strategy. The mean is close to 0, which was expected.

Below is the complete code or get it from Github.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from matplotlib.finance import quotes_historical_yahoo
from datetime import date
import numpy
import sys
import matplotlib.pyplot
 
def get_indices(high, size):
   #2. Generate random indices
   return numpy.random.randint(0, high, size)
 
#1. Get close prices.
today = date.today()
start = (today.year - 1, today.month, today.day)
 
quotes = quotes_historical_yahoo(sys.argv[1], start, today)
close =  numpy.array([q[4] for q in quotes])
 
nbuys = int(sys.argv[2])
N = int(sys.argv[3])
profits = numpy.zeros(N)
 
for i in xrange(N):
   #3. Simulate trades
   buys = numpy.take(close, get_indices(len(close), nbuys))
   sells = numpy.take(close, get_indices(len(close), nbuys))
   profits[i] = sells.sum() - buys.sum()
 
print "Mean", profits.mean() 
print "Std", profits.std()
 
#4. Plot a histogram of the profits
matplotlib.pyplot.hist(profits)
matplotlib.pyplot.show()


If you liked this post and are interested in NumPy check out NumPy Beginner’s Guide by yours truly.

Share
Posted in programming | Tagged , , , | Leave a comment

NumPy Project Euler Problem 9

This entry is part 9 of 9 in the series NumPy Project Euler

Project Euler Problem 9 is a tough one. After reading the Pythagorean Triple Wikipedia page, I implemented a NumPy solution with Euclid’s Formula.

Euclids Formula


1. Create m and n arrays

The Euclid’s Formula defines indices m and n. We will create arrays to hold these indices.

1
2
m = numpy.arange(33)
n = numpy.arange(33)

2. Calculate a, b and c

The second step is to calculate a, b and c of the Pythagorean triple using Euclid’s formula. Use the outer function to get the cartesian products, difference and sums we require.

1
2
3
a = numpy.subtract.outer(m ** 2, n ** 2)
b = 2 * numpy.multiply.outer(m, n)
c = numpy.add.outer(m ** 2, n ** 2)

3. Find the index

At this point we have a number of arrays containing a, b and c values. However, we still need to find the values that conform to the problem’s condition. Find the index of those values with the NumPy where function.

1
idx =  numpy.where((a + b + c) == 1000)

4. Check solution

Check the solution with the numpy.testing module.

1
numpy.testing.assert_equal(a[idx]**2 + b[idx]**2, c[idx]**2)

Below is the complete code or get it from Github

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import numpy
import numpy.testing
 
#A Pythagorean triplet is a set of three natural numbers, a < b < c, for which,
#a ** 2 + b ** 2 = c ** 2
#
#For example, 32 + 42 = 9 + 16 = 25 = 52.
#
#There exists exactly one Pythagorean triplet for which a + b + c = 1000.
#Find the product abc.
 
#1. Create m and n arrays
m = numpy.arange(33)
n = numpy.arange(33)
 
#2. Calculate a, b and c
a = numpy.subtract.outer(m ** 2, n ** 2)
b = 2 * numpy.multiply.outer(m, n)
c = numpy.add.outer(m ** 2, n ** 2)
 
#3. Find the index
idx =  numpy.where((a + b + c) == 1000)
 
#4. Check solution
numpy.testing.assert_equal(a[idx]**2 + b[idx]**2, c[idx]**2)
print a[idx] * b[idx] * c[idx]


If you liked this post and are interested in NumPy check out NumPy Beginner’s Guide by yours truly.

Share
Posted in programming | Tagged , , , | Leave a comment

NumPy Periodic Dips

This entry is part 13 of 17 in the series Numpy Strategies

NumPy Strategies 0.1.5

The stock market has periodic dips to the downside and sometimes to the upside, but those have a different name. Our Fantasy Hedge Fund needs to rebalance its portfolio 5 times a year (this is all part of our plan of Total World Domination). Therefore this User Story:

  • I want to buy and sell stocks 5 times a year.

We will have a look at the probability distribution of the stock price log returns.

1. Get close prices

Let’s start by downloading historical data for a stock. For instance, AAPL.

1
2
3
4
5
today = date.today()
start = (today.year - 1, today.month, today.day)
 
quotes = quotes_historical_yahoo(sys.argv[1], start, today)
close =  numpy.array([q[4] for q in quotes])

2. Get log returns

Second, calculate the daily log returns of the close prices.

1
logreturns = numpy.diff(numpy.log(close))

3. Calculate breakout and pullback

Now comes the interesting part. Let’s say we want to trade 5 times per year or roughly every 50 days. One strategy would be to buy when the price drops by a certain percentage and sell when the price increases by another percentage. By setting the percentile appropriate for our trading frequency, we can match the corresponding log returns. Scipy offers the scoreatpercentile function, that we will use.

1
2
3
freq = 1/float(sys.argv[2])
breakout = scipy.stats.scoreatpercentile(logreturns, 100 * (1 - freq) )
pullback = scipy.stats.scoreatpercentile(logreturns, 100 * freq)

4. Generate buys and sells

Use the NumPy compress function to generate buys and sells for our close price data.

1
2
3
4
5
6
buys = numpy.compress(logreturns < pullback, close)
sells = numpy.compress(logreturns > breakout, close)
print buys
print sells 
print len(buys), len(sells)
print sells.sum() - buys.sum()

The output for AAPL and a 50 day period is:

1
2
3
4
[ 340.1   377.35  378.    373.17  415.99]
[ 357.    370.8   366.48  395.2   419.55]
5 5
24.42

So we have a profit of 24 dollar, if we buy and sell 5 times an AAPL share.

5. Plot a histogram of the log returns

Just for fun let’s plot the histogram of the log returns with Matplotlib.

1
2
matplotlib.pyplot.hist(logreturns)
matplotlib.pyplot.show()
Log Returns Histogram

Below is the complete code or get it from Github.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from matplotlib.finance import quotes_historical_yahoo
from datetime import date
import numpy
import sys
import scipy.stats
import matplotlib.pyplot
 
#1. Get close prices.
today = date.today()
start = (today.year - 1, today.month, today.day)
 
quotes = quotes_historical_yahoo(sys.argv[1], start, today)
close =  numpy.array([q[4] for q in quotes])
 
#2. Get log returns.
logreturns = numpy.diff(numpy.log(close))
 
#3. Calculate breakout and pullback
freq = 1/float(sys.argv[2])
breakout = scipy.stats.scoreatpercentile(logreturns, 100 * (1 - freq) )
pullback = scipy.stats.scoreatpercentile(logreturns, 100 * freq)
 
#4. Generate buys and sells
buys = numpy.compress(logreturns < pullback, close)
sells = numpy.compress(logreturns > breakout, close)
print buys
print sells 
print len(buys), len(sells)
print sells.sum() - buys.sum()
 
#5. Plot a histogram of the log returns
matplotlib.pyplot.hist(logreturns)
matplotlib.pyplot.show()


If you liked this post and are interested in NumPy check out NumPy Beginner’s Guide by yours truly.

Share
Posted in programming | Tagged , , , | Leave a comment

NumPy Project Euler Problem 8

This entry is part 8 of 9 in the series NumPy Project Euler

Project Euler Problem 8 requires a lot of string manipulation. Still we have some opportunities to practice our NumPy skills.

1. Calculate the product of the 5 element array

First we need to compute the product of an array with 5 elements. We can calculate the product of the elements in an array with the NumPy prod function.

1
   products.append(digits[i:i + 5].prod())

2. Get the max of the products

The products are stored in a Python list. We can convert this to a NumPy array and then find the greatest product with the NumPy max function.

1
print numpy.array(products).max()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy
 
#Find the greatest product of five consecutive digits in the 1000-digit number.
 
number = "73167176531330624919225119674426574742355349194934\
96983520312774506326239578318016984801869478851843\
85861560789112949495459501737958331952853208805511\
12540698747158523863050715693290963295227443043557\
66896648950445244523161731856403098711121722383113\
62229893423380308135336276614282806444486645238749\
30358907296290491560440772390713810515859307960866\
70172427121883998797908792274921901699720888093776\
65727333001053367881220235421809751254540594752243\
52584907711670556013604839586446706324415722155397\
53697817977846174064955149290862569321978468622482\
83972241375657056057490261407972968652414535100474\
82166370484403199890008895243450658541227588666881\
16427171479924442928230863465674813919123162824586\
17866458359124566529476545682848912883142607690042\
24219022671055626321111109370544217506941658960408\
07198403850962455444362981230987879927244284909188\
84580156166097919133875499200524063689912560717606\
05886116467109405077541002256983155200055935729725\
71636269561882670428252483600823257530420752963450"
 
digits = numpy.zeros(1000)
 
for i in xrange(len(number)):
   digits[i] = int(number[i])
 
products = []
 
for i in xrange(len(digits) - 5):
   #1. Calculate the product of the 5 element array
   products.append(digits[i:i + 5].prod())
 
#2. Get the max of the products
print numpy.array(products).max()


If you liked this post and are interested in NumPy check out NumPy Beginner’s Guide by yours truly.

Share
Posted in programming | Tagged , , , | Leave a comment

Power Law Discovery

This entry is part 11 of 17 in the series Numpy Strategies

Numpy Strategies 0.1.4

Our Product Owner (disclaimer fictional character) has come back from a long vacation. During his holiday he found some time to google “get rich quick schemes”. This led to a new thrilling User Story.

User Story

  • I want to Discover a Power Law in the closing Stock Prices Log Returns

Business Value

The Business Value of this User Story comes from the fact that our Hedge Fund operates a long term trading strategy. We don’t want to trade too often, because of involved costs. Let’s say that we would prefer to buy and sell once a month based on a significant correction. The issue is to determine an appropriate signal given that we want to initiate a transaction every 1 out of about 20 days. Approximately 5% probability with other words.

1. Get close prices

First, let’s get historical end-of-day data for the past year from Yahoo Finance. After that extract the close prices for this period.

1
2
3
4
5
today = date.today()
start = (today.year - 1, today.month, today.day)
 
quotes = quotes_historical_yahoo(sys.argv[1], start, today)
close =  numpy.array([q[4] for q in quotes])

2. Get positive log returns

Now calculate the log returns for the close prices. First, we will take the log of the close prices and then compute the first difference of this values with the NumPy diff function. From the log returns let’s select the positive values.

1
2
logreturns = numpy.diff(numpy.log(close))
pos = logreturns[logreturns > 0]

3. Get frequencies of returns

We need to get the frequencies of the returns with the histogram function. Counts and an array of the bins is returned. At the end we need to take the log of the frequencies in order to get a nice linear relation.

1
2
3
4
counts, rets = numpy.histogram(pos)
rets = rets[:-1] + (rets[1] - rets[0])/2
freqs = 1.0/counts
freqs =  numpy.log(freqs)

4. Fit the frequencies and returns to a line

Use the polyfit function to do a linear fit.

1
p = numpy.polyfit(rets,freqs, 1)

5. Plot the results

Finally we will plot the data and linear fit with Matplotlib.

1
2
3
matplotlib.pyplot.plot(rets, freqs, 'o')
matplotlib.pyplot.plot(rets, p[0] * rets + p[1])
matplotlib.pyplot.show()

Here is the code in its entirety with imports and all.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from matplotlib.finance import quotes_historical_yahoo
from datetime import date
import numpy
import sys
import matplotlib.pyplot
 
#1. Get close prices.
today = date.today()
start = (today.year - 1, today.month, today.day)
 
quotes = quotes_historical_yahoo(sys.argv[1], start, today)
close =  numpy.array([q[4] for q in quotes])
 
#2. Get positive log returns.
logreturns = numpy.diff(numpy.log(close))
pos = logreturns[logreturns > 0]
 
#3. Get frequencies of returns.
counts, rets = numpy.histogram(pos)
rets = rets[:-1] + (rets[1] - rets[0])/2
freqs = 1.0/counts
freqs =  numpy.log(freqs)
 
#4. Fit the frequencies and returns to a line.
p = numpy.polyfit(rets,freqs, 1)
 
#5. Plot the results.
matplotlib.pyplot.plot(rets, freqs, 'o')
matplotlib.pyplot.plot(rets, p[0] * rets + p[1])
matplotlib.pyplot.show()

This is the resulting plot for AAPL (disclaimer I own AAPL shares). Another disclaimer – use this information at your own risk. I am not responsible for any losses. Please listen to your risk managers.

Power law

What Just Happened?

We discovered a power law in the positive log returns of stock prices. Now it should be trivial to determine our correction criteria.

Have a Go

There are some things worth investigating left:

  • Have a look at the negative log returns.
  • Try out different stocks.
  • Look at different timeframes for instance intraday data.


If you liked this post and are interested in NumPy check out NumPy Beginner’s Guide by yours truly.

Share
Posted in programming | Tagged , , , | Leave a comment

NumPy Project Euler Problem 7

This entry is part 7 of 9 in the series NumPy Project Euler

Project Euler Problem 7 is about prime numbers. So I implemented a Sieve of Eratosthenes with NumPy. I am not following the algorithm to the letter, but I believe that the result is the same.

1. Create a list of consecutive integers

The first mandatory step is to create a list of natural numbers. NumPy has the arange function for that.

1
   a = numpy.arange(i, i + LIM, 2)

2. Sieve out multiples of p

Not sure whether this is what Eratosthenes wanted us to do, but it works. Below we are passing a NumPy array and getting rid of all the elements that have a 0 remainder, when divided by p.

1
   a = a[a % p != 0]

Below is the entire code for this problem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import numpy
 
LIM = 10 ** 6
N = 10 ** 9
P = 10001
primes = []
p = 2
 
#By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
 
#What is the 10 001st prime number?
 
def check_primes(a, p):
   #2. Sieve out multiples of p
   a = a[a % p != 0]
 
   return a
 
for i in xrange(3, N, LIM):
   #1. Create a list of consecutive integers
   a = numpy.arange(i, i + LIM, 2)
 
   while len(primes) < P:
      a = check_primes(a, p)
      primes.append(p)
 
      p = a[0]
 
print len(primes), primes[P-1]


If you liked this post and are interested in NumPy check out NumPy Beginner’s Guide by yours truly.

Share
Posted in programming | Tagged , , , | Leave a comment

Misbehavior of Markets Book Review

In these turbulent economy we seem to be victims of the financial markets. Benoit Mandelbrot, famous mathematician and inventor of fractal geometry, joined forces with Richard Hudson, to write a book about financial theory. “The (Mis)behavior of Markets” falls in the popular science genre. It is low on formulas, instead you can find lots of historical anecdotes and opinions.

Misbehaviour Markets
Authors Benoit Mandelbrot and Richard L. Hudson
ISBN-10 0465043577

1. Risk, Ruin and Reward

We start with a brief history of finance. The author asks us to play a game. Out of 4 charts we need to select the ones that are real and the ones that are fake.

2. By the Toss of a Coin or the Flight of an Arrow?

Chance is important in finance. There is the mild form of chance, described by the bell curve. On the other hand, there is the more extreme Cauchy probability distribution. Financial theory follows the mild path, but Mandelbrot is convinced that this is wrong and a more wild variability is to be expected.

3. Bachelier and His Legacy

The third chapter is about Bachelier and his coin-tossing view of finance. His work led to the theory of the efficient market. According to this theory, the market is so efficient that all information is directly reflected in the price of financial assets.

4. The House of Modern Finance

People who helped build the house of modern finance and their theories are mentioned – Markowitz, Sharpe, Black and Scholes. Even though some received Nobel Prizes, they still lost a lot of money in the markets.

5. The Case Against the Modern Theory of Finance

Mandelbrot tries to demolish the house of modern finance starting with shaky assumptions. He tries to disprove these assumptions. More evidence is presented, such as the low price earnings and price book anomalies. These anomalies are in direct conflict with current theory.

6. Turbulent Markets: A Preview

Turbulence is a nice metaphor for trading. Mandelbrot tries to convince us, that we should be thinking of fractals, when we look at stock charts. He uses cartoons of stock charts to achieve that.

7. Studies in Roughness: A Fractal Primer

Fractal geometry deals with roughness. It introduces a measure called fractal dimension, which is similar to the normal dimension in geometry, but is not an integer.

8. The Mystery of Cotton

This chapter describes a research project of Mandelbrot, when he worked at an IBM laboratory. He discovered a power law in the log returns of cotton prices. The evidence pointed at a L-stable probability distribution with features somewhere between a normal and Cauchy distribution.

9. Long Memory, from the Nile to the Marketplace

Hurst, a famous hydrologist, faced the challenge of figuring out a pattern to the Nile river. Hurst discovered a long term dependence in his data set. It is suggested, that the so called Hurst exponent could be a new yardstick, that would explain better long memory effects in financial markets.

10. Noah, Joseph, and Market Bubbles

The author refers to characters in the Bible to describe different forms of wild variability. For people familiar with the Bible this is a good example. In my opinion we can call it a shaky assumption at best.

11. The Multifractal Nature of Trading Time

Some days are slow, some days just fly by. Apparently this applies to trading too and it is due to the multifractal nature of time.

12. Ten Heresies of Finance

A list of ten big errors in financial theory. Markets are riskier, than we thought. Timing matters. Prices often leap.

13. In the Lab

Mandelbrot warns us that fractal finance is not mature yet. However, it is superior to the mainstream theories, since they dangerously underestimate risk.

The book ends with notes containing formulas and bibliography listing scientific articles. A thrilling book, that I could not put down, until I read it cover to cover. It is the finance equivalent of “A Brief History of Time”. I give it 5 stars out of 5.

Share
Posted in books | Leave a comment

NumPy Project Euler Problem 6

This entry is part 6 of 9 in the series NumPy Project Euler

Project Euler Problem 6 is perfect to demonstrate the power of NumPy. No loops are required and only a few lines of code.

1. Create an array with the first 100 natural numbers

First we will create a NumPy array of the numbers 1 – 100 with the arange function.

a = numpy.arange(101)

2. Sum the squares of the numbers

Second we will sum the squares of the numbers with the sum function.

sum_squares = numpy.sum(a ** 2)

3. Square the sum of the numbers

The NumPy ndarray class has a sum method, that we can use to sum the numbers in our array. After that calculate the square of the sum.

square_sum = a.sum() ** 2

Below is the complete solution.

import numpy
 
#The sum of the squares of the first ten natural numbers is,
#1 ** 2 + 2 ** 2 + ... + 10 ** 2 = 385
 
#The square of the sum of the first ten natural numbers is,
#(1 + 2 + ... + 10) ** 2 = 55 ** 2 = 3025
 
#Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 - 385 = 2640.
 
#Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
 
# 1. Create an array with the first 100 natural numbers
a = numpy.arange(101)
 
# 2. Sum the squares of the numbers
sum_squares = numpy.sum(a ** 2) 
 
# 3. Square the sum of the numbers
square_sum = a.sum() ** 2
 
# Calculate the difference
print square_sum - sum_squares

 

If you liked this post and are interested in NumPy check out NumPy Beginner’s Guide by yours truly.

Share
Posted in programming | Tagged , , , | Leave a comment

Linear Algebra Book review

I had to read “Linear Algebra and Its Applications” by David Lay for the Linear Algebra 1 class in my first semester in University. So this is a gentle introduction to Linear Algebra. The book doesn’t assume a lot of previous knowledge.

Linear Algebra Book
Author David C. Lay
ISBN-10 0201845563

Chapter Structure

Each chapter starts with an introductory example. Each section within a chapter ends with practice problems and exercises. Worked out examples with solutions are given too. As you would expect from a Linear Algebra book, there are lots of theorems and numerical notes.

1. Systems of Linear Equations

The first chapter gives some examples of linear systems. The row reduction algorithm is explained. I remember having to solve these kind of problems by hand for weeks. As is usual in mathematics, we learn to work out something with paper and pencil the hard way and then we figure out how to do it faster by writing a computer program. If you are into Python, please check out NumPy.

2. Vector and Matrix Equations

Chapter 2 starts with a number of examples as well. We learn about the fundamental idea of representing a linear combination of vectors as a product of a matrix and a vector. This leads to this famous equation:

A x = b

3. Matrix Algebra

Chapter 3 teaches about matrix operations such as matrix multiplication, matrix inversion and transposing matrices. The chapter ends with the Leontief Input Output Model from economics and applications to computer graphics.

4. Determinants

The introductory example in this chapter is about determinants in analytic geometry. Properties of determinants are mentioned as well as calculation methods.

5. Vector Spaces

I don’t know if it has anything to do with the chapter title, but the first example of this chapter is about space flight and control systems. In my opinion this chapter is more theoretical than the preceding chapters. The chapter ends with applications to difference equations and Markov Chains.

6. Eigenvalues and Eigenvectors

Dynamical systems and spotted owls are the topic of the introductory example of chapter 6. This chapter covers amongst others the characteristic equation, diagonalization and iterative algorithms to estimate eigenvalues.

7. Orthogonality and Least Squares

Chapter 7 begins with a short text about the North American Datum. After that we continue with sections on:

  • orthogonality
  • orthogonal sets
  • orthogonal projections
  • the Gram-Schmidt process
  • least square problems
  • inner product spaces

8. Symmetric Matrices and Quadratic Forms

A story about multi channel image processing is the introduction of chapter 8. This chapter has sections on quadratic forms and singular value decomposition.


The book is very readable and entertaining. The diverse list of examples are already reason enough to recommend “Linear Algebra and Its Applications”. I give this book 5 stars out of 5.

Share
Posted in books | Leave a comment