|
From: Luigi B. <lui...@gm...> - 2023-04-24 08:54:06
|
Or you can use the `AmortizingFixedRateBond` class (see https://github.com/lballabio/QuantLib/blob/master/ql/instruments/bonds/amortizingfixedratebond.hpp ). Luigi On Mon, Apr 24, 2023 at 12:35 AM Ben Watson <ben...@ma...> wrote: > I would suggest that you build the bond from the cashflows… The bond > cashflows > > i.e. > > bond=ql.Bond(int(self.settlementDays), self.local_calendar, self. > start_date,self.bond_cashflows) > > > > the cashflows can be with FixedRate leg or FloatingRate Leg; > > > > ql.FixedRateLeg(schedule=self.extended_dates_schedule,dayCount = > fixedDayCount,nominals = [self.redemption],couponRates=self.extended_cpns) > > > > > > > > > > *From:* Ngonidzashe Fungura <ngo...@gm...> > *Sent:* Monday, April 24, 2023 1:24 AM > *To:* QuantLib users <qua...@li...> > *Subject:* [Quantlib-users] Fixed Coupon Bond with 3 equal redemptions of > capital > > > > Hi All, > > > > I have a valuation of a fixed coupon bond below and I need help with the > following; > > 1. The repayment of the capital shall be made in three equal amounts > on the following dates: 30 April 2030, 30 April 2031, 30 April 2032. One > third of the nominal value of the loan will be redeemed on the above > mentioned dates, after which no further interest will accrue on the > redeemed portion. > 2. Extraction of the following values (i) nominal value, (ii) cash > flows (i.e., coupon and redeemed capital), (iii) payment date, (iv) accrual > start date, (v) accrual end date, (vi) accrual period, (vii) discount > factor and (vii) PV of cash flows > > *Valuation* > > > import QuantLib as ql > > calc_date = ql.Date(30, 6, 2022) > ql.Settings.instance().evaluationDate = calc_date > spot_dates = [ql.Date(30,6,2022), ql.Date(1,7,2022), > ql.Date(4,7,2022), ql.Date(7,7,2022), > ql.Date(29,7,2022), ql.Date(31,8,2022), > ql.Date(30,9,2022), ql.Date(30,12,2022), > ql.Date(31,3,2023), ql.Date(30,6,2023), > ql.Date(28,6,2024), ql.Date(30,6,2025), > ql.Date(30,6,2026), ql.Date(30,6,2027), > ql.Date(30,6,2028), ql.Date(29,6,2029), > ql.Date(28,6,2030), ql.Date(30,6,2031), > ql.Date(30,6,2032), ql.Date(30,6,2034), > ql.Date(30,6,2037), ql.Date(30,6,2042), > ql.Date(28,6,2047), ql.Date(28,6,2052)] > spot_rates = [0.000000, 0.046757, 0.047312, 0.047849, > 0.049859, 0.049461, 0.051026, 0.063041, > 0.069505, 0.074170, 0.074904, 0.079587, > 0.082547, 0.085506, 0.088410, 0.091284, > 0.093731, 0.095888, 0.097472, 0.099379, > 0.100715, 0.100591, 0.099606, 0.097955] > day_count = ql.Thirty360() > calendar = ql.UnitedStates() > interpolation = ql.Linear() > compounding = ql.Compounded > compounding_frequency = ql.Annual > spot_curve = ql.ZeroCurve(spot_dates, spot_rates, day_count, calendar, > interpolation, compounding, compounding_frequency) > spot_curve_handle = ql.YieldTermStructureHandle(spot_curve) > > issue_date = ql.Date(30, 4, 2022) > maturity_date = ql.Date(30, 4, 2032) > tenor = ql.Period(ql.Semiannual) > calendar = ql.SouthAfrica() > business_convention = ql.Unadjusted > date_generation = ql.DateGeneration.Backward > month_end = False > schedule = ql.Schedule(issue_date, maturity_date, tenor, > calendar, business_convention, > business_convention, date_generation, > month_end) > > # Let us print the schedule to check if it is in agreement with what we expect it to be. > print("Payment dates: ",list(schedule)) > > # Now that we have the schedule, we can create the FixedRateBond object. > coupon_rate = 0.105 > coupons = [coupon_rate] > settlement_days = 0 > face_value = 100 > fixed_rate_bond = ql.FixedRateBond(settlement_days,face_value,schedule,coupons,day_count) > > bond_engine = ql.DiscountingBondEngine(spot_curve_handle) > fixed_rate_bond.setPricingEngine(bond_engine) > > print("NPV of Bond:",round(fixed_rate_bond.NPV(),2)) > > print("Clean Bond Price:",round(fixed_rate_bond.cleanPrice(),2)) > > print('Accrual start date:', ql.BondFunctions.accrualStartDate(fixed_rate_bond)) > > print('Accrual end date:', ql.BondFunctions.accrualEndDate(fixed_rate_bond)) > > print('Number of days between accrual start date and accrual end date:', > day_count.dayCount(ql.BondFunctions.accrualStartDate(fixed_rate_bond), > ql.BondFunctions.accrualEndDate(fixed_rate_bond))) > > print('Accrued days:', ql.BondFunctions.accruedDays(fixed_rate_bond)) > > print("Accrued Amount:",round(fixed_rate_bond.accruedAmount(),2)) > > print("Dirty Bond Price:",round(fixed_rate_bond.dirtyPrice(),2)) > > print("Bond yield:",round(fixed_rate_bond.bondYield(day_count,compounding,compounding_frequency),5)) > > print("Day Count:",fixed_rate_bond.dayCounter()) > > print("Settlement Date:",fixed_rate_bond.settlementDate()) > > for c in fixed_rate_bond.cashflows(): > print('%20s %12f' % (c.date(), c.amount())) > > Thanks > > > _______________________________________________ > QuantLib-users mailing list > Qua...@li... > https://lists.sourceforge.net/lists/listinfo/quantlib-users > |