|
From: David D. <nh...@gm...> - 2020-10-08 13:37:12
|
There is no need to convert. You can build the curve from spot rates
directly.
For example:
dates = [ql.Date(31,12,2019), ql.Date(31,12,2020),
ql.Date(31,12,2021)]zeros = [0.01, 0.02, 0.03]ql.ZeroCurve(dates,
zeros, ql.ActualActual(), ql.TARGET())
On Thu, 8 Oct 2020 at 14:09, isilay erol <ero...@gm...> wrote:
> Dear David,
>
> You are right, the discount factors are increasing,
>
> this indicates that the curve is negative.
>
>
>
> Your sample helped me a lot, thank you very much.
>
> I need to make my calculation from the zero coupon yield curve itself,
>
> not the discount factor. At this point,
>
> I will try to move forward using the formula of the discount factor
> calculation from zero coupon.
>
> If you already have a Python example of this conversion, I would be very
> happy if you could share it with me.
>
> If not, I will try to derive it.
>
> Thanks again
>
> Best regards,
>
>
> On 8 Oct 2020 Thu at 15:39 David Duarte <nh...@gm...> wrote:
>
>> That is correct. The rates in EUR are negative.
>> Notice the discount factors are above 1
>>
>> On Thu, 8 Oct 2020, 13:10 isilay erol, <ero...@gm...> wrote:
>>
>>> Dear David,
>>> I'm working on Anaconda Python,
>>> Thank you for your help,
>>> When I ran your query,
>>> I got negative fwd rates and negative fwd cash flows, am I missing
>>> something?
>>>
>>> You can see my results in the following:
>>>
>>> import QuantLib as ql
>>>
>>> from pandas import DataFrame
>>>
>>>
>>>
>>>
>>>
>>> dates = [
>>>
>>> '07-05-2019', '11-11-2019', '09-12-2019', '09-01-2020', '10-02-2020',
>>>
>>> '09-03-2020', '09-04-2020', '11-05-2020', '09-06-2020',
>>>
>>> '09-07-2020', '10-08-2020', '09-09-2020', '09-10-2020', '09-11-2020',
>>>
>>> '10-05-2021', '09-05-2022', '09-05-2023', '09-05-2024']
>>>
>>>
>>>
>>> dfs = [
>>>
>>> 1.000000, 1.001185, 1.001352, 1.001561, 1.001766, 1.001941, 1.002146,
>>>
>>> 1.002355, 1.002534,
>>>
>>> 1.002712, 1.002897, 1.003069, 1.003232, 1.003395, 1.004146, 1.004549,
>>>
>>> 1.003148, 0.999840]
>>>
>>>
>>>
>>> ql.Settings.instance().evaluationDate = ql.Date(7,5,2019)
>>>
>>>
>>>
>>> qlDates = [ql.Date(dt, '%d-%m-%Y') for dt in dates]
>>>
>>> dayCounter = ql.Actual360()
>>>
>>> curve = ql.DiscountCurve(qlDates, dfs, dayCounter, ql.NullCalendar())
>>>
>>>
>>>
>>> forwardStart = ql.Date(15,6,2020)
>>>
>>> forwardEnd = ql.Date(15,12,2020)
>>>
>>> fwd = curve.forwardRate(forwardStart, forwardEnd, dayCounter,
>>>
>>> ql.Compounded, ql.Annual).rate()
>>>
>>> print(fwd)
>>>
>>> -0.0019082224391586688
>>>
>>>
>>>
>>> yts = ql.YieldTermStructureHandle(curve)
>>>
>>> schedule = ql.MakeSchedule(ql.Date(15,6,2020), ql.Date(15,6,2021),
>>>
>>> ql.Period('6m'))
>>>
>>> index = ql.Euribor6M(yts)
>>>
>>> bond = ql.FloatingRateBond(2,100, schedule, ql.Euribor6M(yts),
>>>
>>> ql.Actual360())
>>>
>>>
>>>
>>> for dt in schedule:
>>>
>>> print(dt, index.fixing(dt))
>>>
>>>
>>>
>>>
>>>
>>> June 15th, 2020 -0.00190201607110241
>>>
>>> December 15th, 2020 -0.001253382120767248
>>>
>>> June 15th, 2021 -0.00039680612008295636
>>>
>>> On 8 Oct 2020 Thu at 12:21 David Duarte <nh...@gm...> wrote:
>>>
>>>> Are you using c++, python or excel?
>>>>
>>>> Since you already have a yield curve, you can build the object by
>>>> inputting spot rates (ZeroCurve class) or discount factors (DiscountCurve).
>>>>
>>>> Here is an example using python:
>>>>
>>>> dates = [
>>>> '07-05-2019', '11-11-2019', '09-12-2019', '09-01-2020',
>>>> '10-02-2020', '09-03-2020', '09-04-2020', '11-05-2020', '09-06-2020',
>>>> '09-07-2020', '10-08-2020', '09-09-2020', '09-10-2020',
>>>> '09-11-2020', '10-05-2021', '09-05-2022', '09-05-2023', '09-05-2024']
>>>>
>>>> dfs = [
>>>> 1.000000, 1.001185, 1.001352, 1.001561, 1.001766, 1.001941,
>>>> 1.002146, 1.002355, 1.002534,
>>>> 1.002712, 1.002897, 1.003069, 1.003232, 1.003395, 1.004146,
>>>> 1.004549, 1.003148, 0.999840]
>>>>
>>>> ql.Settings.instance().evaluationDate = ql.Date(7,5,2019)
>>>> qlDates = [ql.Date(dt, '%d-%m-%Y') for dt in dates]
>>>> dayCounter = ql.Actual360()
>>>> curve = ql.DiscountCurve(qlDates, dfs, dayCounter, ql.NullCalendar())
>>>>
>>>>
>>>>
>>>> To get the forward rates, you can use the "forwardRate" method from the
>>>> curve:
>>>>
>>>> forwardStart = ql.Date(15,6,2020)
>>>> forwardEnd = ql.Date(15,12,2020)
>>>> fwd = curve.forwardRate(forwardStart, forwardEnd, dayCounter,
>>>> ql.Compounded, ql.Annual).rate()
>>>> print(fwd)
>>>>
>>>> or build the floating rate bond object and inspect the rate on the
>>>> cashflows:
>>>>
>>>> yts = ql.YieldTermStructureHandle(curve)
>>>> schedule = ql.MakeSchedule(ql.Date(15,6,2020), ql.Date(15,6,2021),
>>>> ql.Period('6m'))
>>>> index = ql.Euribor6M(yts)
>>>> bond = ql.FloatingRateBond(2,100, schedule, ql.Euribor6M(yts),
>>>> ql.Actual360())
>>>>
>>>> for cf in map(ql.as_coupon, bond.cashflows()):
>>>> if cf:
>>>> print(cf.accrualStartDate().ISO(), cf.accrualStartDate().ISO(),
>>>> f"{cf.rate():.3%}")
>>>>
>>>>
>>>> or even get the rate from the index for given set of dates:
>>>>
>>>> for dt in schedule:
>>>> print(dt, index.fixing(dt))
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Thu, 8 Oct 2020 at 06:39, isilay erol <ero...@gm...> wrote:
>>>>
>>>>> Dear Luigi,
>>>>>
>>>>> I just met with quantlib.
>>>>>
>>>>> I try to understand from the examples how cash flows of floating rate
>>>>> bonds are created.
>>>>>
>>>>> But in the examples, I always see that yield curves are established
>>>>> from scratch.
>>>>>
>>>>>
>>>>>
>>>>> I want to calculate forward rates and forward rate coupons with the
>>>>> yield curve which I already have.
>>>>>
>>>>> (I don't want to construct a yield curve from scratch again - I have a
>>>>> zero coupon yield curve)
>>>>>
>>>>> And this way I want to create the cash flows of the floating bond. But
>>>>> I could not understand how I could do this.
>>>>>
>>>>> Can you help me on this issue?
>>>>>
>>>> _______________________________________________
>>>>
>>>>
>>>>> QuantLib-users mailing list
>>>>> Qua...@li...
>>>>> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>>>>>
>>>>
|