-2
$\begingroup$

I have problem using utils/python_utils function in Python Quantlib. Code is mostly follow CookBook for Quant Finance for Quantlib - EONIA Curve Bootstrap Chapter I imported python-utils, and utils at the beginning of the code, but doesn't seem plot is usable for these 2 package based on error?

I use python 3.7

If utils.plot is not usable, what are other substitute functions?

import QuantLib as ql  
import math  
import python_utils  
import utils  
import pandas as pd  
import matplotlib.pyplot as plt  
today=ql.Date(9, ql.September, 2019)  
ql.Settings.instance().evaluationDate = today  

helpers = [ql.DepositRateHelper(ql.QuoteHandle(ql.SimpleQuote(rate)),\  
                                               ql.Period(1, ql.Days), fixingDays, ql.TARGET(),\  
                                              ql.ModifiedFollowing, False, ql.Actual360())\  
          for rate, fixingDays in [(-0.00363,0)]]


eonia = ql.Eonia()
telescopicValueDates = True

helpers += [\  
   ql.OISRateHelper(2, ql.Period(*tenor), ql.QuoteHandle(ql.SimpleQuote(rate)), eonia)\  
       for rate, tenor in [(-0.005871, (10, ql.Months)), (-0.0059495, (11, ql.Months)), \  
                           (-0.005871, (1, ql.Years)), (-0.006349, (18, ql.Months))]]

helpers += [ql.OISRateHelper(2, ql.Period(*tenor), ql.QuoteHandle(ql.SimpleQuote(rate)), eonia)\  
for rate, tenor in [(0.00073, (2, ql.Years)),(0.0008057, (3, ql.Years)), (0.0009, (4, ql.Years)),\    
                    (0.00105, (7, ql.Years)), (0.00107, (8, ql.Years)), (0.00109, (9, ql.Years)), \  
                    (0.001115, (10,ql.Years)),(0.00112, (11, ql.Years)), (0.00113, (12, ql.Years)),\  
                    (0.00114, (15, ql.Years)), (0.0011, (20, ql.Years)), (0.00107, (25, ql.Years)), \  
                    (0.00105, (30, ql.Years))]]

eonia_curve_c = ql.PiecewiseLogCubicDiscount(0, ql.TARGET(),\  
                                            helpers, ql.Actual365Fixed())
eonia_curve_c.enableExtrapolation()  

today = eonia_curve_c.referenceDate()  
end = today + ql.Period(30, ql.Years)  
dates = [ql.Date(serial) for serial in range(today.serialNumber(), end.serialNumber()+1)]  

rate_c = [eonia_curve_c.forwardRate(d, ql.TARGET().advance(d, 1, ql.Days), ql.Actual360(), ql.Simple).rate()
          for d in dates]

_, ax = utils.plot()  
utils.highlight_x_axis(ax)  
utils.plot_curve(ax, dates, [(rate_c,'-')], format_rates=True
)  

error:

_, ax = utils.plot()  
AttributeError: module 'utils' has no attribute 'plot'

if I use python_utils, error would be:

_, ax = python_utils.plot()  
AttributeError: module 'python_utils' has no attribute 'plot'
$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.