我试图价格从自举曲线20×10交换功能时,接收下面的错误。错误抛出的ImpliedRate函数的最后一行

  

SwapRatesServiceTests.ImpliedRate_ForTwenty_x_TenYearSwap_ReturnsRate:   System.ApplicationException:第二腿:空手柄不能解除引用

我没有最微弱知道从哪里开始调试这个问题。任何帮助将高度赞赏。

重要:我使用Quantlib的C#痛饮版本,所以我的实际刺代码如下基于所述swapvaluation.cpp示例:

测试方法:

    [Test]
    public void ImpliedRate_ForTwenty_x_TenYearSwap_ReturnsRate() 
    {
        //Arrange
        var startingDate = new Date(10,Month.October,2030); // starting date of 20x10yr swap
        var length= 10;
        repo.Setup(r => r.Read(It.IsAny<string>())).Returns(LoadSwapPoints()); // LoadSwapPoints returns IEnumerable<RateHelpers>

        //Act
        service.ConstructSwapPoints(SettlementDate);
        var instrumentRate = service.ImpliedRate(startingDate, length);

        //Assert
        Assert.That(instrumentRate, Is.Not.Null); // this must change to a value test

    }

这是较大ConstructSwapPoints方法的一部分

        var depoFRASwapInstruments = PointVector; // RateHelperVector populated with RateHelpers
        DayCounter termStructureDayCounter = new ActualActual(ActualActual.Convention.Actual365);

        QuoteHandleVector quotes = new QuoteHandleVector();
        DateVector quoteDates = new DateVector();

        py = CreatePiecewiseLinearCurve(settlementDate, depoFRASwapInstruments, termStructureDayCounter, quotes, quoteDates);
        DiscountingTermStructure = new RelinkableYieldTermStructureHandle(py); //RelinkableYieldTermStructureHandle
        //DiscountingTermStructure.linkTo(py); // alternate way

        PricingEngine = new DiscountingSwapEngine(DiscountingTermStructure); // DiscountingSwapEngine           

使用的方法ImpliedRate如下(我已经剪断了一些零件出由于IP限制);

    public double ImpliedRate(Date startingDate, int length)
    {

        var swapMaturityDate = startingDate.Add(new Period(length, TimeUnit.Years));
        var curveMaturityDate = py.maxDate();

        Schedule fixedSchedule = new Schedule(startingDate, swapMaturityDate, new Period(Frequency.Quarterly), SouthAfricanCalender, Convention, Convention, DateGeneration.Rule.Forward, false);
        Schedule floatSchedule = new Schedule(startingDate, swapMaturityDate, new Period(Frequency.Quarterly), SouthAfricanCalender, Convention, Convention, DateGeneration.Rule.Forward, false);

        VanillaSwap impliedSwap = new VanillaSwap(
            _VanillaSwap.Type.Payer, 
            10000000.0, 
            fixedSchedule, 
            0.1, 
            Actual365FixedDayCounter, 
            floatSchedule, 
            new Jibar(new Period(Frequency.Quarterly)), 
            0, 
            Actual365FixedDayCounter);

        impliedSwap.setPricingEngine(PricingEngine);

        return impliedSwap.fairRate(); // <---exception thrown here
    }

我希望我的术语是正确的,因为金融行话仍是新的我。

编辑:我已经添加了C ++代码,因为我图实际上与一些底层C ++代码。希望此曝光可以揭示一些见解什么可这里发生的一切。

有帮助吗?

解决方案

根据从 Quantlib邮件列表反馈

在Jibar索引需要具有到所创建的无风险曲线的基准。如果没有一个长期的结构,Jibar可以回到过去的定价而不是预测未来的。所述Jibar构造需要被替换

new Jibar(new Period(Frequency.Quarterly), DiscountingTermStructure)

VanillaSwap impliedSwap = new VanillaSwap(
    _VanillaSwap.Type.Payer, 
    10000000.0, 
    fixedSchedule, 
    0.1, 
    Actual365FixedDayCounter, 
    floatSchedule, 
    new Jibar(new Period(Frequency.Quarterly), DiscountingTermStructure), 
    0, 
    Actual365FixedDayCounter);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top