Skip to content

Instantly share code, notes, and snippets.

@andrewrcollins
Created June 22, 2013 03:55
Show Gist options
  • Save andrewrcollins/5835811 to your computer and use it in GitHub Desktop.
Save andrewrcollins/5835811 to your computer and use it in GitHub Desktop.
Future Value Interest Factor (FVIF)
<?php
/**
* Future Value Interest Factor (FVIF)
*
* @param float $interest annual interest
* @param int $periods periods
* @throws InvalidArgumentException if $interest is not float
* @throws InvalidArgumentException if $periods is not int
* @return float future value interest factor
*/
function fvif($interest, $periods)
{
if(!is_float($interest))
{
throw new InvalidArgumentException('$interest is not float');
}
if(!is_int($periods))
{
throw new InvalidArgumentException('$periods is not int');
}
if($periods == 0)
{
return 1;
}
$interest_factor = $interest + 1;
if($interest_factor == 0)
{
return 0;
}
if($periods == 1)
{
return $interest_factor;
}
if($periods < 0)
{
$periods = -$periods;
$interest_factor = 1 / $interest_factor;
}
return pow($interest_factor, $periods);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment