Financial Algorithms Cookbook | Time Value of Money
Cash Flow Algorithms
Cash flow analysis is an extension of the basic TVM concepts applied to compound interest problems when payments occur in regular periods and do not have the same value. Any financial investment can be represented as an initial investment of money and a series of cash flows that occur in regular periods of time. Each flow of money can be positive (received) or negative (paid out) and considered as a cash flow. Common cash flow problems usually involve the calculation of the Internal Rate of Return (IRR) or the Net Present Value (NPV).
Internal Rate of Return Of a Series of Cashflows
Internal Rate of Return is the discount rate that if applied to all future cash flows causes NPV = 0.
The algoithm uses Newton-Raphsons method for solving equations. It needs to take an estimate of the answer. Of course you could implement this algorithm with a sensible built in value.
def IRR(estimate, cashFlows):
def irr_f(estimate, cashFlows):
t=0
irr=0.0
discountFactor = 1.0
irr_i = estimate+1
for Ct in cashFlows[1:]:
irr += Ct *(1.0/discountFactor)
discountFactor *= irr_i
irr *= (1-(1/irr_i))/estimate
irr += cashFlows[0]
return irr
return newton_raphson(irr_f, estimate, cashFlows)
Example
You want to invest in development project that will return over 15%. You find a building that will cost 3.7 million, and will take will a year to to convert into appartments costing 12m. You would like to rent it for four years before selling it at 9.2 million. What is this investments Internal Rate of Return ?
| C0 | C1 | C2 | C3 | C4 | C5 | C6 |
| Purchase | Refurbish costs | Net Rent | Net Rent | Net Rent | Net Rent | Sold |
| 3.7m | 1.2 | 300k | 315k | 330K | 347k | 9.2 |
cashflows = [-3700000,-1200000,300000,315000,330000,347000,9200000] estimate = 10 IRR(estimate, cashflows ) >>15.13
References
- Gallager, T; Andrew Jr., J., Financial Management: Principals and Practices, Upper Saddle River, NJ: Prentice Hall, 1996
- HP-12C Business Calculator Owner's Manual, Hewlett Packard, 1984
- HP-10B Business Calculator Owner's Manual, Hewlett Packard, 1994
