Skip to content

Instantly share code, notes, and snippets.

@chris-belcher
Last active March 26, 2016 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-belcher/647da261ce718fc8ca10 to your computer and use it in GitHub Desktop.
Save chris-belcher/647da261ce718fc8ca10 to your computer and use it in GitHub Desktop.
calculating-equivalent-interest-rate
JoinMarket yield generators earn money on an unpredictable basis. It's worth calculating
the equivalent interest rate as if joinmarket was a savings account.
We can make a model of a bank account that takes deposits and withdrawals at any time and
where the balance accumulates interest, then the parameters from a JoinMarket yield-generator
wallet can be inputted to obtain the equivalent interest rate.
We know that the present value of a bank account (P) grows to the future value (F) determined
by the interest rate per unit time (r) and time (t)
https://en.wikipedia.org/wiki/Compound_interest#Mathematics_of_interest_rates
F = P exp(rt)
Say there is a sequence of deposit values D_n = [D0, D1, D2, D3, ... DN] where withdrawals are negative
valued deposits. The deposit times happen at t_n = [t0, t1, t2, t3, ... tN]. The bank account offers
rate r. The current time is tN+1 and the current bank balance is B. Without loss of generality we can set t0 = 0
The balance of the bank account grows by deposits and by interest.
This is example stops at time t3.
D0 ----> D0 exp(r t1) ----> D0 exp(r t1) + D1 ----> (D0 exp(r t1) + D1) exp(r(t2 - t1))
----> (D0 exp(r t1) + D1) exp(r(t2 - t1)) + D2 ----> ((D0 exp(r t1) + D1) exp(r(t2 - t1)) + D2) exp(r(t3 - t2))
This final balance is equal to the current balance B. Expand the brackets and rearrange
B = ((D0 exp(r t1) + D1) exp(r(t2 - t1)) + D2) exp(r(t3 - t2))
= (D0 exp(r t1) + D1) exp(r(t2 - t1))exp(r(t3 - t2)) + D2 exp(r(t3 - t2))
= D0 exp(r t1)exp(r(t2 - t1))exp(r(t3 - t2)) + D1 exp(r(t2 - t1))exp(r(t3 - t2)) + D2 exp(r(t3 - t2))
= D0 exp(r t3) + D1 exp(r(t3 - t1) + D2 exp(r(t3 - t2))
= exp(r t3) (D0 exp(-r t0) + D1 exp(-r t1) + D2 exp(-r t2))
That expression is equivalent to all the deposits growing by exp(r t3) but the later deposits being discounted
as if they were borrowed. The expression can be easily generalized to:
B = exp(r tN+1) sum(D_n exp(-r t_n)) = sum( D_n exp(r(tN+1 - t_n)) )
Now using this formula we can find a numerical solution for r by find the root of
f(r) = sum( D_n exp(r(tN+1 - t_n)) ) - B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment