home *** CD-ROM | disk | FTP | other *** search
- ********************
-
- FUNCTION Solve_ytm
-
- PARAMETERS _presvalue, _mat, _totc4yr, _perperyr, _noyears
-
- IF TYPE("_presvalue") + TYPE("_mat") + TYPE("_totc4yr") + ;
- TYPE("_perperyr") + TYPE("_noyears") != "NNNNN"
- RETURN(-1)
- ENDIF
-
- PRIVATE _coupons, _rates, _numbers, _dates, _temp, _top, _bottom, _nxt
-
- NOTE Contributed in part by Abe Rice
-
- NOTE _presvalue = present value
- NOTE _mat = _mat
- NOTE _totc4yr = total coupon for year
- NOTE _perperyr = periods per year
- NOTE _noyears = number of years
-
- _coupons = _totc4yr / _perperyr
- _rates = _coupons / _presvalue
- _numbers = _perperyr * _noyears
- _dates = (1 / ( 1 + _rates ))
- DO WHILE .T.
- _temp = ( _presvalue - _mat * _dates ** _numbers ) / _coupons
- _top = _temp
- _bottom = _temp - _dates ** _numbers + 1
- _nxt = _top / _bottom
- IF ABS(_nxt - _dates) < 10**-15
- EXIT
- ENDIF
- _dates = _nxt
- ENDDO
- RETURN( _perperyr * (1 - _dates) / _dates )
-
- * End of File