1
$\begingroup$

Suppose we have already known the dates and rates of a spot rate curve, and I passed the data to the ZeroCurve class to construct a discount curve for bond pricing. What I wanna find is how to change the referenceDate of the discount curve without changing the original dates and rates data. I have tried like below:

Settings.instance().evaluationDate = Date(11, 12, 2017)

fake_dates = [Date(8, 5, 2017+i) for i in range(5)]
fake_rates = [(1+i)/100 for i in range(5)]

day_counter = ActualActual()

spot_curve = ZeroCurve(fake_dates, fake_rates, day_counter, China(), Linear(), Compounded, Semiannual)     

discount_curve = YieldTermStructureHandle(spot_curve)

print(discount_curve.referenceDate())

# Reset the evaluation date

Settings.instance().evaluationDate = Date(12, 12, 2017)
print(discount_curve.referenceDate())

But, this doesn't work! It returns the same result of Date(11, 12, 2017)

I am a newbie to QuantLib-Python, it would be appreciated if anyone could do me a favor. Many thanks!

$\endgroup$
0
$\begingroup$

I suggest that you read the following chapter in the QuantLib Python Cookbook:

"5. Term structures and their reference dates"

Alternatively, see this video:

https://www.youtube.com/watch?v=pc1yOmxU2GQ

The author strips a term structure in a way that its reference date moves with the evaluation date and one method that it doesn't.

$\endgroup$
  • $\begingroup$ Thanks very much! The video exactly matches what I need. $\endgroup$ – Fitz_Hoo Jun 25 '18 at 3:02
  • $\begingroup$ No problem. Please accept the answer to informs others that the question is not open anymore. $\endgroup$ – Bernd Jun 25 '18 at 20:02
0
$\begingroup$

I meant to add a comment to answer my own question according to @Bernd's link(thx @Bernd), but the comment editor is really not friendly to use for me. Back to the question, there are two alternative ways to choose.

  1. Use the tenors and rates to construct a helper.

    helper_= DepositRateHelper(QuoteHandle(SimpleQuote(rate/100)),Period(*tenor),0,China(),Following,False,ActualActual()) for tenor, rate in [((1, Years), 1),((2, Years), 2),((3, Years), 3),((4, Years), 4), ((5, Years), 5)]]
    
    discount_curve = PiecewiseFlatForward(2, TARGET(), helper_, ActualActual())
    discount_curve.referenceDate()
    

Now, we can change the first argument of PiecewiseFlatForward to get our required referenceDate.

  1. Use the dates and rates to directly construct a curve. But now we have to change the dates if we want to change the referenceDate.

    fake_dates_shift = [date + Period(2, Days) for date in fake_dates]   
    spot_curve_shift = ZeroCurve(fake_dates_shift, fake_rates, day_counter, China(), Linear(), Compounded, Semiannual)     
    discount_curve_shift = YieldTermStructureHandle(spot_curve_shift)
    discount_curve_shift.referenceDate()
    
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.