|
From: Philippe H. <phi...@ex...> - 2023-12-17 21:08:00
|
You could try ql.CashFlows(cashflows, curve_handle, valaution_date) I think. Where valuation date can be the curve evaluation date or anything you want but beware about ex-coupon dates
Regards
Philippe Hatstadt
+1-203-252-0408
> On Dec 17, 2023, at 3:22 PM, Quant <qua...@gm...> wrote:
>
>
> Hi Quantlib Users,
>
> I have bootstrapped the yield curve and I have managed to extract discount factors from this yield curve but the discount factors are referencing from the Evaluation Date. These discount factors are used to calculate the PV of the bond but they can not be used to calculate the Dirty Price of the bond if the Evaluation Date is different from the Bond Settlement Date. How do I extract the Discount Factors from the Bond Settlement Date instead of the Evaluation Date. Hoping that my question is clear.
>
> Find below a part of the code that I have tried to use to extract the discount factors;
> fields = ['accrualStartDate', 'accrualEndDate', 'date', 'nominal', 'rate',
> 'amount', 'accrualDays', 'accrualPeriod']
> BondCashflows = []
> for cf in list(map(ql.as_fixed_rate_coupon, bond.cashflows()))[:-1]:
> row = {fld: eval(f"cf.{fld}()") for fld in fields}
> row['AccrualPeriod'] = round((row['accrualEndDate'] - row['accrualStartDate']) / 365, 4)
> if row['date'] >= today:
> row['ZeroRate (NPV)'] = round(curve.zeroRate(row['date'], day_count, ql.Compounded, ql.Annual).rate(), 9)
> row['ZeroRate (Dirty Price)'] = round(curve.forwardRate(bond.settlementDate(), row['date'], day_count, ql.Compounded, ql.Annual).rate(), 9)
> row['DiscFactor (NPV)'] = round(curve.discount(row['date']), 9)
> row['DiscFactor (Dirty Price)'] = round(curve.discount(bond.settlementDate(), row['date']), 9)
> else:
> row['ZeroRate (NPV)'] = 0
> row['ZeroRate (Dirty Price)'] = 0
> row['DiscFactor (NPV)'] = 0 # or any other appropriate handling for dates before today
> row['DiscFactor (Dirty Price)'] = 0 # or any other appropriate handling for dates before today
> row['NPV'] = round(row['DiscFactor (NPV)'] * row['amount'], 9)
> BondCashflows.append(row)
>
> BondCashflows = pd.DataFrame(BondCashflows)
>
> print(BondCashflows)
>
> Thanks & regards
> _______________________________________________
> QuantLib-users mailing list
> Qua...@li...
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
--
1370 Broadway, Suite 1450 | New York, NY | 10018
<https://www.exosfinancial.com/>
<https://www.linkedin.com/company/meetexos/about/>
Broker-Dealer
services offered through Exos Securities LLC, Member SIPC, FINRA. For
important disclosures including Form CRS and Regulation BI click here
<https://www.exosfinancial.com/general-disclosures>.
Confidentiality
Notice: The information contained in this email (including attachments) is
only for the personal and confidential use of the sender and recipient
named above. If the reader is not the intended recipient, you are notified
that you have received this message in error and that any review,
dissemination, copying or distribution is prohibited. If you have received
this communication in error, please notify the sender immediately by e-mail
and delete or destroy the original message and all copies.
|