|
From: Francois B. <ig...@gm...> - 2020-10-09 07:11:37
|
So the error message states that you have already added the fixing.
I'm unsure whether the Python interface for index.addFixing provides a
parameter to optionally overwrite any existing indices. If so, try that.
Alternatively, there should be something like index.clearFixings() which
you can call first before adding new fixings.
regards
Francois Botha
On Fri, 9 Oct 2020 at 08:58, isilay erol <ero...@gm...> wrote:
> Hello again,
>
> I want to ask one more question;
>
> I want set a past fixing for the current latest coupon (which, having
> fixed in the past, can’t be forecast).
>
> The forecasting of floating bond cashflow should be start generate from
> this latest repring coupon rate.
>
> That’s why I heve added the following querry only to see what will happen;
>
>
>
>
>
> “index.addFixing(ql.Date(6,ql.March,2019), 0.003)”
>
>
>
> Bu I have the folowing error message;
>
> Am I thinking wrongly?
>
>
>
> 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']
>
>
>
> zeros = [
>
> 0.000000, 0.001185, 0.001352, 0.001561, 0.001766, 0.001941, 0.002146,
>
> 0.002355, 0.002534,
>
> 0.002712, 0.002897, 0.003069, 0.003232, 0.003395, 0.004146, 0.004549,
>
> 0.003148, 0.004040]
>
>
>
> ql.Settings.instance().evaluationDate = ql.Date(7,5,2019)
>
> qlDates = [ql.Date(dt, '%d-%m-%Y') for dt in dates]
>
> dayCounter = ql.Actual360()
>
>
>
>
>
> zCurve = ql.ZeroCurve(qlDates, zeros, ql.ActualActual(), ql.TARGET())
>
>
>
> forwardStart = ql.Date(15,6,2020)
>
> forwardEnd = ql.Date(15,12,2020)
>
> fwd = zCurve.forwardRate(forwardStart, forwardEnd, dayCounter,
>
> ql.Compounded, ql.Annual).rate()
>
> print(fwd)
>
> 0.005623856615195155
>
>
>
> yts = ql.YieldTermStructureHandle(zCurve)
>
> schedule = ql.MakeSchedule(ql.Date(15,6,2020), ql.Date(15,6,2021),
>
> ql.Period('6m'))
>
> index = ql.Euribor6M(yts)
>
> index.addFixing(ql.Date(6,ql.March,2019), 0.003)
>
> bond = ql.FloatingRateBond(2,100, schedule, ql.Euribor6M(yts),
>
> ql.Actual360())
>
>
>
> Traceback (most recent call last):
>
>
>
> File "<ipython-input-61-ec28b13dc284>", line 5, in <module>
>
> index.addFixing(ql.Date(6,ql.March,2019), 0.003)
>
>
>
> File "C:\Anaconda3\lib\site-packages\QuantLib\QuantLib.py", line 5475,
> in addFixing
>
> return _QuantLib.Index_addFixing(self, fixingDate, fixing,
> forceOverwrite)
>
>
>
> RuntimeError: At least one duplicated fixing provided: March 6th, 2019,
> 0.003 while 0.002 value is already present
>
>
> Best regards,
>
> On 8 Oct 2020 Thu at 17:20 isilay erol <ero...@gm...> wrote:
>
>> Thank you very much Luigi an David.
>>
>> On 8 Oct 2020 Thu at 16:32 Luigi Ballabio <lui...@gm...>
>> wrote:
>>
>>> If you use ql.ZeroCurve instead of ql.DiscountCurve you can input zero
>>> rates directly and get a curve that you can use in the exact same way.
>>>
>>> Luigi
>>>
>>>
>>> On Thu, Oct 8, 2020 at 3:13 PM 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
>>>>>>>>
>>>>>>> _______________________________________________
>>>> QuantLib-users mailing list
>>>> Qua...@li...
>>>> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>>>>
>>> _______________________________________________
> QuantLib-users mailing list
> Qua...@li...
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
|