Showing posts with label Mathematics. Show all posts
Showing posts with label Mathematics. Show all posts

Friday, November 27, 2009

How many bottle caps?

I ran across the following problem and couldn't resist. The original inspiration was a Mountain Dew promotion.

Consider the following game: Suppose you have N bottle caps, each with the name of a different sports team on the underside. You win if you draw (with replacement) three of the same team. Note that a win is impossible for less than three draws and is guaranteed by the 2N+1 draw. For n draws, the probability of having some particular set of caps (x_1, \dots, x_N), \sum_i^N x_i = n, follows a Multinomial distribution:

p(x_1, \dots, x_N) = \frac{n!}{x_1!x_2!\cdots x_N!}\left(\frac{1}{N}\right)^n

The probability of not winning by the n'th draw is the sum of all the probabilities with x_i = 0, 1, 2, i = 1, \dots, N$, and sum_i^N x_i = n. Now, permutations of the vector (x_1, \dots, x_N) are equally likely, and the number of possible non-winning vectors that have k = \max\{ n-N, 0\}, \dots, n/2 teams with two drawn caps is

{N \choose{n-k}} {{n-k}\choose{k}} = \frac{N!}{k! (n-2k)! (N-n+k)!}

Then, the probability of not winning by the n'th draw, given that there are k teams with two caps, is

p(n|k) = {N\choose{n-k}} {{n-k}\choose{k}} \frac{n!}{2^k} \left(\frac{1}{N}\right)^n

Thus, the probability of winning on the (n+1)'th draw is

p_{\rm win}(n) = \sum_{k = \max\{n-N, 0\}}^{n/2} p(n|k)\frac{k}{N}

If there are 30 teams, the chance of winning on the third draw is 0.1%. It takes about 18 draws to have a 50% chance of winning, 27 draws to have a 90% chance of winning, and 38 draws to have a 99.9% chance of winning.

Monday, September 01, 2008

Graduated Annuity Calculator

I use Google Analytics to keep track of visits to the Cogitorium as a matter of curiosity. When I posted the results of my graduated annuity calculations, I figured most people would respond as my brother did: "Why would you write about something boring like that?" Much to my very great surprise, my entry on the graduated annuity has turned out to be my most popular! Since the beginning of this year, the entry has received nearly one hit per day (which is a lot by my humble standards).

Given the interest in graduated annuities, I thought I would whip up a quick applet to perform calculations with the graduated annuity, since many people might not want to slog through the math on their own. Below are a few usage notes, the applet, and several calculation examples. For those who are interested, the source code is available, and is released into the public domain.

  1. The Interest Rate and the Acceleration Rate are entered in percent and cannot be the same.
  2. When calculating the Final value, enter a positive Base Value for savings or a negative Base Value (with an Initial Value) for accelerated withdrawals.
  3. When calculating either rate, no Initial Value is permitted.
  4. Selecting Years calculates the amount of time a given Initial Value will last with accelerated withdrawals. It doesn't work with Final Values other than 0, or with positive Base Deposits.
  5. Enter 0 for the Acceleration Rate to calculate a normal annuity.




Examples:
  1. To calculate the savings of $1000/year (unaccelerated) for 10 years at 5% interest, enter 0 for the Initial Value, 1000 for the Base Deposit, 5 for the Interest Rate, 0 for the Acceleration Rate, and 10 for Years. Pressing calculate gives $12,577.89.
  2. Suppose we choose to accelerate the savings in the previous example by 4% each year. Enter 4 for the Acceleration Rate. Pressing calculate shows the savings grow to $14,865.03.
  3. Suppose we have $10,000 and would like to reach $100,000 in 5 years. How much would need to be saved each year, if we expect an 8% return on the savings? Select the Base Deposit radio button, enter 10000 for the Initial Value, 100000 for the Final Value, 8 for the Interest Rate, 0 for the Acceleration Rate, and 5 for Years. Pressing calculate gives $14,541.08.
  4. Suppose we want to reach $100,000 in 10 years. If we start with a $6,000/yr deposit, how fast would the deposits have to accelerate to reach our goal, if we expect an 8% return on the savings? Select the Acceleration Rate radio button, enter 0 for Initial Value, 100000 for Final Value, 6000 for Base Deposit, and 10 for Years. Pressing calculate shows that the deposit amount must increase by 3.6% each year to reach the goal.
  5. Suppose we have $500,000 saved for retirement, earning 5% per year. We plan on withdrawing $30,000/yr and would like to increase this amount by 2% each year to account for cost of living increases (price inflation). How much will be left after 10 years? Select the Final Value radio button, and enter 500000 for Initial Value, -30000 for Base Desposit, 5 for Interest Rate, 2 for Acceleration Rate, and 10 for Years. Pressing calculate shows that $404,547.11 will remain.
  6. How long will the savings in this scenario last? Select the Years radio button. Pressing calculate shows that the savings will last almost 24 years.

Thursday, August 30, 2007

Calculating a Graduated Annuity

(Use the calculator to skip the math below.)

Calculating the future value of a savings program with fixed savings installments and a fixed interest rate (a simple annuity) is fairly straightforward with a geometric series:


T_1 = p ; T_2 = pr + p ; T_3 = pr^2 + pr + p ; T_n = pr^{n-1} + pr^{n-2} + pr^{n-3} + \dots + pr^2 + pr + p

To calculate the value after n periods, we multiply the last equation by r and subtract the result:

rT_n = pr^n + pr^{n-1} + pr^{n-2} + \dots + pr^3 + pr^2 + pr ; (r-1)T_n = pr^n - p ; T_n = p{r^n-1\over r-1}

So, saving $1,000/year for 10 years at 5% interest would give:

T_{10} = \$1,000{1.05^{10}-1\over 1.05-1} = \$12,577.89

And if we had the goal of saving $100,000 over 30 years with a 8%
interest rate, we could calculate the yearly deposit required:

p = T_n{r-1\over r^n-1} = \$100,000{1.08-1\over 1.08^{30}-1} = \$882.74


Now, since the real value of the periodic deposit degrades over time due to inflation, and since one's ability to save will hopefully increase over time due to increased income through cost-of-living increases and promotions, a real-life long-term savings plan will likely include deposits that increase over time (a graduated annuity). These, too, can be represented with a series:

T_1 = p ; T_2 = pr + pa ; T_3 & = pr^2 + par + pa^2 ; T_4 = pr^3 + par^2 + pa^2r + pa^3 ; T_n & = pr^{n-1} + par^{n-2} + pa^2r^{n-3} + \dots + pa^{n-3}r^2 + pa^{n-2}r + pa^{n-1}

where a is the geometric ratio describing the rate of increase (the graduation) of the deposits. This series is similar in form to the binomial series, except that the coefficients in this series are all the same. To solve for the sum, we multiply by a/r and subtract:

{a\over r}T_n = par^{n-2} + pa^2r^{n-2} + \dots + pa^{n-1} + p{a^n\over r} ; (1-{a\over r})T_n = p(r^{n-1} - {a^n\over r}) ; {r-a\over r}T_n = p{r^n-a^n\over r} ; T_n = p{r^n - a^n \over r-a}

Notice how this simplifies to the result for constant deposits, when a=1.

This equation can be rearranged to the elegant form:

{T_n\over p}r - r^n = {T_n\over p}a - a^n, r \ne a

When asked to solve for either rate, Mathematica complained that this equation involves variables in "an essentially non-algebraic way," which I found a bit odd. Nevertheless, to determine the interest rate necessary to achieve a given sum with a set rate of deposit graduation (or vice versa), one can evaluate one side of the equation, move the resulting constant to the other side, and calculate the positive real roots of the n-th degree polynomial.

In any case, after 10 years, a savings program that begins at $1,000/year
and increases by 4% each year with 8% interest would give:

T_{10} =  \$1,000{1.08^{10}-1.04^{10}\over 1.08-1.04} = \$16,967.02


This equation is also useful for determining savings left after a series of increasing withdraws. If one starts with $500,000 in retirement savings invested at 5%, taking a 2% inflation-adjusted $30,000 annuity for 5 years would leave:

T_n = Ar^n - p{r^n - a^n \over r-a} = \$500,000\cdot1.05^5 - \$30,000{1.05^5-1.02^5\over1.05-1.02} = \$465,940.02


One can rearrange the formula to achieve a somewhat unwieldy but functional equation for the number of years before the retirement savings will run out:

0 = Ar^n-p{r^n-a^n\over r-a} ; {A(r-a)\over p}r^n = r^n - a^n ; a^n = [1-{A(r-a)\over p}]r^n ; n\log a = n\log r + \log[1-{A(r-a)\over p}] ; n(\log a - \log r) = \log[1-{A(r-a)\over p}] ; n = \log[1-{A(r-a)\over p}] \div \log {a\over r}

So, to find out how long the $500,000 investment from the previous example will last:

n = \log[1-{\$500,000(1.05-1.02)\over\$30,000}] \div \log{1.02\over1.05} = 23.9 years


All of these calculations assume that payments occur at the end of the year (an ordinary annuity). The calculations for payments at the beginning of the year (an annuity due) are equally straightforward, and yield:

T_n = pr{r^n-a^n\over r-a}