The July 2016 Perl programming challenge by Ramana Mokkapati


THE CHALLENGE: Write a Perl program that calculates financial annual interest rate. DETAILS: [Problem] Financial institution offers annual percentage interest rate "R" (compounded daily); daily rate is "r". R = r * 365 * 100 Depositor deposits/withdraws money on different dates... date principal ------------- d1 p1 d2 p3 d3 p3 . . . etc... "P" is the account value on date "D". e.g. P = p1(1+r)^(D-d1) + p2(1+r)^(D-d2) + p3(1+r)^(D-d3) + ... Programming challenge: Given a file containing "deposit date" and "deposit amount" (one pair per line - comma or tab separated), and the account value "P" on date "D", find the effective interest rate R and plot the growth of account's value over the period (d1 .. D). [/Problem] [Example] % cat deposits.csv date,deposit 2016-01-10,100 2016-01-23,50 2016-01-30,-25 2016-02-10,80 2016-03-20,125 2016-04-15,-130 2016-05-05,25 2016-05-26,45 2016-06-18,102 Step 1) Find "r" (daily compounded interest rate) from the following equation ... (assume account value "P" is 400 on statement date "D" = 2016-06-30) P = p1(1+r)^(D-d1) + p2(1+r)^(D-d2) + p3(1+r)^(D-d3) + ... R (annually compounded percentage interest rate) = 365 * 100 * r Step 2) If R = 28%, use this to compute the account value for each day from the initial date (2016-01-10) to the statement date (D). E.g. Date |Deposit|AccountValue 2016-01-10| 100| 100.00 2016-01-11| | 100.08 2016-01-12| | 100.15 2016-01-13| | 100.23 2016-01-14| | 100.31 2016-01-15| | 100.38 2016-01-16| | 100.46 2016-01-17| | 100.54 2016-01-18| | 100.62 2016-01-19| | 100.69 2016-01-20| | 100.77 2016-01-21| | 100.85 2016-01-22| | 100.92 2016-01-23| 50| 151.00 <== This represents $100 compounded for 13 days + today's deposit 2016-01-24| | 151.12 2016-01-25| | 151.23 2016-01-26| | 151.35 2016-01-27| | 151.46 2016-01-28| | 151.58 2016-01-29| | 151.70 2016-01-30| -25| 126.81 2016-01-31| | 126.91 . . . 2016-06-30| | 400.00 <== Note that this number should match the account value ("P" = 400). If not R should be different. Step 3) Just plot a graph of account value over time. [/Example]