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.)


The QuantLib module.


Valuation date as a string in the form of ‘YYYY-MM-DD’.


Projection end date as a string in the form of ‘YYYY-MM-DD’.


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

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 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.



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


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_().


Returns the aggregated cashflows of the entire bond portfolio.

Takes the sum of cashflows() across bond_id and returns as a list the aggregated cashflows of all the bonds in bond_data.


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 by date_init, and increments annually.


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 and schedule().

A pricing engine for the bond object is created as a DiscountingBondEngine object from riskfree_curve() and the z_spread attribute in bond_data, and associated with the bond object through a ZeroSpreadedTermStructure object.


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.


Returns all redemption cashflows

Returns a list of redemptions of all the bonds in bond_data.


Returns ZeroCurve object

Creates QuantLib’s ZeroCurve object from zero_curve and returns it. The ZeroCurve object is used by fixed_rate_bond() to construct a discount curve for calculating the market value of the specified bond.


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.


Returns the number of time steps

Calculates the number of time steps from date_end and date_() ren returns it.


Calculate Z-spread

For the bond specified by bond_id, Calculate the Z-spread of the bond specified by bond_id from the bond’s market value and riskfree_curve(). This is for testing that the calculated Z-spread matches the input in bond_data.


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 in bond_data.