Skip to content

Bond

Bond

Bases: BaseModel

Bond security.

Attributes:

Name Type Description
face_value float

Face value of the bond.

id str

ID of the bond.

interest_rate float

Interest rate of the bond.

issue_date int

Issue date of the bond.

issuer Issuer

Issuer of the bond.

listing Listing

Listing of the bond.

maturity_date int

Maturity date of the bond.

name str

Name of the bond.

price_spread Union[PriceSpread]

Price spread of the bond.

repurchase_listing Listing

Repurchase listing of the bond.

version int

Version of the bond.

volume float

Volume

client Client

Client for interacting with the API.

Source code in alpha_trader/bonds/__init__.py
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
class Bond(BaseModel):
    """
        Bond security.

        Attributes:
            face_value: Face value of the bond.
            id: ID of the bond.
            interest_rate: Interest rate of the bond.
            issue_date: Issue date of the bond.
            issuer: Issuer of the bond.
            listing: Listing of the bond.
            maturity_date: Maturity date of the bond.
            name: Name of the bond.
            price_spread: Price spread of the bond.
            repurchase_listing: Repurchase listing of the bond.
            version: Version of the bond.
            volume: Volume
            client: Client for interacting with the API.
    """
    face_value: float
    id: str
    interest_rate: float
    issue_date: int
    issuer: Issuer
    listing: Listing
    maturity_date: int
    name: str
    price_spread: Union[PriceSpread]
    repurchase_listing: Listing
    version: int
    volume: float
    client: Client

    @staticmethod
    def initialize_from_api_response(api_response: Dict, client: Client, price_spread: PriceSpread = None):
        from alpha_trader.listing import Listing
        from alpha_trader.price.price_spread import PriceSpread

        if api_response["priceSpread"] is not None:
            price_spread = PriceSpread.initialize_from_api_response(api_response["priceSpread"], client)

        return Bond(
            face_value=api_response["faceValue"],
            id=api_response["id"],
            interest_rate=api_response["interestRate"],
            issue_date=api_response["issueDate"],
            issuer=Issuer.initialize_from_api_response(api_response["issuer"], client=client),
            listing=Listing.initialize_from_api_response(api_response["listing"], client),
            maturity_date=api_response["maturityDate"],
            name=api_response["name"],
            price_spread=price_spread,
            repurchase_listing=Listing.initialize_from_api_response(api_response["repurchaseListing"], client),
            version=api_response["version"],
            volume=api_response["volume"],
            client=client
        )

    @staticmethod
    def issue(
        company_id: str,
        face_value: float,
        interest_rate: float,
        maturity_date: int,
        number_of_bonds: int,
        client: Client
    ) -> "Bond":
        """
            Issue new bonds
        Args:
            client: API Client
            company_id: ID of the company
            face_value: face value of the bond
            interest_rate: interest rate
            maturity_date: maturity date
            number_of_bonds: quantity of bonds to issue

        Returns:
            Bond
        """
        data = {
            "companyId": company_id,
            "faceValue": face_value,
            "interestRate": interest_rate,
            "maturityDate": maturity_date,
            "numberOfBonds": number_of_bonds
        }
        response = client.request("POST", "api/bonds", data=data)
        print(response.text)

        return Bond.initialize_from_api_response(response.json(), client)

    def __str__(self):
        return f"Bond(name={self.name}, volume={self.volume}, price_spread={self.price_spread}) "

    def __repr__(self):
        return self.__str__()

    @property
    def remaining_time(self) -> float:
        """
            Calculate remaining time
        Returns:
            remaining time
        """
        return self.listing.end_date - time.time() * 1000

    @property
    def effective_interest_rate(self) -> float:
        """
            Calculate effective interest rate
        Returns:
            effective interest rate
        """
        remaining_days = self.remaining_time / 60 / 60 / 24 / 1000
        effective_interest_rate = (100 - self.price_spread.ask_price + self.interest_rate) / remaining_days

        return effective_interest_rate

effective_interest_rate: float property

Calculate effective interest rate

Returns: effective interest rate

remaining_time: float property

Calculate remaining time

Returns: remaining time

issue(company_id, face_value, interest_rate, maturity_date, number_of_bonds, client) staticmethod

Issue new bonds

Args: client: API Client company_id: ID of the company face_value: face value of the bond interest_rate: interest rate maturity_date: maturity date number_of_bonds: quantity of bonds to issue

Returns:

Type Description
'Bond'

Bond

Source code in alpha_trader/bonds/__init__.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
@staticmethod
def issue(
    company_id: str,
    face_value: float,
    interest_rate: float,
    maturity_date: int,
    number_of_bonds: int,
    client: Client
) -> "Bond":
    """
        Issue new bonds
    Args:
        client: API Client
        company_id: ID of the company
        face_value: face value of the bond
        interest_rate: interest rate
        maturity_date: maturity date
        number_of_bonds: quantity of bonds to issue

    Returns:
        Bond
    """
    data = {
        "companyId": company_id,
        "faceValue": face_value,
        "interestRate": interest_rate,
        "maturityDate": maturity_date,
        "numberOfBonds": number_of_bonds
    }
    response = client.request("POST", "api/bonds", data=data)
    print(response.text)

    return Bond.initialize_from_api_response(response.json(), client)