FinancePy

FinancePy API Reference

Bond

financepy.products.bonds.bond

Classes

Bond

Bond(issue_dt: financepy.utils.date.Date, maturity_dt: financepy.utils.date.Date, coupon: float, freq_type: financepy.utils.frequency.FrequencyTypes, accrual_dc_type: financepy.utils.day_count.DayCountTypes, ex_div_days: int = 0, cal_type: financepy.utils.calendar.CalendarTypes = <CalendarTypes.WEEKEND: 2>, bd_type=<BusDayAdjustTypes.FOLLOWING: 2>, dg_type=<DateGenRuleTypes.BACKWARD: 2>, cpn_type=<CouponType.FIXED: 0>) -> None
Class for fixed coupon bonds and performing related analytics. These are bullet bonds which means they have regular coupon payments of a known size that are paid on known dts plus a payment of par at maturity.

Methods

times

times(self, settle_dt: financepy.utils.date.Date, curve_dc_type: financepy.utils.day_count.DayCountTypes = <DayCountTypes.ACT_365F: 7>)
Years from settlement to payments using day count convention

flows

flows(self, settle_dt: financepy.utils.date.Date)
Times from settlement to payments

reset_flows

reset_flows(self, cpn_dts: List[financepy.utils.date.Date], payment_dts: List[financepy.utils.date.Date], flow_amounts: numpy.ndarray)
Set the flows of the bond externally. Coupon dates are for accrued while payment dates are calendar adjusted. Flows are on payment dates

dirty_price_from_ytm

dirty_price_from_ytm(self, settle_dt: financepy.utils.date.Date, ytm: float, convention: financepy.products.bonds.bond.YTMCalcType = <YTMCalcType.UK_DMO: 1>)
Calculate the dirty price of bond from its yield to maturity. This function is vectorised with respect to the yield input. It implements a number of standard conventions for calculating the YTM.

dirty_price_from_ytm_vector

dirty_price_from_ytm_vector(self, settle_dts: (<class 'financepy.utils.date.Date'>, <class 'list'>), ytms: (<class 'float'>, <class 'list'>, <class 'numpy.ndarray'>), convention: financepy.products.bonds.bond.YTMCalcType = <YTMCalcType.UK_DMO: 1>)
Calculate dirty prices for vectors of settlement dates or yields.

forward_price

forward_price(self, settle_dt: financepy.utils.date.Date, forward_dt: financepy.utils.date.Date, clean_price: float, repo_rate: float, repo_dc_type: financepy.utils.day_count.DayCountTypes = <DayCountTypes.ACT_360: 8>)

No description available.

principal

principal(self, settle_dt: financepy.utils.date.Date, ytm: float, face: float, convention: financepy.products.bonds.bond.YTMCalcType)
Calculate the principal value of the bond based on the face amount from its discount margin and making assumptions about the future Ibor rates.

dollar_duration

dollar_duration(self, settle_dt: (<class 'financepy.utils.date.Date'>, typing.List), ytm: (<class 'float'>, typing.List), convention: financepy.products.bonds.bond.YTMCalcType = <YTMCalcType.UK_DMO: 1>)
Calculate dollar duration from a 1bp bumped-yield DV01. Dollar duration is the dirty-price change for a 100bp change in yield, approximated as: dollar_duration = 10000 * DV01 where DV01 is the positive dirty-price change for a +1bp yield shift.

dv01

dv01(self, settle_dt: financepy.utils.date.Date, ytm: float, convention: financepy.products.bonds.bond.YTMCalcType = <YTMCalcType.UK_DMO: 1>)
Change in dirty price for a +1 basis point increase in yield. Bloomberg-style DV01 / PV01 is positive for a long fixed-rate bond.

macaulay_duration

macaulay_duration(self, settle_dt: financepy.utils.date.Date, ytm: float, convention: financepy.products.bonds.bond.YTMCalcType = <YTMCalcType.UK_DMO: 1>)
Calculate the Macaulay duration of the bond on a settlement date given its yield to maturity.

modified_duration

modified_duration(self, settle_dt: financepy.utils.date.Date, ytm: float, convention: financepy.products.bonds.bond.YTMCalcType = <YTMCalcType.UK_DMO: 1>)
Calculate the modified duration of the bond on a settlement date given its yield to maturity.

theta

theta(self, settle_dt: financepy.utils.date.Date, ytm: float, convention: financepy.products.bonds.bond.YTMCalcType = <YTMCalcType.UK_DMO: 1>, day_step: int = 1)
Calculate the change in the dirty price due to moving calendar time i.e. the settlement date, forward by day_step days.

key_rate_durations_zero_tent

key_rate_durations_zero_tent(self, settle_dt: financepy.utils.date.Date, zero_curve: financepy.market.curves.discount_curve.DiscountCurve, key_rate_tenors: list = None, shift: float = None)
Calculate key-rate durations using the textbook zero-rate tent formulation. This method perturbs the zero curve directly with piecewise-linear tent functions: - interior key rates have triangular weights - the first key rate is flat to the left - the last key rate is flat to the right Parameters ---------- settle_dt : Date Settlement date. zero_curve : DiscountCurve Base zero/discount curve used for valuation. It must provide discount factors through df(date). key_rate_tenors : list of float, optional Key-rate maturities in years. If None, defaults to [0.5, 1, 2, 3, 5, 7, 10, 20, 30]. shift : float, optional Size of the zero-rate bump. If None, defaults to 1 bp = 0.0001. Returns ------- tuple (key_rate_tenors, key_rate_durations) Notes ----- The bumped zero curve is defined by z_i^{up/down}(t) = z(t) +/- shift * w_i(t) where w_i(t) is the tent weight for key node i. This implementation assumes continuously-compounded zero rates: z(t) = -log(df(t))/t For t = 0, the bump is taken to be zero.

key_rate_durations

key_rate_durations(self, settle_dt: financepy.utils.date.Date, ytm: float, key_rate_tenors: list = None, shift: float = None, rates: list = None)
Calculates the key rate durations for a bond. Parameters ---------- settle_dt : FinancePy Date object The settlement date. ytm : float The yield to maturity. key_rate_tenors : list of float, optional The tenors of the key rates. If None, defaults to [0.5, 1, 2, 3, 5, 7, 10, 20, 30]. shift : float, optional The shift used to calculate the key rate durations. If None, defaults to 0.0001. rates : list of float, optional Corresponding yield curve data aligned with key_rate_tenors. If None, a flat yield curve at `ytm` is used. Returns ------- tuple of (numpy array of float, numpy array of float) A tuple containing the key rate tenors and the key rate durations.

convexity_from_ytm

convexity_from_ytm(self, settle_dt: financepy.utils.date.Date, ytm: float, convention: financepy.products.bonds.bond.YTMCalcType = <YTMCalcType.UK_DMO: 1>)
Calculate the bond convexity from the yield to maturity. This function is vectorised with respect to the yield input. This is defined as 1/P_D partial 2 P_D / partial dy 2

clean_price_from_ytm

clean_price_from_ytm(self, settle_dt: financepy.utils.date.Date, ytm: float, convention: financepy.products.bonds.bond.YTMCalcType = <YTMCalcType.UK_DMO: 1>)
Calculate the bond clean price from the yield to maturity. This function is vectorised with respect to the yield input.

clean_price_from_discount_curve

clean_price_from_discount_curve(self, settle_dt: financepy.utils.date.Date, discount_curve: financepy.market.curves.discount_curve.DiscountCurve)
Calculate the clean bond value using some discount curve to present-value the bond's cash flows back to the curve anchor date and not to the settlement date.

dirty_price_from_discount_curve

dirty_price_from_discount_curve(self, settle_dt: financepy.utils.date.Date, discount_curve: financepy.market.curves.discount_curve.DiscountCurve)

No description available.

yield_to_maturity

yield_to_maturity(self, settle_dt: financepy.utils.date.Date, clean_price: int | float | list | numpy.ndarray, convention: financepy.products.bonds.bond.YTMCalcType = <YTMCalcType.US_TREASURY: 3>)
Calculate the bond's yield to maturity by solving the price yield relationship using a one-dimensional root solver.

current_yield

current_yield(self, settle_dt: financepy.utils.date.Date, clean_price: float | list | numpy.ndarray)
Calculate the bond's simple yield.

accrued_interest

accrued_interest(self, settle_dt: financepy.utils.date.Date, face: float = 100.0)
Calculate the amount of coupon that has accrued between the previous coupon date and the settlement date. Note that for some day count schemes (such as 30E/360) this is not actually the number of days between the previous coupon payment date and settlement date. If the bond trades with ex-coupon dates then you need to use the number of days before the coupon date the ex-coupon date is. You can specify the calendar to be used in the bond constructor - NONE means only calendar days, WEEKEND is only weekends, or you can specify a country calendar for business days.

asset_swap_spread

asset_swap_spread(self, settle_dt: financepy.utils.date.Date, clean_price: float, discount_curve: financepy.market.curves.discount_curve.DiscountCurve, swap_float_day_count_convention_type=<DayCountTypes.ACT_360: 8>, swap_float_frequency_type=<FrequencyTypes.SEMI_ANNUAL: 2>, swap_float_calendar_type=<CalendarTypes.WEEKEND: 2>, swap_float_bus_day_adjust_rule_type=<BusDayAdjustTypes.FOLLOWING: 2>, swap_float_date_gen_rule_type=<DateGenRuleTypes.BACKWARD: 2>)
Calculate the par asset swap spread of the bond. The discount curve is an Ibor curve that is passed in. This function is vectorised with respect to the clean price.

z_spread

z_spread(self, settle_dt: financepy.utils.date.Date, clean_price: float, discount_curve: financepy.market.curves.discount_curve.DiscountCurve)
Calculate the z-spread of the bond. The discount curve is a Ibor curve that is passed in.

dirty_price_from_oas

dirty_price_from_oas(self, settle_dt: financepy.utils.date.Date, discount_curve: financepy.market.curves.discount_curve.DiscountCurve, oas: float)
Calculate the price of the bond by adding a spread (OAS) to the curve.

option_adjusted_spread

option_adjusted_spread(self, settle_dt: financepy.utils.date.Date, clean_price: float, discount_curve: financepy.market.curves.discount_curve.DiscountCurve)
Return OAS for bullet bond given settlement date, clean bond price and the discount relative to which the spread is to be computed.

dirty_price_from_survival_curve

dirty_price_from_survival_curve(self, settle_dt: financepy.utils.date.Date, discount_curve: financepy.market.curves.discount_curve.DiscountCurve, survival_curve: financepy.market.curves.discount_curve.DiscountCurve, recovery_rate: float)
Calculate discounted present value of flows assuming default model. The survival curve treats the coupons as zero recovery payments while the recovery fraction of the par amount is paid at default. For the defaulting principal we discretize the time steps using the coupon payment times. A finer discretization may handle the time value with more accuracy. I reduce any error by averaging period start and period end payment present values.

clean_price_from_survival_curve

clean_price_from_survival_curve(self, settle_dt: financepy.utils.date.Date, discount_curve: financepy.market.curves.discount_curve.DiscountCurve, survival_curve: financepy.market.curves.discount_curve.DiscountCurve, recovery_rate: float)
Calculate clean price value of flows assuming default model. The survival curve treats the coupons as zero recovery payments while the recovery fraction of the par amount is paid at default.

calc_ror

calc_ror(self, begin_dt: financepy.utils.date.Date, end_dt: financepy.utils.date.Date, begin_ytm: float, end_ytm: float, convention: financepy.products.bonds.bond.YTMCalcType = <YTMCalcType.US_STREET: 2>)
Calculate the rate of total return(capital return and interest) given a BUY YTM and a SELL YTM of this bond. This function computes the dirty prices at buying and selling, plus the coupon payments during the period. It returns a tuple which includes a simple rate of return, a compounded IRR and the PnL.

print_payments

print_payments(self, settle_dt: financepy.utils.date.Date, face: float = 100)
Print a list of the unadjusted coupon dts and the adjusted payment dates used in the analytic calculations for the bond.

npv

npv(self, settle_dt: financepy.utils.date.Date, discount_curve: financepy.market.curves.discount_curve.DiscountCurve, face: float = 100)
Calculate full NPV of bond.

CouponType

CouponType(*values)
Inherits from: Enum
Create a collection of name/value pairs. Example enumeration: >>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3 Access them by: - attribute access: >>> Color.RED <Color.RED: 1> - value lookup: >>> Color(1) <Color.RED: 1> - name lookup: >>> Color['RED'] <Color.RED: 1> Enumerations can be iterated over, and know how many members they have: >>> len(Color) 3 >>> list(Color) [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>] Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details.

YTMCalcType

YTMCalcType(*values)
Inherits from: Enum
Create a collection of name/value pairs. Example enumeration: >>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3 Access them by: - attribute access: >>> Color.RED <Color.RED: 1> - value lookup: >>> Color(1) <Color.RED: 1> - name lookup: >>> Color['RED'] <Color.RED: 1> Enumerations can be iterated over, and know how many members they have: >>> len(Color) 3 >>> list(Color) [<Color.RED: 1>, <Color.BLUE: 2>, <Color.GREEN: 3>] Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details.

Functions

validate_price

validate_price(px)

No description available.

validate_yield

validate_yield(ytm)

No description available.

vectorise_price

vectorise_price(price: float)

No description available.

Generated automatically from the FinancePy source code. Do not edit this file manually.