home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a075 / 1.img / TOOLKIT1.EXE / SST191.PRG < prev    next >
Encoding:
Text File  |  1989-08-08  |  1.0 KB  |  39 lines

  1. ********************
  2.  
  3. FUNCTION Solve_ytm
  4.  
  5.    PARAMETERS _presvalue, _mat, _totc4yr, _perperyr, _noyears
  6.  
  7.    IF TYPE("_presvalue") + TYPE("_mat") + TYPE("_totc4yr") + ;
  8.       TYPE("_perperyr") + TYPE("_noyears") != "NNNNN"
  9.       RETURN(-1)
  10.    ENDIF
  11.  
  12.    PRIVATE _coupons, _rates, _numbers, _dates, _temp, _top, _bottom, _nxt
  13.  
  14.    NOTE  Contributed in part by Abe Rice
  15.  
  16.    NOTE  _presvalue = present value
  17.    NOTE  _mat   = _mat
  18.    NOTE  _totc4yr   = total coupon for year
  19.    NOTE  _perperyr = periods per year
  20.    NOTE  _noyears   = number of years
  21.  
  22.    _coupons = _totc4yr / _perperyr
  23.    _rates   = _coupons / _presvalue
  24.    _numbers = _perperyr * _noyears
  25.    _dates   = (1 / ( 1 + _rates ))
  26.    DO WHILE .T.
  27.       _temp = ( _presvalue - _mat * _dates ** _numbers ) / _coupons
  28.       _top = _temp
  29.       _bottom = _temp - _dates ** _numbers + 1
  30.       _nxt = _top / _bottom
  31.       IF ABS(_nxt - _dates)  <  10**-15
  32.          EXIT
  33.       ENDIF
  34.       _dates = _nxt
  35.    ENDDO
  36.    RETURN( _perperyr * (1 - _dates) / _dates )
  37.  
  38. * End of File
  39.