Bonds#
The main Space in the BasicBonds
model.
Parameters and References
(In all the sample code below,
the global variable Bonds
refers to the
Bonds
space.)
- date_init#
Valuation date as a string in the form of ‘YYYY-MM-DD’.
- date_end#
Projection end date as a string in the form of ‘YYYY-MM-DD’.
- zero_curve#
Zero curve at the valuation date as a pandas Series indexed with strings indicating various durations. This data is used by
riskfree_curve()
to create QuantLib’s ZeroCurve object:>>> Bonds.zero_curve Duration 1M 0.0004 2M 0.0015 3M 0.0026 6M 0.0057 1Y 0.0091 2Y 0.0136 3Y 0.0161 5Y 0.0182 7Y 0.0192 10Y 0.0194 20Y 0.0231 30Y 0.0225 Name: Rate, dtype: float64
The data is saved as an Excel file named “zero_curve.xlsx” in the model.
- bond_data#
Bond data as a pandas DataFrame. By default, a sample table generated by the generate_bond_data.ipynb notebook included in the library:
>>> Bonds.bond_data settlement_days face_value issue_date ... tenor coupon_rate z_spread bond_id ... 1 0 235000 2017-12-12 ... 1Y 0.07 0.0304 2 0 324000 2021-11-29 ... 1Y 0.08 0.0304 3 0 799000 2017-02-03 ... 6M 0.03 0.0155 4 0 679000 2017-11-19 ... 1Y 0.08 0.0229 5 0 397000 2018-07-01 ... 6M 0.06 0.0142 ... ... ... ... ... ... ... 996 0 560000 2019-02-16 ... 1Y 0.06 0.0261 997 0 161000 2020-03-12 ... 6M 0.05 0.0199 998 0 375000 2019-05-05 ... 1Y 0.03 0.0138 999 0 498000 2019-02-21 ... 1Y 0.03 0.0230 1000 0 438000 2019-03-14 ... 1Y 0.06 0.0256 [1000 rows x 8 columns]
The column names and their data types are as follows:
>>> Bonds.bond_data.dtypes settlement_days int64 face_value int64 issue_date datetime64[ns] bond_term int64 maturity_date datetime64[ns] tenor object coupon_rate float64 z_spread float64 dtype: object
The data is saved as an Excel file named “bond_data.xlsx” in the model.
Cells
|
Returns the cashflows of the selected bond. |
Returns the aggregated cashflows of the entire bond portfolio. |
|
|
Date at each projection step |
|
Returns QuantLib’s FixedRateBond object |
Returns the market values of the entire bonds |
|
|
Returns cashflows of redemptions |
Returns all redemption cashflows |
|
Returns ZeroCurve object |
|
|
Returns a Schedule object |
Returns the number of time steps |
|
|
Calculate Z-spread |
- cashflows(bond_id)[source]#
Returns the cashflows of the selected bond.
Returns the cashflows of the selected bond as a list. Each element of the list is the total cashflows falling in each projection period defined by
date_()
.
- cashflows_total()[source]#
Returns the aggregated cashflows of the entire bond portfolio.
Takes the sum of
cashflows()
acrossbond_id
and returns as a list the aggregated cashflows of all the bonds inbond_data
.
- date_(i)[source]#
Date at each projection step
Defines projection time steps by returning QuantLib’s Date object that corresponds to the value of the integer index
i
. By default,date_(i)
starts from the valuation date specified bydate_init
, and increments annually.
- fixed_rate_bond(bond_id)[source]#
Returns QuantLib’s FixedRateBond object
Create QuantLib’s FixedRateBond object representing a bond specified by the given bond ID. The bond object is created from the attributes in
bond_data
andschedule()
.A pricing engine for the bond object is created as a DiscountingBondEngine object from
riskfree_curve()
and thez_spread
attribute inbond_data
, and associated with the bond object through a ZeroSpreadedTermStructure object.
- redemptions(bond_id)[source]#
Returns cashflows of redemptions
For the specified bond, returns a list of redemptions cashflows. Since the redemption cashflow occurs only once, all but one element are zero.
- redemptions_total()[source]#
Returns all redemption cashflows
Returns a list of redemptions of all the bonds in
bond_data
.
- riskfree_curve()[source]#
Returns ZeroCurve object
Creates QuantLib’s ZeroCurve object from
zero_curve
and returns it. The ZeroCurve object is used byfixed_rate_bond()
to construct a discount curve for calculating the market value of the specified bond.
- schedule(bond_id)[source]#
Returns a Schedule object
Create QuantLib’s Schedule object for the specified bond and returns it. The returned Schedule object is used to by
fixed_rate_bond()
to construct FixedRateBond object.
- step_size()[source]#
Returns the number of time steps
Calculates the number of time steps from
date_end
anddate_()
ren returns it.
- z_spread_recalc(bond_id)[source]#
Calculate Z-spread
For the bond specified by
bond_id
, Calculate the Z-spread of the bond specified bybond_id
from the bond’s market value andriskfree_curve()
. This is for testing that the calculated Z-spread matches the input inbond_data
.
- market_values()[source]#
Returns the market values of the entire bonds
Calculates and Returns a list of the market values of
fixed_rate_bond()
for all bonds input inbond_data
.