Listing 1 FINANCES.C — functions for calculating interest rate formulas

/******************************************************
         File Name: FINANCES.C
       Description: Library of functions for
                  calculating interest rate
                  formulas
Global Function List: a_to_f
                  a_to_f_c
                  a_to_p
                  a_to_p_c
                  f_to_a
                  f_to_a_c
                  f_to_p
                  f_to_p_c
                  p_to_a
                  p_to_a_c
                  p_to_f
                  p_to_f_c
       Portability: Standard C
******************************************************/
/* Standard C */
#include <math.h>
/* Own */
#include <finances.h>

/*****************************************************
      Name: a_to_f
Description: annuity to future value
 Parameters: i - effective interest rate per period
           n - number of periods
    Return: F/A - annuity to future value factor
*****************************************************/
double a_to_f( double i, int n )
   {
   return ( ( p_to_f( i, n ) - 1.0 ) / i );
   }

/*****************************************************
      Name: a_to_f_c
Description: Annuity to future value
           continuous compounding
 Parameters: r - nominal interest rate per period
           n - number of periods
    Return: F/A - Annuity to future value factor
*****************************************************/
double a_to_f_c( double r, int n )
   {
   return ( ( p_to_f_c( r, n ) - 1.0 ) /
        ( pow( LN BASE, r ) - 1.0 ) );
   }

/*****************************************************
      Name: a_to_p
Description: annuity to present value
 Parameters: i - effective interest rate per period
           n - number of periods
    Return: P/A - annuity to present value factor
*****************************************************/
double a_to_p( double i, int n )
   {
   return ( a_to_f( i, n ) / p_to_f( i, n ) );
   }

/*****************************************************
      Name: a_to_p_c
Description: annuity to present value
           continuous compounding
 Parameters: r - nominal interest rate per period
           n - number of periods
    Return: P/A - annuity to present value factor
*****************************************************/
double a_to_p c( double r, int n )
   {
   return ( a_to_f_c( r, n ) / p_to_f_c( r, n ) );
   }

/*****************************************************
      Name: f_to_a
Description: future value to annuity
 Parameters: i - effective interest rate per period
           n - number of periods
    Return: A/F - future value to annuity factor
*****************************************************/
double f_to_a( double i, int n )
   {
   return ( 1.0 / a_to_f( i, n ) );
   }

/*****************************************************
      Name: f_to_a c
Description: future value to annuity
           continuous compounding
 Parameters: r - nominal interest rate per period
           n - number of periods
    Return: A/F - future value to annuity factor
*****************************************************/
double f_to_a c( double r, int n )
   {
   return ( 1.0 / a_to_f_c( r, n ) );
   }
/*****************************************************
      Name: f_to_p
Description: future value to present value
 Parameters: i - effective interest rate per period
           n - number of periods
    Return: P/F - future to present value factor
*****************************************************/
double f_to_p( double i, int n )
   {
   return ( 1.0 / p_to_f( i, n ) );
   }
/*****************************************************
      Name: f_to_p_c
Description: future value to present value
           continuous compounding
 Parameters: r - nominal interest rate per period
           n - number of periods
    Return: P/F - future to present value factor
*****************************************************/
double f_to_p_c( double r, int n )
   {
   return ( 1.0 / p_to_f_c( r, n ) );
   }
/*****************************************************
      Name: p_to_a
Description: present value to annuity
 Parameters: i - effective interest rate per period
           n - number of periods
    Return: A/P - present value to annuity factor
*****************************************************/
double p_to_a( double i, int n )
   {
   return ( p_to_f( i, n ) / a_to_f( i, n ) );
   }

/****************************************************
      Name: p_to_a_c
Description: present value to annuity
           continuous compounding
 Parameters: r - nominal interest rate per period
           n - number of periods
    Return: A/P - present value to annuity factor
****************************************************/
double p_to_a_c( double r, int n )
   {
   return ( p_to_f_c( r, n ) / a_to_f_c( r, n ) );
   }

/****************************************************
      Name: p_to_f
Description: present value to future value
 Parameters: i - effective interest rate per period
           n - number of periods
    Return: F/P - present to future value factor
****************************************************/
double p_to_f( double i, int n )
   {
   return ( pow( 1 + i, n ) );
   }

/****************************************************
      Name: p_to_f_c
Description: present value to future value
           continuous compounding
 Parameters: r - nominal interest rate per period
           n - number of periods
    Return: F/P - present to future value factor
****************************************************/
double p_to_f_c( double r, int n )
   {
   return ( pow( LN_BASE, r * n ) );
   }

/* End of File */