Equity Trading Platform

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Saturday, 10 March 2007

Awk Scripts For Compund Interest

Posted on 11:35 by Unknown
This post from my Math Play blog  shows the power of compound interest.
 
Now, I will give two awk scripts.  The first one (compound) calculates compound interest on a lump sum.  The second one (compound_add) calculates the total return when we deposit regular contributions, as opposed to a lump sum.
 
First script (compound):
 
The run:
 
[514]-> compound
 
Usage: /usr/bin/nawk principle rate time
 
 
[515]-> compound 100 10 4
 
Amount 100.00 compounded at 1.1000 for 4 yields:
 
1: 110.0000
 
2: 121.0000
 
3: 133.1000
 
4: 146.4100
 
The script:
 
#! /usr/bin/nawk -f
 
BEGIN {
 
if (ARGC < 4)
 
{
 
printf ("Usage: %s principle rate time\n",ARGV[0])
 
exit 1
 
}
 
principle=ARGV[1]
 
rate=ARGV[2]/100+1
 
time=ARGV[3]
 
printf ("Amount %.2f compounded at %.4f for %d yields: \n\n",principle,rate,time)
 
for (i=1;i<=time; i++)
 
{
 
principle *= rate
 
printf ("%d: %.4f\n", i, principle)
 
}
 
}
 
 
Now, we will look at the second script (compound_add):
 
The run:
 
[517]-> compound_add
 
Usage: /usr/bin/nawk principle rate time
 
[518]-> compound_add 100 10 4
 
Amount 100.00 added in each time and compounded at 1.1000 for 4 yields:
 
1: 110.00 (invested: 100)
 
2: 231.00 (invested: 200)
 
3: 364.10 (invested: 300)
 
4: 510.51 (invested: 400)
 
The script:
 
#! /usr/bin/nawk -f
 
BEGIN {
 
if (ARGC < 4)
 
{
 
printf ("Usage: %s principle rate time\n",ARGV[0])
 
exit 1
 
}
 
principle=ARGV[1]
 
rate=ARGV[2]/100+1
 
time=ARGV[3]
 
printf ("Amount %.2f added in each time and compounded at %.4f for %d yields: \n\n",principle,rate,time)
 
for (i=1;i<=time; i++)
 
{
 
total = (principle + total)*rate
 
invest += principle
 
printf ("%d: %.2f (invested: %d)\n", i, total, invest)
 
}
 
}
 
Notice that the two scripts are almost identical.  The main difference is in the calculation, which is done as the script loops thru the time intervals.
 
In "compound", we simply keep multiplying principle by 1 + rate/100, to accumulate the value.
 
In "compound_add", we have to create a new "total" variable, so we can preserve the original principle value, so we can keep adding it in.  In this case, we take the accumulation, add in a new principle, and apply 1 + rate/100 to the whole thing.
 
In the first example, we add in $100, and let it grow at 10% per period for 4 periods.
 
In the second example, we contribute $100 in each period, for a total of $400 invested. All contributions grow at 10%/period for however many periods that they are in the account.
Email ThisBlogThis!Share to XShare to Facebook
Posted in Personal Finance | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Why Ron Paul Scares the GOP
    Good article in Time Magazine...
  • It's a Small World, After All...
    http://news.yahoo.com/s/ap/20080325/ap_on_el_pr/candidates_genealogy
  • The Hummer and the Model-T
    True Story: A couple of months ago, Forbes Magazine sponsored an off-road race over hilly terrain between a 1921 Ford Model-T and a Hummer. ...
  • U.S. Government Waste in Iraq
    http://news.yahoo.com/s/ap/20080728/ap_on_re_mi_ea/iraq_vacant_prison
  • Detecting Tax and Accounting Fraud thru Benford's Law
    On a recent tax blog carnival , I found this interesting post about how the IRS can flag "creative" numbers for audit by using Ben...
  • R.I.P. Pavarotti
  • Practical Way to Simplify The Federal Tax Today
    As a first step, we should eliminate all deductions, except for: charity, mortgage, property taxes, and local taxes. This does not sound lik...
  • Whatever Happened to Ron Paul...
    http://news.yahoo.com/s/politico/20080515/pl_politico/10353
  • Origin of Term "Yakuza"
    Yakuza is the term used for organized crime members in Japan. I read about the origin of the term in Wikipedia, and it is interesting. The ...
  • Dedicated Sales Page and Affiliate Promotion Tools!
    Update 04/15/2008: I have discontinued the Ebook version. I found that offering it hurt my sales conversion rate. It looks like I need to...

Categories

  • Billionaires
  • Business
  • Entrepreneurs
  • Financial Crisis
  • Government
  • Hollywood Bollywood
  • Humor
  • internet marketing
  • Law
  • Marketing
  • Passive Income
  • Personal Finance
  • Personal Growth
  • Politics
  • Real Estate
  • Stock Trading
  • Taxes
  • Videos

Blog Archive

  • ►  2008 (252)
    • ►  September (25)
    • ►  August (27)
    • ►  July (23)
    • ►  June (37)
    • ►  May (34)
    • ►  April (36)
    • ►  March (34)
    • ►  February (22)
    • ►  January (14)
  • ▼  2007 (155)
    • ►  December (20)
    • ►  November (13)
    • ►  October (14)
    • ►  September (4)
    • ►  August (9)
    • ►  July (7)
    • ►  June (13)
    • ►  May (15)
    • ►  April (10)
    • ▼  March (28)
      • Fwd: FW: FW: Beauty of Math!
      • Constant Value Investing With Virtual Shares
      • Lessons in Passive Income Building
      • The Old Man, the Boy, and the Donkey
      • Forbes' Quotations on Bureaucrats
      • Improve Your Business Writing
      • Some Words to Live By
      • Rich Schefren
      • Top 10 Surprising Results of Global Warming
      • European Commercial Real Estate Investment
      • U.S. Home Price Increases Still Slowing
      • Awk Scripts For Compund Interest
      • Google Calculator
      • Motorola Settles Bias Suit
      • Newspaper Affiliated Websites
      • For Olympic Bid, Chicago Needs "Skin in the Game"
      • Selling Real Estate on YouTube
      • 5 Tips to Simplify Writing for Better Results
      • Orlando Real Estate History
      • Importance of News to Local Stations
      • Walgreens Bias Suit
      • The Business of Making Lifestyle Coaches
      • 4 Red Flags For Home Repair Fraud
      • Gross-Receipts Tax
      • Sheldon Adelson
      • How to Succeed
      • Complicator's Gloves
      • Bayou Group Hedge Fund
    • ►  February (11)
    • ►  January (11)
  • ►  2006 (71)
    • ►  December (12)
    • ►  November (8)
    • ►  October (26)
    • ►  September (9)
    • ►  August (8)
    • ►  July (4)
    • ►  June (4)
Powered by Blogger.

About Me

Unknown
View my complete profile