Created
          June 22, 2013 03:55 
        
      - 
      
- 
        Save andrewrcollins/5835811 to your computer and use it in GitHub Desktop. 
    Future Value Interest Factor (FVIF)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?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