簡體   English   中英

Quantlib-給一個奇怪的錯誤

[英]Quantlib - giving a strange error

我正在使用Quantlib引導曲線,然后獲得折現率。

通常,通常的步驟可以正常工作。

但是,對於下面給出的數據,它將引發一個奇怪的錯誤。

碼:

def create_ois_swaps(self, ois_swap_rates, helpers=None):
    ''' Creates a OIS rate helper from incoming OIS rates
        Input:
        ois_swap_rates: list of tuples comprising of (start_date, end_date, rate, label)
    '''
    if self.helpers is None:
        self.helpers = [
            DatedOISRateHelper(start_date, end_date, QuoteHandle(SimpleQuote(rate / 100)), self.ff_local)
            for start_date, end_date, rate in [tuple((fixed_bond.pydate_to_qldate(sd),
                                                      fixed_bond.pydate_to_qldate(ed),
                                                      rate)) for sd, ed, rate, label
                                               in ois_swap_rates if label not in ['ONTN', 'TN']]]
    else:
        self.helpers += [DatedOISRateHelper(start_date,
                                            end_date,
                                            QuoteHandle(SimpleQuote(rate / 100)), self.ff_local)
                         for start_date, end_date, rate in [tuple((fixed_bond.pydate_to_qldate(sd),
                                                                   fixed_bond.pydate_to_qldate(ed),
                                                                   rate)) for sd, ed, rate, label
                                                            in ois_swap_rates if label not in ['ONTN', 'TN']]]
    # for start_date, end_date, rate in ois_swap_rates]
    self.ois_curve_c = PiecewiseLogCubicDiscount(0, self.calendar, self.helpers, Actual365Fixed())
    self.ois_curve_c.enableExtrapolation()

def bootstrap_usd_ois_3M_curve(self,
                               usd_3M_swap_rates,
                               discountCurve,
                               bootStrapMethod=BootStrapMethod.PiecewiseLogCubicDiscount):

    discount_curve = RelinkableYieldTermStructureHandle()
    discount_curve.linkTo(discountCurve)
    self.helpers += [SwapRateHelper(QuoteHandle(SimpleQuote(rate / 100)),
                                    Period(int(label[:-1]), Years),
                                    TARGET(),
                                    Semiannual,
                                    Unadjusted,
                                    Thirty360(Thirty360.BondBasis),
                                    Euribor3M(),
                                    QuoteHandle(),
                                    Period(0, Days),
                                    discount_curve)
                     for sd, ed, rate, label in usd_3M_swap_rates if label not in ['ONTN', 'TN']]
    # for rate, tenor in usd_3M_swap_rates]

    if bootStrapMethod == BootStrapMethod.PiecewiseLogCubicDiscount:
        self.usd_3M_c = PiecewiseLogCubicDiscount(0, TARGET(), self.helpers, Actual365Fixed())
    elif bootStrapMethod == BootStrapMethod.PiecewiseFlatForward:
        self.usd_3M_c = PiecewiseFlatForward(0, TARGET(), self.helpers, Actual365Fixed())

    # Also, we enable extrapolation beyond the maturity of the last helper; that is mostly
    # for convenience as we retrieve rates to plot the curve near its far end.
    self.usd_3M_c.enableExtrapolation()

在我的主要代碼中,我將上述兩個函數稱為:

創建OIS曲線

usd_ois.create_ois_swaps(ois_rate_ql)

引導曲線

usd_ois.bootstrap_usd_ois_3M_curve(usd_3M_swap_rates=libor_rate_ql, discountCurve=usd_ois.ois_curve_c, bootStrapMethod=BootStrapMethod.PiecewiseFlatForward)

日期:

曲線評估日期:2017.01.02

對於Discounting_Rate:-

開始日期:2017.01.02結束日期:2018.01.01天計數:ACT / 360

錯誤信息:

返回_QuantLib.YieldTermStructure_forwardRate(self,* args)RuntimeError:給定負時間(-0.00273973)

曲線對象

曲線對象 使用的數據: 用於引導的libor和OIS速率

曲線對象的狀態

曲線對象的狀態

注意,我有一個1)貼現OIS曲線和一個2)向前3M曲線

評估日期為2017年1月2日

我正在撥打的電話在折價曲線上如下所示: ois_curve.ois_curve_c.forwardRate(pydate_to_qldate(start_date), pydate_to_qldate(end_date), daycount, Simple).rate() * 100

其中start_Date = 2017年1月2日end_date = 2018年1月2日

我在一段時間內運行相同的代碼。 大多數日期-成功,但很少日期-奇怪地拋出此錯誤

作為參考,我在這里總結上面的評論。 評估日期(2017年1月2日)是曲線使用的日歷的假期; 因此,曲線將其參考日期移至下一個工作日。 屆時,就曲線而言,1月2日已過去,要求該日期的匯率會導致錯誤。

我同意,至少應該使該錯誤更具可讀性。 我不確定將評估日期設置為假期是否必然會使曲線無效。 拋出錯誤可能是不可行的。 我們可能會使用不同的日歷使用不同的曲線,並且只要我們僅使用有效曲線,就可以將其中之一的評估日期設置為假日。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM