Bonds

Primer on bonds.

Introduction

The purpose of this notebook is to show functionality related to bonds on the platform.

A notebook containing all the code used in this page can be accessed in the research environment: Example notebooks.

Environment

Setting up your environment takes three steps:

  • Import the relevant internal and external libraries

  • Configure the environment parameters

  • Initialise the environment

import sigtech.framework as sig

import QuantLib as ql
import datetime as dtm
import seaborn as sns

sns.set(rc={'figure.figsize': (18, 6)})
sig.config.init();

Government Bond Instrument

Government bonds are objects that can be retrieved by the object name constructed by the Country code, coupon, maturity date and 'GOVT' key.

bond_sig = sig.obj.get('US 2.625 2029/02/15 GOVT')

Each bond has various data elements accessible through their objects. The available time series for bond instruments are stored in the properties .history_fields and .extra_fields and are the following:

bond_sig.history_fields, bond_sig.extra_fields

For querying the listed time series, the name of the time series can be passed in as the field parameter in the method .history(field = ) as shown below:

bond_sig.history(field='YTM').tail(5)

Furthermore, the bond also holds relevant static data as seen below:

bond_sig.data_dict()

Every single bond is part of a bond group, where a bond group contains all bonds issued by an issuer.

bond_group = bond_sig.group()
bond_group

As shown above, the bond group also acts as an object, therefore it holds functionality and data on its own. An example of the functionality is to query all bonds in a bond group which is shown below:

bond_group.query_instrument_names()[:5]

All coupons can be retrieved by the method .cashflows() as shown below:

bond_sig.cashflows(dtm.date(2021, 2, 1))

Z-spread

The z-spread is calculated using the Python QuantLib library. Below is an example of when calculating the z-spread on a given date. For more information on the Python QuantLib library, see the Python QuantLib documentation.

bond_sig.z_spread(dtm.date(2020, 2, 28))

The z-spread can also be retrieved as a time series as shown below:

bond_sig.z_spreads().plot();

Asset swap spread

The asset swap spread is also calculated using the Python QuantLib library. The asset swap spread can be retrieved for a given date with the following method:

bond_sig.asw_spread(dtm.date(2020, 2, 28))

Convexity

ql_bond = bond_sig._quant_library_bond

ql.BondFunctions.convexity(
    ql_bond,
    0.05,
    ql_bond.dayCounter(),
    ql.Annual,
    ql_bond.frequency()
)

Modified duration

bond_sig.modified_duration(
    dtm.date(2020, 1, 4),
    6.
)

Creating Strategies

To create strategies of forward contract, users can easily make use of the building block RollingBondStrategy object. For further information on RollingBondStrategy, see Rolling Bond Strategy.

Last updated

© 2023 SIG Technologies Limited