Source code for sdk.lusid.models.bond

# coding: utf-8

"""
    LUSID API

    FINBOURNE Technology  # noqa: E501

    Contact: info@finbourne.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from datetime import datetime
from typing import Any, Dict, List, Optional, Union
from pydantic.v1 import Field, StrictFloat, StrictInt, StrictStr, conlist, constr, validator
from lusid.models.ex_dividend_configuration import ExDividendConfiguration
from lusid.models.flow_conventions import FlowConventions
from lusid.models.lusid_instrument import LusidInstrument
from lusid.models.rounding_convention import RoundingConvention

[docs] class Bond(LusidInstrument): """ LUSID representation of a Vanilla Fixed Rate Bond. # noqa: E501 """ start_date: datetime = Field(..., alias="startDate", description="The Start date of the bond, this is normally when accrual of the first coupon begins.") maturity_date: datetime = Field(..., alias="maturityDate", description="The Maturity date of the bond, this is when the last coupon accrual period ends. Note that while most bonds have their last payment on this date there are some cases where the final payment is the next working day.") dom_ccy: StrictStr = Field(..., alias="domCcy", description="The domestic currency of the instrument. This should be the same as the Currency set on the FlowConventions.") flow_conventions: FlowConventions = Field(..., alias="flowConventions") principal: Union[StrictFloat, StrictInt] = Field(..., description="The face-value or principal for the bond at outset. This might be reduced through its lifetime in the event of amortisation or similar.") coupon_rate: Union[StrictFloat, StrictInt] = Field(..., alias="couponRate", description="Simple coupon rate.") identifiers: Optional[Dict[str, StrictStr]] = Field(None, description="External market codes and identifiers for the bond, e.g. ISIN.") ex_dividend_days: Optional[StrictInt] = Field(None, alias="exDividendDays", description="Optional. Number of calendar days in the ex-dividend period. If the settlement date falls in the ex-dividend period then the coupon paid is zero and the accrued interest is negative. If set, this must be a non-negative number. If not set, or set to 0, then there is no ex-dividend period. NOTE: This field is deprecated. If you wish to set the ExDividendDays on a bond, please use the ExDividendConfiguration.") initial_coupon_date: Optional[datetime] = Field(None, alias="initialCouponDate", description="Optional and to be DEPRECATED. If set, this is the date at which the bond begins to accrue interest. Instead, this information should be entered in the field StartDate.") first_coupon_pay_date: Optional[datetime] = Field(None, alias="firstCouponPayDate", description="The date that the first coupon of the bond is paid. This is required for bonds that have a long first coupon or short first coupon. The first coupon pay date is used as an anchor to compare with the start date and determine if this is a long/short coupon period.") calculation_type: Optional[constr(strict=True, max_length=50, min_length=0)] = Field(None, alias="calculationType", description="The calculation type applied to the bond coupon amount. This is required for bonds that have a particular type of computing the period coupon, such as simple compounding, irregular coupons etc. The default CalculationType is `Standard`, which returns a coupon amount equal to Principal * Coupon Rate / Coupon Frequency. Coupon Frequency is 12M / Payment Frequency. Payment Frequency can be 1M, 3M, 6M, 12M etc. So Coupon Frequency can be 12, 4, 2, 1 respectively. Supported string (enumeration) values are: [Standard, DayCountCoupon, NoCalculationFloater, BrazilFixedCoupon, StandardWithCappedAccruedInterest].") rounding_conventions: Optional[conlist(RoundingConvention)] = Field(None, alias="roundingConventions", description="Rounding conventions for analytics, if any.") ex_dividend_configuration: Optional[ExDividendConfiguration] = Field(None, alias="exDividendConfiguration") original_issue_price: Optional[Union[StrictFloat, StrictInt]] = Field(None, alias="originalIssuePrice", description="The price the bond was issued at. This is to be entered as a percentage of par, for example a value of 98.5 would represent 98.5%.") instrument_type: StrictStr = Field(..., alias="instrumentType", description="The available values are: QuotedSecurity, InterestRateSwap, FxForward, Future, ExoticInstrument, FxOption, CreditDefaultSwap, InterestRateSwaption, Bond, EquityOption, FixedLeg, FloatingLeg, BespokeCashFlowsLeg, Unknown, TermDeposit, ContractForDifference, EquitySwap, CashPerpetual, CapFloor, CashSettled, CdsIndex, Basket, FundingLeg, FxSwap, ForwardRateAgreement, SimpleInstrument, Repo, Equity, ExchangeTradedOption, ReferenceInstrument, ComplexBond, InflationLinkedBond, InflationSwap, SimpleCashFlowLoan, TotalReturnSwap, InflationLeg, FundShareClass, FlexibleLoan") additional_properties: Dict[str, Any] = {} __properties = ["instrumentType", "startDate", "maturityDate", "domCcy", "flowConventions", "principal", "couponRate", "identifiers", "exDividendDays", "initialCouponDate", "firstCouponPayDate", "calculationType", "roundingConventions", "exDividendConfiguration", "originalIssuePrice"]
[docs] @validator('instrument_type') def instrument_type_validate_enum(cls, value): """Validates the enum""" if value not in ('QuotedSecurity', 'InterestRateSwap', 'FxForward', 'Future', 'ExoticInstrument', 'FxOption', 'CreditDefaultSwap', 'InterestRateSwaption', 'Bond', 'EquityOption', 'FixedLeg', 'FloatingLeg', 'BespokeCashFlowsLeg', 'Unknown', 'TermDeposit', 'ContractForDifference', 'EquitySwap', 'CashPerpetual', 'CapFloor', 'CashSettled', 'CdsIndex', 'Basket', 'FundingLeg', 'FxSwap', 'ForwardRateAgreement', 'SimpleInstrument', 'Repo', 'Equity', 'ExchangeTradedOption', 'ReferenceInstrument', 'ComplexBond', 'InflationLinkedBond', 'InflationSwap', 'SimpleCashFlowLoan', 'TotalReturnSwap', 'InflationLeg', 'FundShareClass', 'FlexibleLoan'): raise ValueError("must be one of enum values ('QuotedSecurity', 'InterestRateSwap', 'FxForward', 'Future', 'ExoticInstrument', 'FxOption', 'CreditDefaultSwap', 'InterestRateSwaption', 'Bond', 'EquityOption', 'FixedLeg', 'FloatingLeg', 'BespokeCashFlowsLeg', 'Unknown', 'TermDeposit', 'ContractForDifference', 'EquitySwap', 'CashPerpetual', 'CapFloor', 'CashSettled', 'CdsIndex', 'Basket', 'FundingLeg', 'FxSwap', 'ForwardRateAgreement', 'SimpleInstrument', 'Repo', 'Equity', 'ExchangeTradedOption', 'ReferenceInstrument', 'ComplexBond', 'InflationLinkedBond', 'InflationSwap', 'SimpleCashFlowLoan', 'TotalReturnSwap', 'InflationLeg', 'FundShareClass', 'FlexibleLoan')") return value
[docs] class Config: """Pydantic configuration""" allow_population_by_field_name = True validate_assignment = True
[docs] def to_str(self) -> str: """Returns the string representation of the model using alias""" return pprint.pformat(self.dict(by_alias=True))
[docs] def to_json(self) -> str: """Returns the JSON representation of the model using alias""" return json.dumps(self.to_dict())
[docs] @classmethod def from_json(cls, json_str: str) -> Bond: """Create an instance of Bond from a JSON string""" return cls.from_dict(json.loads(json_str))
[docs] def to_dict(self): """Returns the dictionary representation of the model using alias""" _dict = self.dict(by_alias=True, exclude={ "additional_properties" }, exclude_none=True) # override the default output from pydantic by calling `to_dict()` of flow_conventions if self.flow_conventions: _dict['flowConventions'] = self.flow_conventions.to_dict() # override the default output from pydantic by calling `to_dict()` of each item in rounding_conventions (list) _items = [] if self.rounding_conventions: for _item in self.rounding_conventions: if _item: _items.append(_item.to_dict()) _dict['roundingConventions'] = _items # override the default output from pydantic by calling `to_dict()` of ex_dividend_configuration if self.ex_dividend_configuration: _dict['exDividendConfiguration'] = self.ex_dividend_configuration.to_dict() # puts key-value pairs in additional_properties in the top level if self.additional_properties is not None: for _key, _value in self.additional_properties.items(): _dict[_key] = _value # set to None if identifiers (nullable) is None # and __fields_set__ contains the field if self.identifiers is None and "identifiers" in self.__fields_set__: _dict['identifiers'] = None # set to None if ex_dividend_days (nullable) is None # and __fields_set__ contains the field if self.ex_dividend_days is None and "ex_dividend_days" in self.__fields_set__: _dict['exDividendDays'] = None # set to None if initial_coupon_date (nullable) is None # and __fields_set__ contains the field if self.initial_coupon_date is None and "initial_coupon_date" in self.__fields_set__: _dict['initialCouponDate'] = None # set to None if first_coupon_pay_date (nullable) is None # and __fields_set__ contains the field if self.first_coupon_pay_date is None and "first_coupon_pay_date" in self.__fields_set__: _dict['firstCouponPayDate'] = None # set to None if calculation_type (nullable) is None # and __fields_set__ contains the field if self.calculation_type is None and "calculation_type" in self.__fields_set__: _dict['calculationType'] = None # set to None if rounding_conventions (nullable) is None # and __fields_set__ contains the field if self.rounding_conventions is None and "rounding_conventions" in self.__fields_set__: _dict['roundingConventions'] = None # set to None if original_issue_price (nullable) is None # and __fields_set__ contains the field if self.original_issue_price is None and "original_issue_price" in self.__fields_set__: _dict['originalIssuePrice'] = None return _dict
[docs] @classmethod def from_dict(cls, obj: dict) -> Bond: """Create an instance of Bond from a dict""" if obj is None: return None if not isinstance(obj, dict): return Bond.parse_obj(obj) _obj = Bond.parse_obj({ "instrument_type": obj.get("instrumentType"), "start_date": obj.get("startDate"), "maturity_date": obj.get("maturityDate"), "dom_ccy": obj.get("domCcy"), "flow_conventions": FlowConventions.from_dict(obj.get("flowConventions")) if obj.get("flowConventions") is not None else None, "principal": obj.get("principal"), "coupon_rate": obj.get("couponRate"), "identifiers": obj.get("identifiers"), "ex_dividend_days": obj.get("exDividendDays"), "initial_coupon_date": obj.get("initialCouponDate"), "first_coupon_pay_date": obj.get("firstCouponPayDate"), "calculation_type": obj.get("calculationType"), "rounding_conventions": [RoundingConvention.from_dict(_item) for _item in obj.get("roundingConventions")] if obj.get("roundingConventions") is not None else None, "ex_dividend_configuration": ExDividendConfiguration.from_dict(obj.get("exDividendConfiguration")) if obj.get("exDividendConfiguration") is not None else None, "original_issue_price": obj.get("originalIssuePrice") }) # store additional fields in additional_properties for _key in obj.keys(): if _key not in cls.__properties: _obj.additional_properties[_key] = obj.get(_key) return _obj