# Android AER Calculator

This post is about an Android application I wrote to calculate the Annual Equivalent Rate (AER) of a portfolio.

The AER of a portfolio is the annualised interest rate that, when applied to the portfolio contributions, results in the current value of the portfolio.

## Simple example

If I invested £100 exactly one year ago and the value now is £105, the AER would be 5%.

This is because £100 x (1 + 5%) = £105.

## Not so simple Example

However, things get significantly more complicated when there are multiple contributions on different dates.

What is the AER of a portfolio with contributions of £100 one year ago, £50 ten months ago that is worth £160 today?

It turns out to be approximately 7.04%. This is a typical example that is simply stated but has a not-so-obvious solution.

## The Algorithm

To compute the AER, I used a numerical method called the NewtonRaphson method.

The method starts with an initial guess to the root of a function. From here, we follow the derivative of the function in order to converge on the true root of the function.

In this case, the function we are interested in is: $f(r) = \sum_i C_i (r + 1)^{\frac{D_i - D_t}{365}} - P$

Where $C_i$ is the ith contribution, $D_i$ is the ith day, $D_t$ is the current day and $P$ is the present value of the portfolio.

The derivative is: $f'(r) = \sum_i C_i \left[ \frac{D_i - D_t}{365} \right] (r + 1)^{\left[ \frac{D_i - D_t}{365} - 1\right] }$

The algorithm starts with an initial estimate $r_0$ and obtains a better approximation $r_1$ by using the relation: $\displaystyle r_1 = r_0 - \frac{f(r_0)}{f'(r_0)}$

This process is repeated until the difference between successive estimates is less than some threshold value or the number of iterations hits some predefined limit.

## AER Calculator

This led me to write the Android application AER Calculator, which can be found on the Google Play Store.  The (open source!) project can be found on GitHub.