|
From: Luigi B. <lui...@gm...> - 2024-01-30 09:36:22
|
Hello Amir,
the call in your code:
ql_rc = ql.CashFlows.yieldRate(BondLeg, dirty_val,
ql.Actual365Fixed(), ql.Compounded, ql.Continuous, True)
should instead be:
ql_rc = ql.CashFlows.yieldRate(BondLeg, dirty_val,
ql.Actual365Fixed(), ql.Continuous, ql.NoFrequency, True)
that is, "continuous" is not a frequency to associate to "compounded", but
a compounding method in its own right. Unfortunately Python doesn't have
real enums so it can't warn of this, and the first call was interpreting
the numeric value of ql.Continuous, 2, as semiannual frequency. The second
call gives the result you expect.
May you point us to the documentation you used to write the call? It's
probably in need of clarification. Thanks!
Luigi
On Mon, Jan 29, 2024 at 11:20 PM Amir Lakha <ami...@gm...> wrote:
> Hi Quantlib Users,
>
> I am having some difficulties in reconciling the yield to maturity
> calculation for a stream of cashflows.
>
> I have attached the jupyter notebook with my code.
>
> In the code, I take vectors of dates and amounts to create a BondLeg, to
> which I assign a dirty_value.
>
> I use ql.Cashflows.yieldRate to calculate an Annually Compounding and
> Continuous Compounding Yield to Maturity.
>
> I generate the yearFraction for the dates using the same daycount basis
> used to calculate the yields.
>
>
> I then use a PYOMO Non Linear Optimization Solver (ipopt) to solve for the
> yield to maturities using the yearfractions, cashflow amounts and
> dirty_value.
>
> The PYOMO annually compounding yield is within 1bp of the QuantLib yield.
> However, the QuantLib continuously compounding yield is 13bp higher than
> the PYOMO yield.
>
> Any help in figuring out what I am doing wrong would be much appreciated.
>
> PS, Excel using Goal Seek gives me the same answers as PYOMO as one would
> expect.
>
> Many thanks in advance,
>
> Best,
> _______________________________________________
> QuantLib-users mailing list
> Qua...@li...
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
|