*This 22nd article in the series on mathematics through open source takes the reader into personal financial management. The author demonstrates how personal financial computations can be done easily by using Maxima.*

In todays credit-oriented world, loans, EMIs, the principal, interest rates, savings, etc, are commonly used terms. How well do we really understand these terms, or for that matter, are we able to accurately compute the figures related to such matters? Do we just accept what the other party has provided us? Or should one go into the details to first understand and then double-check the numbers being presented to us? This is where Maximas finance package comes to your rescue; you can actually verify figures without much involvement in the computational details. This article is going to walk you through the details of this package.

**Basic operations**

To be able to use the finance package of Maxima, the first thing to do, after getting the Maxima prompt, is to load the finance package, using *load()*. Then go ahead to do the various computations. *days360()* is the simplest function to give the number of days between two dates, assuming there are 360 days per year and 30 days per month this is the norm when calculating interest rates.

$ maxima -q (%i1) load(finance); (%o1) /usr/share/maxima/5.24.0/share/contrib/finance/finance.mac (%i2) days360(2014, 1, 1, 2014, 10, 1); (%o2) 270 (%i3) days360(2014, 1, 1, 2014, 12, 31); (%o3) 360 (%i4) days360(2014, 1, 1, 2014, 3, 1); (%o4) 60 (%i5) days360(2014, 1, 1, 2015, 1, 1); (%o5) 360 (%i6) quit();

Note that *days360()* takes from and to dates, each as a triplet of the year, month and date.

One common computation that we often deal with is the final amount we would get after applying a particular rate of compound interest on a particular principal amount just use* fv(<rate>, <principal>, <period>)* for computing the future value of the* <principal>,* at the compound interest *<rate>* , after a certain* <period>.* As an example, what would be the future value of investing `10,000 for 10 years at the compound interest rate of 15 per cent per year just call fv(0.15, 10000, 10);

$ maxima -q (%i1) load(finance)$ /* $ to suppress its output */ (%i2) fv(0.15, 10000, 10); (%o2) 40455.57735707907

If you are interested in how exactly this is calculated, or what the formula is, Maxima is fun to play around with. Just use some symbols, instead of actual numbers:

(%i3) string(fv(r, p, n)); (%o3) p*(r+1)^n (%i4) quit();

And, there you go.* p*(r+1)^n* is the future value when investing p amount for n periods at the compounded interest rate of r per period.

How about doing an inverse computation? Lets suppose, I want to get `1,000,000 after five years from my investment today at the interest rate of 10.75 per cent. Now, for that, how much should I invest today? Dont scratch your head, just call *pv(<rate>, <future_val>, <period>);*

(%i1) load(finance)$ (%i2) pv(0.1075, 1000000, 5); (%o2) 600179.7323625274 (%i3) fv(0.1075, 600180, 5); (%o3) 1000000.445928875 (%i4) quit()

;

So you need to invest `600,180 to get a value of `1,000,000 after five years at a rate of interest of 10.75 per cent thats the check done above, using *fv()*.

**Loans and EMIs**

Today, with access to easy credit, people plan on buying a house, a car, or even smaller items, with the thought, Lets buy it on loan and pay it off in EMIs (equated monthly instalments). These terms would be familiar to most of you but how do you compute them? One assumes that there are some complicated formulae to do so, which is right. But, you dont need to worry about any of them. Just instruct Maxima to give you the complete schedule for your loan, at a given rate of interest, for a given period of time, using *amortization()*. The first example below provides the schedule for a home loan of `2 million at an interest rate of 9.25 per cent per annum (p.a.) for five years. The various columns in the output schedule provide the following information:

- n: instalment payment time year, in the case of our example
- Balance: principal + interest left over to be paid out, after the current instalment is paid out
- Interest: interest part being paid out in the current instalment
- Amortization: principal part being paid out in the current instalment
- Payment: current instalment to be paid out, i.e., the EYI (equated yearly instalment)

What is this EYI? We were supposed to talk only about EMI, right? Okay, in that case, we need to convert the rate of interest and the period, in terms of months. So, we need to divide the per annum rate of interest by 12 to get what it amounts to per month, and multiply the number of years by 12 to get that in the number of months. That is exactly what the second example below shows. Note that it is 60 EMIs to be paid out over the period of five years.

$ maxima -q (%i1) load(finance)$ (%i2) amortization(0.0925, 2000000, 5)$ n Balance Interest Amortization Payment 0.000 2000000.000 0.000 0.000 0.000 1.000 1667475.420 185000.000 332524.580 517524.580 2.000 1304192.317 154241.476 363283.103 517524.580 3.000 907305.527 120637.789 396886.790 517524.580 4.000 473706.709 83925.761 433598.818 517524.580 5.000 0.000 43817.871 473706.709 517524.580 (%i3) amortization(0.0925/12, 2000000, 5*12)$ n Balance Interest Amortization Payment 0.000 2000000.000 0.000 0.000 0.000 1.000 1973656.870 15416.667 26343.130 41759.797 2.000 1947110.679 15213.605 26546.192 41759.797 3.000 1920359.860 15008.978 26750.818 41759.797 4.000 1893402.837 14802.774 26957.023 41759.797 5.000 1866238.021 14594.980 27164.816 41759.797 6.000 1838863.809 14385.585 27374.212 41759.797 7.000 1811278.588 14174.575 27585.221 41759.797 8.000 1783480.730 13961.939 27797.857 41759.797 9.000 1755468.598 13747.664 28012.133 41759.797 10.000 1727240.538 13531.737 28228.059 41759.797 11.000 1698794.887 13314.146 28445.651 41759.797 12.000 1670129.968 13094.877 28664.919 41759.797 13.000 1641244.090 12873.919 28885.878 41759.797 14.000 1612135.550 12651.257 29108.540 41759.797 15.000 1582802.632 12426.878 29332.918 41759.797 16.000 1553243.605 12200.770 29559.026 41759.797 17.000 1523456.728 11972.919 29786.877 41759.797 18.000 1493440.244 11743.312 30016.484 41759.797 19.000 1463192.382 11511.935 30247.861 41759.797 20.000 1432711.360 11278.775 30481.022 41759.797 21.000 1401995.381 11043.817 30715.980 41759.797 22.000 1371042.632 10807.048 30952.749 41759.797 23.000 1339851.289 10568.454 31191.343 41759.797 24.000 1308419.513 10328.020 31431.776 41759.797 25.000 1276745.450 10085.734 31674.063 41759.797 26.000 1244827.233 9841.580 31918.217 41759.797 27.000 1212662.979 9595.543 32164.253 41759.797 28.000 1180250.793 9347.610 32412.186 41759.797 29.000 1147588.763 9097.767 32662.030 41759.797 30.000 1114674.963 8845.997 32913.800 41759.797 31.000 1081507.453 8592.286 33167.510 41759.797 32.000 1048084.276 8336.620 33423.177 41759.797 33.000 1014403.463 8078.983 33680.814 41759.797 34.000 980463.026 7819.360 33940.437 41759.797 35.000 946260.965 7557.736 34202.061 41759.797 36.000 911795.264 7294.095 34465.702 41759.797 37.000 877063.889 7028.422 34731.375 41759.797 38.000 842064.793 6760.701 34999.096 41759.797 39.000 806795.913 6490.916 35268.880 41759.797 40.000 771255.168 6219.052 35540.745 41759.797 41.000 735440.463 5945.092 35814.705 41759.797 42.000 699349.687 5669.020 36090.776 41759.797 43.000 662980.711 5390.821 36368.976 41759.797 44.000 626331.390 5110.476 36649.320 41759.797 45.000 589399.565 4827.971 36931.825 41759.797 46.000 552183.057 4543.288 37216.508 41759.797 47.000 514679.671 4256.411 37503.386 41759.797 48.000 476887.197 3967.322 37792.474 41759.797 49.000 438803.406 3676.005 38083.791 41759.797 50.000 400426.052 3382.443 38377.354 41759.797 51.000 361752.873 3086.617 38673.179 41759.797 52.000 322781.588 2788.512 38971.285 41759.797 53.000 283509.900 2488.108 39271.689 41759.797 54.000 243935.492 2185.389 39574.408 41759.797 55.000 204056.031 1880.336 39879.461 41759.797 56.000 163869.167 1572.932 40186.865 41759.797 57.000 123372.528 1263.158 40496.638 41759.797 58.000 82563.728 950.997 40808.800 41759.797 59.000 41440.360 636.429 41123.368 41759.797 60.000 0.000 319.436 41440.360 41759.797 (%i4) quit();

If you want to be a little adventurous in your monthly payments, that is, instead of equal payments, you want to do increasing payments, Maxima could help you with that as well. *arit_amortization()* and *geo_amortization()* are two such functions, which provide the schedule for increasing payments with fixed amount increments and fixed rate increments, respectively. Heres a small demo of how it works:

$ maxima -q (%i1) load(finance)$ (%i2) amortization(0.10, 100, 5)$ n Balance Interest Amortization Payment 0.000 100.000 0.000 0.000 0.000 1.000 83.620 10.000 16.380 26.380 2.000 65.603 8.362 18.01 26.380 3.000 45.783 6.560 19.819 26.380 4.000 23.982 4.578 21.801 26.380 5.000 0.000 2.398 23.982 26.380 (%i3) arit_amortization(0.10, 10, 100, 5)$ n Balance Interest Amortization Payment 0.000 100.000 0.000 0.000 0.000 1.000 101.722 10.000 -1.722 8.278 2.000 93.615 10.172 8.106 18.278 3.000 74.698 9.362 18.917 28.278 4.000 43.890 7.470 30.809 38.278 5.000 0.000 4.389 43.890 48.278 (%i4) geo_amortization(0.10, 0.05, 100, 5)$ n Balance Interest Amortization Payment 0.000 100.000 0.000 0.000 0.000 1.000 85.907 10.000 14.093 24.093 2.000 69.200 8.591 16.707 25.298 3.000 49.558 6.920 19.642 26.562 4.000 26.623 4.956 22.935 27.891 5.000 0.000 2.662 26.623 29.285 (%i5) quit();

*%i2* has been provided for comparative analysis. *%i3* shows the incremental payout with increments of `10 (the second parameter of *arit_amortization())*. *%i4* shows the incremental payout with increments at the rate of 5 per cent (the second parameter of *geo_amortization()).* Both these computations could be done in decrements as well just pass the second parameter as negative.

** Plan your savings**

Say, you have a savings account like the PPF (Public Provident Fund), giving you interest at a rate of 8 per cent p.a., and at the end of five years, you want to have saved `100,000. So, what should be your minimum yearly deposit into your account? It is not as simple as dividing by 5, as the interest would be also added to your savings.* saving()* shows you the complete schedule as follows:

$ maxima -q (%i1) load(finance)$ (%i2) saving(0.08 /* interest rate */, 100000 /* final savings */, 5 /* years */)$ n Balance Interest Payment 0.000 0.000 0.000 0.000 1.000 17045.645 0.000 17045.645 2.000 35454.943 1363.652 17045.645 3.000 55336.983 2836.395 17045.645 4.000 76809.588 4426.959 17045.645 5.000 100000.000 6144.767 17045.645

And the minimum yearly deposit to be made is `17,046. The Balance and Interest columns, respectively, tell you about the balance and the interest accumulated in the corresponding year. If you are only interested in knowing the minimum amount to be deposited, you may just use the* annuity_fv()* function, which basically computes the annuity of `17,046 every year for five years in order to have saved `100,000 after five years.

(%i3) annuity_fv(0.08, 100000, 5); (%o3) 17045.64545668365 (%i4) quit();

** Project planning**

Finance management is a key element of planning any project, whether professional or personal. Assume a project would take n years, with given yearly expenses, and say the available interest rate is r p.a. Then, a common question that every project manager needs to answer is: what is the net present value (NPV) of the project, which needs to be invested for the project. The answer to this basic question is, more often than not, one of the important factors for deciding whether or not to take up this project. Maxima provides npv() to compute the same. As an example, if a project needs `100, `200, `150 and `600 over four years, respectively, and the current interest rate is 7 per cent, what is the NPV? It would be `848 as shown below:

$ maxima -q (%i1) load(finance)$ (%i2) npv(0.07, [100, 200, 150, 600]); (%o2) 848.3274983420189 (%i3) quit();

Another common practice when choosing between various projects is to compute the benefit-to-cost ratio of the various projects, and select the one with the best ratio. The benefit-to-cost ratio for a given interest rate *<r>* could be computed using* benefit_cost().* Heres an example to demonstrate this, assuming 18 per cent as the rate of interest:

Project P1 (2 years): Yearly benefits (100, 200), yearly costs (150, 50) Project P2 (3 years): Yearly benefits (0, 200, 100), yearly costs (100, 100, 0) Project P3 (4 years): Yearly benefits (0, 200, 200, 100), yearly costs (100, 100, 50, 50)

$ maxima -q (%i1) load(finance)$ (%i2) benefit_cost(0.18, [100, 200], [150, 50]); (%o2) 1.400881057268722 (%i3) benefit_cost(0.18, [0, 200, 100], [100, 100, 0]); (%o3) 1.306173223448919 (%i4) benefit_cost(0.18, [0, 200, 200, 100], [100, 100, 50, 50]); (%o4) 1.489492494361802 (%i5) quit();

And clearly, over the long run, the four-year project P3 has a better benefit-cost ratio. But if one is only looking for shorter term benefits, then you could go with project P1 as well.

## Connect With Us