2010-10-25 71 views
1

嘗試從自舉曲線定價20x10交換時,出現以下錯誤。錯誤坐上ImpliedRate函數的最後一行拋出嘗試使用Quantlib時定價儀器時出錯

SwapRatesServiceTests.ImpliedRate_ForTwenty_x_TenYearSwap_ReturnsRate: System.ApplicationException:2腿:空手柄無法提領

我沒有最微弱的想法哪裏開始調試這個問題。任何援助將不勝感激。

重要提示:我使用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++代碼有關。希望這種曝光可能揭示一些可能在這裏發生的事情。

+0

我還通過電子郵件發送quantlib用戶羣,所以我將與任何相關反饋更新接收。 – Ahmad 2010-10-25 09:29:36

回答

0

基於從Quantlib mailing list

反饋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);