In this thread, I'll help you understand Generating Functions.
They're a super cool math technique you can use to predict the behavior of various financial models. Using just pencil and paper. No Excel!
2/
Imagine we have a portfolio that returns 10% per year.
And we save $50K per year -- which we add to this portfolio.
So, each year, the portfolio grows 10% via compounding, plus $50K of new money pours in.
Starting at $0, what will our portfolio be worth after 30 years?
3/
Many models in finance and investing follow a pattern like this.
They connect the previous year to the next year using a simple formula.
For our example, the formula is: compound the previous year's portfolio by 10% and add $50K => that gives us the next year's portfolio.
4/
We can model this using a Recurrence Equation.
Let W(N) be the portfolio's value after N years.
Then, the Recurrence Equation lets us calculate W(N) from W(N - 1).
Like so:
5/
Generating Functions are a powerful way to solve such Recurrence Equations.
And such Recurrence Equations are at the heart of all kinds of financial models.
So, Generating Functions are a super useful trick to keep in our toolbox.
6/
This is a 3-part trick.
Part 1: Define a "polynomial series" f(x) whose coefficients are the things we want to calculate.
For example, we want to calculate W(N) -- our portfolio's value after N years.
So, we'll let W(0), W(1), W(2), ... be our coefficients.
Like so:
7/
This f(x) is our "Generating Function".
Part 2: Apply the Recurrence Equation to the Generating Function, and simplify until a formula for f(x) emerges.
Brace yourself, this is going to get mathy!
8/
So, after all that math, we end up with a formula for our Generating Function f(x).
Now for the final part.
Part 3: Write the f(x) formula as a new polynomial series. The coefficients of this series are of course the very things we originally set out to calculate!
9/
Our final W(k) equation above tells us *exactly* what our portfolio will be worth after 30 -- or any other number of -- years.
It's about $8.2M after 30 years.
See? Just paper and pencil.
OK, a calculator too.
But no simulation. No Excel. No Python. Just math.
10/
Another example: What's the monthly payment on a $500K 30-year 3% fixed rate mortgage?
Here's the Generating Function solution:
11/
This tells us that our monthly mortgage payment will be ~$2,108.02.
With the help of Generating Functions, we worked it out using just paper and pencil.
And hey! Google's mortgage calculator agrees with us:
12/
Let's do a third example!
Many investors use "cohort analysis" to model the unit economics of businesses. For example, Life Time Value (LTV) vs Customer Acquisition Cost (CAC) trade-offs.
Generating Functions can give us useful insights into such models.
13/
For example, suppose it costs a company $100 to acquire a customer.
That is, CAC is $100 per customer.
And once a customer signs up, the company makes $50 off them in their first year and $75 off them in all future years.
14/
Also, churn among first year customers is high. Only 50% of them continue into Year 2.
But from Year 2 onwards, customer retention rates are high -- say, 90%.
That is, 90% of Year 2 customers sign up for Year 3, 90% of Year 3 customers sign up for Year 4, etc.
15/
Suppose the company starts with $100K of capital -- all of which is used to acquire customers.
And suppose the company re-invests all its earnings each year to acquire even more customers.
How will the number of customers scale over time?
16/
This is basic cohort analysis.
We have 2 customer cohorts: "Year 1" and "Year 2+". They have different income and churn characteristics.
17/
Cohort analysis of this sort can be boiled down to a Recurrence Equation.
The more cohorts we have, the more terms in the equation.
For example, we have 2 cohorts. So, our equation connects the current year to 2 previous years.
Like a Fibonacci series:
18/
As usual, we use Generating Functions to solve our cohort Recurrence Equation.
This gives us exact formulas for the number of customers in each cohort, the income from them, etc., over time.
Surprisingly, the square root of 166 plays a big role!
19/
The Generating Function also gives us key insights into the long run behavior of our cohorts.
For example, the 1.3442^(k-1) tells us that the number of customers in each cohort, the income from them, etc., will compound at ~34.42%. The 0.0558^(k-1) will quickly die down.
20/
So, that's the crux of our Generating Function method.
We, a) define a Generating Function, b) apply our Recurrence Equation to it, and c) write the result as a new series whose coefficients solve the problem we're interested in.
21/
And the beauty is that the same procedure solves a wide variety of Recurrence Equations.
This gives the method broad applicability in finance and investing -- with uses ranging from calculating mortgages to analyzing cohorts.
22/
To learn more, I recommend the book Generatingfunctionology by Herbert Wilf.
The first sentence of this book: A Generating Function is a clothesline on which we hang up a sequence of numbers for display.