home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_11_02 / 1102054a < prev    next >
Text File  |  1992-12-07  |  6KB  |  180 lines

  1. /*****************************************************
  2.            File Name: FINANCES.C
  3.          Description: Library of functions for
  4.                       calculating interest rate
  5.                       formulas
  6. Global Function List: a_to_f
  7.                       a_to_f_c
  8.                       a_to_p
  9.                       a_to_p_c
  10.                       f_to_a
  11.                       f_to_a_c
  12.                       f_to_p
  13.                       f_to_p_c
  14.                       p_to_a
  15.                       p_to_a_c
  16.                       p_to_f
  17.                       p_to_f_c
  18.          Portability: Standard C
  19. ******************************************************/
  20.  
  21. /* Standard C */
  22. #include <math.h>
  23.  
  24. /* Own */
  25. #include <finances.h>
  26.  
  27. /*****************************************************
  28.        Name: a_to_f
  29. Description: annuity to future value
  30.  Parameters: i - effective interest rate per period
  31.              n - number of periods
  32.      Return: F/A - annuity to future value factor
  33. *****************************************************/
  34. double a_to_f( double i, int n )
  35.    {
  36.    return ( ( p_to_f( i, n ) - 1.0 ) / i );
  37.    }
  38.  
  39. /*****************************************************
  40.        Name: a_to_f_c
  41. Description: Annuity to future value
  42.              continuous compounding
  43.  Parameters: r - nominal interest rate per period
  44.              n - number of periods
  45.      Return: F/A - Annuity to future value factor
  46. *****************************************************/
  47. double a_to_f_c( double r, int n )
  48.    {
  49.    return ( ( p_to_f_c( r, n ) - 1.0 ) /
  50.          ( pow( LN_BASE, r ) - 1.0 ) );
  51.    }
  52.  
  53. /*****************************************************
  54.        Name: a_to_p
  55. Description: annuity to present value
  56.  Parameters: i - effective interest rate per period
  57.              n - number of periods
  58.      Return: P/A - annuity to present value factor
  59. *****************************************************/
  60. double a_to_p( double i, int n )
  61.    {
  62.    return ( a_to_f( i, n ) / p_to_f( i, n ) );
  63.    }
  64.  
  65. /*****************************************************
  66.        Name: a_to_p_c
  67. Description: annuity to present value
  68.              continuous compounding
  69.  Parameters: r - nominal interest rate per period
  70.              n - number of periods
  71.      Return: P/A - annuity to present value factor
  72. *****************************************************/
  73. double a_to_p_c( double r, int n )
  74.    {
  75.    return ( a_to_f_c( r, n ) / p_to_f_c( r, n ) );
  76.    }
  77.  
  78. /*****************************************************
  79.        Name: f_to_a
  80. Description: future value to annuity
  81.  Parameters: i - effective interest rate per period
  82.              n - number of periods
  83.      Return: A/F - future value to annuity factor
  84. *****************************************************/
  85. double f_to_a( double i, int n )
  86.    {
  87.    return ( 1.0 / a_to_f( i, n ) );
  88.    }
  89.  
  90. /*****************************************************
  91.        Name: f_to_a_c
  92. Description: future value to annuity
  93.              continuous compounding
  94.  Parameters: r - nominal interest rate per period
  95.              n - number of periods
  96.      Return: A/F - future value to annuity factor
  97. *****************************************************/
  98. double f_to_a_c( double r, int n )
  99.    {
  100.    return ( 1.0 / a_to_f_c( r, n ) );
  101.    }
  102.  
  103. /*****************************************************
  104.        Name: f_to_p
  105. Description: future value to present value
  106.  Parameters: i - effective interest rate per period
  107.              n - number of periods
  108.      Return: P/F - future to present value factor
  109. *****************************************************/
  110. double f_to_p( double i, int n )
  111.    {
  112.    return ( 1.0 / p_to_f( i, n ) );
  113.    }
  114.  
  115. /*****************************************************
  116.        Name: f_to_p_c
  117. Description: future value to present value
  118.              continuous compounding
  119.  Parameters: r - nominal interest rate per period
  120.              n - number of periods
  121.      Return: P/F - future to present value factor
  122. *****************************************************/
  123. double f_to_p_c( double r, int n )
  124.    {
  125.    return ( 1.0 / p_to_f_c( r, n ) );
  126.    }
  127.  
  128. /*****************************************************
  129.        Name: p_to_a
  130. Description: present value to annuity
  131.  Parameters: i - effective interest rate per period
  132.              n - number of periods
  133.      Return: A/P - present value to annuity factor
  134. *****************************************************/
  135. double p_to_a( double i, int n )
  136.    {
  137.    return ( p_to_f( i, n ) / a_to_f( i, n ) );
  138.    }
  139.  
  140. /*****************************************************
  141.        Name: p_to_a_c
  142. Description: present value to annuity
  143.              continuous compounding
  144.  Parameters: r - nominal interest rate per period
  145.              n - number of periods
  146.      Return: A/P - present value to annuity factor
  147. *****************************************************/
  148. double p_to_a_c( double r, int n )
  149.    {
  150.    return ( p_to_f_c( r, n ) / a_to_f_c( r, n ) );
  151.    }
  152.  
  153. /*****************************************************
  154.        Name: p_to_f
  155. Description: present value to future value
  156.  Parameters: i - effective interest rate per period
  157.              n - number of periods
  158.      Return: F/P - present to future value factor
  159. *****************************************************/
  160. double p_to_f( double i, int n )
  161.    {
  162.    return ( pow( 1 + i, n ) );
  163.    }
  164.  
  165. /*****************************************************
  166.        Name: p_to_f_c
  167. Description: present value to future value
  168.              continuous compounding
  169.  Parameters: r - nominal interest rate per period
  170.              n - number of periods
  171.      Return: F/P - present to future value factor
  172. *****************************************************/
  173. double p_to_f_c( double r, int n )
  174.    {
  175.    return ( pow( LN_BASE, r * n ) );
  176.    }
  177.  
  178.  
  179.  
  180.