{"id":5714,"date":"2014-09-29T01:57:41","date_gmt":"2014-09-29T01:57:41","guid":{"rendered":"http:\/\/www.oracletutoring.ca\/blog\/?p=5714"},"modified":"2014-09-29T01:57:41","modified_gmt":"2014-09-29T01:57:41","slug":"perl-a-compound-interest-calculator-part-ii","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/perl-a-compound-interest-calculator-part-ii\/","title":{"rendered":"Perl:  A compound interest calculator, Part II"},"content":{"rendered":"<h1>Compound interest is probably studied more in high school than it was twenty years ago. \u00a0The tutor amends the perl program from September 10 to cover the general case of compound interest.<\/h1>\n<p>Back in my <a href=\"?p=5464\">September 10 article,<\/a> I offered a short Perl program that calculates compound interest with annual compounding. However, what about monthly, weekly, daily, or other compounding frequencies? Today, I&#8217;ll show the changes needed for the program to cover all possibilities.<\/p>\n<p>For those wanting a refresher on the general formula for compound interest &#8211; or else on what compounding means &#8211; see my article <a href=\"?p=5550\">here.<\/a> For those curious about the ideas behind the Perl program in the <a href=\"?p=5464\">September 10 article,<\/a> search this blog for perl. Otherwise, click, on right pane, (or right <a href=\"?cat=105\">here<\/a>) the computer science category; you&#8217;ll find the perl articles in there.<\/p>\n<p>The new program follows. The changes from the original are <span style=\"color: #990099;\">in lilac<\/span>.  Those changes enable the program to cover the general case &#8211; that is, where the compounding may be more than annually.<\/p>\n<p><span style=\"color: brown; font-family: monospace;\"><br \/>\n#!\/usr\/bin\/perl<br \/>\n$principal =$ARGV[0];<br \/>\n$percent=$ARGV[1];<br \/>\n$rate=$ARGV[1]\/100;<br \/>\n$time=$ARGV[2];<br \/>\n<span style=\"color: #990099;\">$ppyear=$ARGV[3];#compounding periods per year<\/span><br \/>\n$futurevalue=$principal*(1+$rate<span style=\"color: #990099;\">\/$ppyear<\/span>)**($time<span style=\"color: #990099;\">*$ppyear<\/span>);<br \/>\nprint &#8220;The principal amount is $principal\\n&#8221;;<br \/>\nprint &#8220;The annual interest rate is $percent percent\\n&#8221;;<br \/>\n<span style=\"color: #990099;\">print &#8220;The compoundings per year is $ppyear\\n&#8221;;<\/span><\/p>\n<p>print &#8220;The time duration of the investment is $time years\\n\\n&#8221;;<br \/>\nprint &#8220;The future value of the intestment is $futurevalue\\n\\n&#8221;;<br \/>\n<\/span><\/p>\n<p>Now, when you run this program from the command line, you&#8217;ll need to add in one last parameter: the compoundings per year.  If the compounding is monthly, the number will be 12; weekly will mean 52.<\/p>\n<p><strong>Example:<\/strong>  Imagine the new, improved compound interest calculator is called <span style=\"font-family:monospace\">intcalc1.txt<\/span>.  Let&#8217;s further imagine you want to use it to calculate the future value of an investment of $2500, at interest rate 3.2%, compounded monthly, over a term of 5 years.  What command would you enter at the terminal to accomplish that calculation?<\/p>\n<p>Solution:  Assuming you are in the proper directory (see my article <a href=\"?p=4658\">here<\/a> if you need a primer), you will enter the following:<\/p>\n<p><span style=\"font-family:monospace\">perl intcalc1.txt 2500 3.2 5 12<\/span><\/p>\n<p>If all goes well, you might be greeted with the following response:<\/p>\n<p><span style=\"font-family:monospace\"><br \/>\nThe principal amount is 2500<br \/>\nThe annual interest rate is 3.2 percent<br \/>\nThe compoundings per year is 12<br \/>\nThe time duration of the investment is 5 years<\/p>\n<p> The future value of the investment is 2933.152481&#8230;<\/span><\/p>\n<p>While there is more to say about this program, today&#8217;s purpose is satisfied.  I&#8217;ll be extending the discussion in future posts:)<\/p>\n<p>Jack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Compound interest is probably studied more in high school than it was twenty years ago. \u00a0The tutor amends the perl program from September 10 to cover the general case of compound interest. Back in my September 10 article, I offered &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/perl-a-compound-interest-calculator-part-ii\/\"> <span class=\"screen-reader-text\">Perl:  A compound interest calculator, Part II<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[236,228,173],"class_list":["post-5714","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-compound-interest-general-case","tag-compound-interest-with-variable-periods","tag-perl-programming"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/5714","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=5714"}],"version-history":[{"count":38,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/5714\/revisions"}],"predecessor-version":[{"id":5753,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/5714\/revisions\/5753"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=5714"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=5714"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=5714"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}