Skip to content

Instantly share code, notes, and snippets.

@Lucent
Last active August 21, 2018 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lucent/ec6a2343c2b77b707045a263323bee1f to your computer and use it in GitHub Desktop.
Save Lucent/ec6a2343c2b77b707045a263323bee1f to your computer and use it in GitHub Desktop.
Calculate CD interest over term
<?
setlocale(LC_MONETARY, "en_US");
$cd_list = array(
array("Principal" => 250000, "Interest" => 5.05, "Start" => "27 Apr 2007", "Term" => "6 months", "Interest Term" => "6 months"),
array("Principal" => 250000, "Interest" => 5.10, "Start" => "27 Apr 2007", "Term" => "9 months", "Interest Term" => "9 months"),
array("Principal" => 250000, "Interest" => 5.20, "Start" => "27 Apr 2007", "Term" => "12 months", "Interest Term" => "6 months"),
array("Principal" => 250000, "Interest" => 5.00, "Start" => "27 Apr 2007", "Term" => "90 days", "Interest Term" => "90 days")
);
$total = 0;
foreach ($cd_list as $cd) {
$persecond = 365 * 24 * 60 * 60 * $cd["Principal"] * ($cd["Interest"] / 100);
if (time() > strtotime($cd["Start"] . " + " . $cd["Term"]))
echo "CD starting ", $cd["Start"], " term ", $cd["Term"], " paid ", money_format("%n", (strtotime($cd["Start"] . " + " . $cd["Term"]) - strtotime($cd["Start"])) / $persecond), " on ", date("j M Y", strtotime($cd["Start"] . " + " . $cd["Term"])), "<br>\n";
else $total += (time() - strtotime($cd["Start"])) / $persecond . "\n";
}
?>
Interest accumulated: <?= money_format("%n", $total) ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment