useful script on bladecenters
[tridge/junkcode.git] / effective_rate.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 if ($#ARGV < 1) {
6         print "
7 Usage: effective_rate.pl <advertised_rate> <days_between_interest_credit>
8 ";
9         exit(0);
10 }
11
12 sub compound_rate($$)
13 {
14         my $rate = shift;
15         my $interest_period = shift;
16         my $value = 1.0;
17         my $daily_rate = $rate / 365.0;
18
19         my $limbo = 0;
20         for (my $day=1; $day <= 365.0; $day++) {
21                 $limbo += ($daily_rate/100.0) * $value;
22                 if ($day % $interest_period == 0) {
23                         $value += $limbo;
24                         $limbo = 0;
25                 }
26         }
27         $value += $limbo;
28
29         return 100 * ($value - 1.0);
30 }
31
32 my $rate = shift;
33 my $interest_period = shift;
34
35 my $real_rate = compound_rate($rate, $interest_period);
36
37 printf "Compound rate %.2f\n", $real_rate;