Bond Price with YTM/zero-curve & NPV, IRR, annuities
Project description
Installation
pip install bond_pricing
For installation without pulling in scipy
as a dependency, see below
The source code is at https://github.com/jrvarma/bond_pricing if you want to go that route.
Overview
This package provides bond pricing functions as well as basic NPV/IRR functions. Bond valuation can be done using an yield to maturity or using a zero yield curve. There is a convenience function to construct a zero yield curve from a few points on the par bond or zero yield curve or from Nelson Siegel parameters.
The documentation is available at https://bond-pricing.readthedocs.io/
The bond valuation functions can be used in two modes:
-
The first mode is similar to spreadsheet bond pricing functions. The settlement date and maturity date are given as dates and the software calculates the time to maturity and to each coupon payment date from these dates. For any
daycount
other than simple counting of days (ACT/365 in ISDA terminology), this packages relies on theisda_daycounters
module that can be downloaded from https://github.com/miradulo/isda_daycounters -
Maturity can be given in years (the
settle
parameter is set toNone
and is assumed to be time 0) and there are no dates at all. This mode is particularly convenient to price par bonds or price other bonds on issue date or coupon dates. For example, finding the price of a 7 year 3.5% coupon bond if the prevailing yield is 3.65% is easier in this mode as the maturity is simply given as 7.0 instead of providing a maturity date and specifying today's date. Using this mode between coupon dates is not so easy as the user has to basically compute the day count and year fraction and provide the maturity as say 6.7 years. -
Bond Valuation
- Bond price using YTM (
bond_price
) or using zero yield curve (zero_curve_bond_price
) - Accrued interest and dirty bond prices using YTM (
bond_price_breakup
) or using zero yield curve (zero_curve_bond_price_breakup
) - Duration using YTM (
bond_duration
) - Yield to maturity (
bond_yield
).
- Bond price using YTM (
-
Zero curve construction
- bootstrap zero yields from par yields (
par_yld_to_zero
) or vice versa (zero_to_par
) - compute zero rates from Nelson Siegel parameters (
nelson_siegel_zero_rate
) - construct zero prices from par or zero yields at selected knot points using a cubic spline or assuming a flat yield curve (
make_zero_price_fun
)
- bootstrap zero yields from par yields (
-
Present Value functions
- Net Present Value (
npv
) - Internal Rate of Return (
irr
) - Duration (
duration
). These functions allow different compounding frequencies: for example, the cash flows may be monthly while the interest rate is semi-annually compounded. The functionequiv_rate
converts between different compounding frequencies.
- Net Present Value (
-
Annuity functions
- Annuity present value (
annuity_pv
) - Future value (
annuity_fv
) - Implied interest rate (
annuity_rate
) - Number of periods to achieve given present value or terminal value (
annuity_periods
). - Periodic instalment to achieve given present value or terminal value (
annuity_instalment
). - Breakup of instalment into principal and interest (
annuity_instalment_breakup
)
In these functions also, the cash flow frequency may be different from the compounding frequency.
- Annuity present value (
Reducing Dependencies
This module requires numpy
, pandas
and scipy
. In some environments, installing scipy
may be difficult, and only a couple of functions (the newton
root finder and CubicSpline
interpolation) are actually needed from the huge scipy
package. So a provision has been made to avoid scipy
with some loss of functionality (the newton
root finder is replaced by a less sophisticated root bracketing and bisection algorithm and CubicSpline
interpolation is replaced by the much cruder linear interpolation). At run time, the module checks for the availability of scipy
and uses the cruder methods (with a suitable warning) if scipy
is not available.
To install this package without pulling in scipy
as a dependency, do the following:
git clone https://github.com/jrvarma/bond_pricing.git
export no_scipy=1
pip install bond_pricing
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file bond_pricing-0.7.3.tar.gz
.
File metadata
- Download URL: bond_pricing-0.7.3.tar.gz
- Upload date:
- Size: 33.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 357a3e267693463436714453249bff70635930f5a6f52798306382a8533a80b0 |
|
MD5 | 739ee9458c6642ca6acf12ede8620103 |
|
BLAKE2b-256 | 85f3f400be5ccbc2d1a4fa7e8a372143fe5a884885d738af56bea546a6bef901 |
File details
Details for the file bond_pricing-0.7.3-py3-none-any.whl
.
File metadata
- Download URL: bond_pricing-0.7.3-py3-none-any.whl
- Upload date:
- Size: 34.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b24f796eb5321128515b8c71563a93aa602ebe407c5c11e37638c9476f59962 |
|
MD5 | 2ca9df5d37e5011a15edc0ac45355959 |
|
BLAKE2b-256 | 25b13e682ca23d739cde05402ac06ced223464d727f87042ea54e35d05adc6d5 |